From: Jérôme Benoit Date: Thu, 23 Mar 2023 22:00:45 +0000 (+0100) Subject: fix: add charging station status checkpoints to firmware update X-Git-Tag: v1.2.0-0~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1bf29f5be7c0ffe3d029e447ecb50da55bfd8948;p=e-mobility-charging-stations-simulator.git fix: add charging station status checkpoints to firmware update simulation async execution Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 3fef7d87..c6056dd5 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -66,7 +66,9 @@ export class AutomaticTransactionGenerator extends AsyncResource { } public start(): void { - if (this.checkChargingStation() === false) { + if ( + ChargingStationUtils.checkChargingStation(this.chargingStation, this.logPrefix()) === false + ) { return; } if (this.started === true) { @@ -87,7 +89,12 @@ export class AutomaticTransactionGenerator extends AsyncResource { } public startConnector(connectorId: number): void { - if (this.checkChargingStation(connectorId) === false) { + if ( + ChargingStationUtils.checkChargingStation( + this.chargingStation, + this.logPrefix(connectorId) + ) === false + ) { return; } if (this.connectorsStatus.has(connectorId) === false) { @@ -461,12 +468,4 @@ export class AutomaticTransactionGenerator extends AsyncResource { this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++; } } - - private checkChargingStation(connectorId?: number): boolean { - if (this.chargingStation.started === false && this.chargingStation.starting === false) { - logger.warn(`${this.logPrefix(connectorId)} charging station is stopped, cannot proceed`); - return false; - } - return true; - } } diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index efa8921c..ca9a93bc 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -89,6 +89,14 @@ export class ChargingStationUtils { .digest('hex'); } + public static checkChargingStation(chargingStation: ChargingStation, logPrefix: string): boolean { + if (chargingStation.started === false && chargingStation.starting === false) { + logger.warn(`${logPrefix} charging station is stopped, cannot proceed`); + return false; + } + return true; + } + public static getTemplateMaxNumberOfConnectors(stationTemplate: ChargingStationTemplate): number { const templateConnectors = stationTemplate?.Connectors; if (!templateConnectors) { diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index fb87345d..b22e7e49 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -992,7 +992,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { maxDelay = 30, minDelay = 15 ): Promise { - chargingStation.stopAutomaticTransactionGenerator(); + if ( + ChargingStationUtils.checkChargingStation(chargingStation, chargingStation.logPrefix()) === + false + ) { + return; + } for (const connectorId of chargingStation.connectors.keys()) { if ( connectorId > 0 && @@ -1083,6 +1088,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } } while (transactionsStarted); await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000); + if ( + ChargingStationUtils.checkChargingStation(chargingStation, chargingStation.logPrefix()) === + false + ) { + return; + } await chargingStation.ocppRequestService.requestHandler< OCPP16FirmwareStatusNotificationRequest, OCPP16FirmwareStatusNotificationResponse