From 7e3bde4fa97ee4937b806bb4dfeb16ef0f99d1a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 4 Feb 2024 12:27:46 +0100 Subject: [PATCH] fix: make the ATG wait for running transactions to be stopped MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 21 +++++++++++++++++-- src/charging-station/ChargingStation.ts | 9 +++++--- src/utils/Constants.ts | 5 ++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 2380c967..adf38e67 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -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 { + 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) } } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index f193d148..36cd0958 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -711,7 +711,10 @@ export class ChargingStation extends EventEmitter { } } - public async stop (reason?: StopTransactionReason, stopTransactions?: boolean): Promise { + public async stop ( + reason?: StopTransactionReason, + stopTransactions = this.stationInfo?.stopTransactionsOnStopped + ): Promise { 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 { this.internalStopMessageSequence() // Stop ongoing transactions diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 9b8fd1c5..38890575 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -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, -- 2.34.1