fix: make the ATG wait for running transactions to be stopped
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 4 Feb 2024 11:27:46 +0000 (12:27 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 4 Feb 2024 11:27:46 +0000 (12:27 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts
src/utils/Constants.ts

index 2380c967beada92d179262a2c71abc30640758f6..adf38e67b4591c0dae62a6b76827556bbba5382f 100644 (file)
@@ -188,6 +188,7 @@ export class AutomaticTransactionGenerator {
     while (this.connectorsStatus.get(connectorId)?.start === true) {
       await this.waitChargingStationAvailable(connectorId)
       await this.waitConnectorAvailable(connectorId)
+      await this.waitRunningTransactionStopped(connectorId)
       if (!this.canStartConnector(connectorId)) {
         this.stopConnector(connectorId)
         break
@@ -337,7 +338,7 @@ export class AutomaticTransactionGenerator {
         )
         logged = true
       }
-      await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME)
+      await sleep(Constants.DEFAULT_ATG_WAIT_TIME)
     }
   }
 
@@ -352,7 +353,23 @@ export class AutomaticTransactionGenerator {
         )
         logged = true
       }
-      await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME)
+      await sleep(Constants.DEFAULT_ATG_WAIT_TIME)
+    }
+  }
+
+  private async waitRunningTransactionStopped (connectorId: number): Promise<void> {
+    const connectorStatus = this.chargingStation.getConnectorStatus(connectorId)
+    let logged = false
+    while (connectorStatus?.transactionStarted === true) {
+      if (!logged) {
+        logger.info(
+          `${this.logPrefix(
+            connectorId
+          )} transaction loop waiting for running transaction ${connectorStatus.transactionId} on connector ${connectorId} to be stopped`
+        )
+        logged = true
+      }
+      await sleep(Constants.DEFAULT_ATG_WAIT_TIME)
     }
   }
 
index f193d148b1927f921417fdce192d1c6486d4efa4..36cd0958fffe778f3cb68c0402be8b3285f58f4f 100644 (file)
@@ -711,7 +711,10 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
-  public async stop (reason?: StopTransactionReason, stopTransactions?: boolean): Promise<void> {
+  public async stop (
+    reason?: StopTransactionReason,
+    stopTransactions = this.stationInfo?.stopTransactionsOnStopped
+  ): Promise<void> {
     if (this.started) {
       if (!this.stopping) {
         this.stopping = true
@@ -1169,7 +1172,7 @@ export class ChargingStation extends EventEmitter {
     stationInfo.resetTime =
       stationTemplate.resetTime != null
         ? secondsToMilliseconds(stationTemplate.resetTime)
-        : Constants.CHARGING_STATION_DEFAULT_RESET_TIME
+        : Constants.DEFAULT_CHARGING_STATION_RESET_TIME
     return stationInfo
   }
 
@@ -2225,7 +2228,7 @@ export class ChargingStation extends EventEmitter {
 
   private async stopMessageSequence (
     reason?: StopTransactionReason,
-    stopTransactions = this.stationInfo?.stopTransactionsOnStopped
+    stopTransactions?: boolean
   ): Promise<void> {
     this.internalStopMessageSequence()
     // Stop ongoing transactions
index 9b8fd1c517a7199465febcb0bb9df792ff4d3500..38890575f176c9f4f635a0d91a91d1b077570e01 100644 (file)
@@ -38,10 +38,9 @@ export class Constants {
   static readonly DEFAULT_HEARTBEAT_INTERVAL = 60000 // Ms
   static readonly DEFAULT_METER_VALUES_INTERVAL = 60000 // Ms
 
-  static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000 // Ms
-  static readonly CHARGING_STATION_ATG_AVAILABILITY_TIME = 1000 // Ms
-  static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000 // Ms
+  static readonly DEFAULT_CHARGING_STATION_RESET_TIME = 60000 // Ms
 
+  static readonly DEFAULT_ATG_WAIT_TIME = 1000 // Ms
   static readonly DEFAULT_ATG_CONFIGURATION: AutomaticTransactionGeneratorConfiguration =
     Object.freeze({
       enable: false,