fix: add charging station status checkpoints to firmware update
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 23 Mar 2023 22:00:45 +0000 (23:00 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 23 Mar 2023 22:00:45 +0000 (23:00 +0100)
simulation async execution

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index 3fef7d878b4a3fd6122712908a60f6e7cbd92595..c6056dd53af52a539e1ef1e7bc472d5184d6281e 100644 (file)
@@ -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;
-  }
 }
index efa8921c645707a293ecbd7a2b60dcb3de1d84c4..ca9a93bce9a7c06f851cbea3e1af30c238931eb9 100644 (file)
@@ -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) {
index fb87345d00d9ccba36f3fa0164c0d21be3236453..b22e7e499d8315f73154af46c36f41c17c923190 100644 (file)
@@ -992,7 +992,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     maxDelay = 30,
     minDelay = 15
   ): Promise<void> {
-    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