feat(simulator): wait when necessary between phases at firmware update
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 24 Mar 2023 18:31:04 +0000 (19:31 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 24 Mar 2023 18:31:04 +0000 (19:31 +0100)
 simulation

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

index b22e7e499d8315f73154af46c36f41c17c923190..718f2f90319b9bb58bd25e57457be1f77e52185c 100644 (file)
@@ -1045,6 +1045,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       status: OCPP16FirmwareStatus.Downloaded,
     });
     chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Downloaded;
+    let wasTransactionsStarted = false;
     let transactionsStarted: boolean;
     do {
       let trxCount = 0;
@@ -1065,6 +1066,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         );
         await Utils.sleep(waitTime);
         transactionsStarted = true;
+        wasTransactionsStarted = true;
       } else {
         for (const connectorId of chargingStation.connectors.keys()) {
           if (
@@ -1087,7 +1089,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         transactionsStarted = false;
       }
     } while (transactionsStarted);
-    await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000);
+    !wasTransactionsStarted &&
+      (await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000));
     if (
       ChargingStationUtils.checkChargingStation(chargingStation, chargingStation.logPrefix()) ===
       false