Configuration,
Constants,
DCElectricUtils,
- MessageChannelUtils,
Utils,
buildChargingStationAutomaticTransactionGeneratorConfiguration,
buildConnectorsStatus,
buildEvsesStatus,
+ buildStartedMessage,
+ buildStoppedMessage,
+ buildUpdatedMessage,
handleFileException,
logger,
watchJsonFile,
}
);
this.started = true;
- parentPort?.postMessage(MessageChannelUtils.buildStartedMessage(this));
+ parentPort?.postMessage(buildStartedMessage(this));
this.starting = false;
} else {
logger.warn(`${this.logPrefix()} Charging station is already starting...`);
delete this.bootNotificationResponse;
this.started = false;
this.saveConfiguration();
- parentPort?.postMessage(MessageChannelUtils.buildStoppedMessage(this));
+ parentPort?.postMessage(buildStoppedMessage(this));
this.stopping = false;
} else {
logger.warn(`${this.logPrefix()} Charging station is already stopping...`);
this.automaticTransactionGenerator?.start();
}
this.saveAutomaticTransactionGeneratorConfiguration();
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(buildUpdatedMessage(this));
}
public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
this.automaticTransactionGenerator?.stop();
}
this.saveAutomaticTransactionGeneratorConfiguration();
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(buildUpdatedMessage(this));
}
public async stopTransactionOnConnector(
}
this.wsConnectionRestarted = false;
this.autoReconnectRetryCount = 0;
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(buildUpdatedMessage(this));
} else {
logger.warn(
`${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed`
this.started === true && (await this.reconnect());
break;
}
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(buildUpdatedMessage(this));
}
private getCachedRequest(messageType: MessageType, messageId: string): CachedRequest | undefined {
logger.error(`${this.logPrefix()} ${errorMsg}`);
throw new OCPPError(ErrorType.PROTOCOL_ERROR, errorMsg);
}
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(buildUpdatedMessage(this));
} else {
throw new OCPPError(ErrorType.PROTOCOL_ERROR, 'Incoming message is not an array', null, {
request,
type SetChargingProfileResponse,
type UnlockConnectorResponse,
} from '../../../types';
-import { Constants, MessageChannelUtils, Utils, logger } from '../../../utils';
+import { Constants, Utils, buildUpdatedMessage, logger } from '../../../utils';
import { OCPPResponseService } from '../OCPPResponseService';
const moduleName = 'OCPP16ResponseService';
): Promise<void> {
ChargingStationUtils.resetConnectorStatus(chargingStation.getConnectorStatus(connectorId));
chargingStation.stopMeterValues(connectorId);
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation));
+ parentPort?.postMessage(buildUpdatedMessage(chargingStation));
if (
chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Available
) {
chargingStation.getConnectorStatus(transactionConnectorId)
);
chargingStation.stopMeterValues(transactionConnectorId);
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation));
+ parentPort?.postMessage(buildUpdatedMessage(chargingStation));
const logMsg = `${chargingStation.logPrefix()} Transaction with id ${requestPayload.transactionId.toString()} STOPPED on ${
chargingStation.stationInfo.chargingStationId
}#${transactionConnectorId?.toString()} with status '${
type Statistics,
} from '../types';
-export class MessageChannelUtils {
- private constructor() {
- // This is intentional
- }
+export const buildStartedMessage = (
+ chargingStation: ChargingStation
+): ChargingStationWorkerMessage<ChargingStationData> => {
+ return {
+ id: ChargingStationWorkerMessageEvents.started,
+ data: buildChargingStationDataPayload(chargingStation),
+ };
+};
- public static buildStartedMessage(
- chargingStation: ChargingStation
- ): ChargingStationWorkerMessage<ChargingStationData> {
- return {
- id: ChargingStationWorkerMessageEvents.started,
- data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
- };
- }
+export const buildStoppedMessage = (
+ chargingStation: ChargingStation
+): ChargingStationWorkerMessage<ChargingStationData> => {
+ return {
+ id: ChargingStationWorkerMessageEvents.stopped,
+ data: buildChargingStationDataPayload(chargingStation),
+ };
+};
- public static buildStoppedMessage(
- chargingStation: ChargingStation
- ): ChargingStationWorkerMessage<ChargingStationData> {
- return {
- id: ChargingStationWorkerMessageEvents.stopped,
- data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
- };
- }
+export const buildUpdatedMessage = (
+ chargingStation: ChargingStation
+): ChargingStationWorkerMessage<ChargingStationData> => {
+ return {
+ id: ChargingStationWorkerMessageEvents.updated,
+ data: buildChargingStationDataPayload(chargingStation),
+ };
+};
- public static buildUpdatedMessage(
- chargingStation: ChargingStation
- ): ChargingStationWorkerMessage<ChargingStationData> {
- return {
- id: ChargingStationWorkerMessageEvents.updated,
- data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
- };
- }
+export const buildPerformanceStatisticsMessage = (
+ statistics: Statistics
+): ChargingStationWorkerMessage<Statistics> => {
+ return {
+ id: ChargingStationWorkerMessageEvents.performanceStatistics,
+ data: statistics,
+ };
+};
- public static buildPerformanceStatisticsMessage(
- statistics: Statistics
- ): ChargingStationWorkerMessage<Statistics> {
- return {
- id: ChargingStationWorkerMessageEvents.performanceStatistics,
- data: statistics,
- };
- }
-
- private static buildChargingStationDataPayload(
- chargingStation: ChargingStation
- ): ChargingStationData {
- return {
- started: chargingStation.started,
- stationInfo: chargingStation.stationInfo,
- connectors: buildConnectorsStatus(chargingStation),
- evses: buildEvsesStatus(chargingStation, OutputFormat.worker),
- ocppConfiguration: chargingStation.ocppConfiguration,
- wsState: chargingStation?.wsConnection?.readyState,
- bootNotificationResponse: chargingStation.bootNotificationResponse,
- ...(chargingStation.automaticTransactionGenerator && {
- automaticTransactionGenerator:
- buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation),
- }),
- };
- }
-}
+const buildChargingStationDataPayload = (chargingStation: ChargingStation): ChargingStationData => {
+ return {
+ started: chargingStation.started,
+ stationInfo: chargingStation.stationInfo,
+ connectors: buildConnectorsStatus(chargingStation),
+ evses: buildEvsesStatus(chargingStation, OutputFormat.worker),
+ ocppConfiguration: chargingStation.ocppConfiguration,
+ wsState: chargingStation?.wsConnection?.readyState,
+ bootNotificationResponse: chargingStation.bootNotificationResponse,
+ ...(chargingStation.automaticTransactionGenerator && {
+ automaticTransactionGenerator:
+ buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation),
+ }),
+ };
+};