X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FAutomaticTransactionGenerator.ts;h=ebfd8c196fd026b0ca673bba3cb5a38bff8a3e9d;hb=3e888c6560f1a59e1d34f06d465e698305c90aea;hp=f390d55fe20554291d068ba6f848963f0845cb9f;hpb=3d20f4db7cad24703c7acac80f01ab4c6908ce58;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index f390d55f..ebfd8c19 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -189,20 +189,13 @@ export class AutomaticTransactionGenerator extends AsyncResource { )}`, ); while (this.connectorsStatus.get(connectorId)?.start === true) { + await this.waitChargingStationServiceInitialization(connectorId); + await this.waitChargingStationAvailable(connectorId); + await this.waitConnectorAvailable(connectorId); if (!this.canStartConnector(connectorId)) { this.stopConnector(connectorId); break; } - if (!this.chargingStation?.ocppRequestService) { - logger.info( - `${this.logPrefix( - connectorId, - )} transaction loop waiting for charging station service to be initialized`, - ); - do { - await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME); - } while (!this.chargingStation?.ocppRequestService); - } const wait = secondsToMilliseconds( getRandomInteger( this.chargingStation.getAutomaticTransactionGeneratorConfiguration() @@ -326,6 +319,45 @@ export class AutomaticTransactionGenerator extends AsyncResource { return true; } + private async waitChargingStationServiceInitialization(connectorId: number): Promise { + if (!this.chargingStation?.ocppRequestService) { + logger.info( + `${this.logPrefix( + connectorId, + )} transaction loop waiting for charging station service to be initialized`, + ); + do { + await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME); + } while (!this.chargingStation?.ocppRequestService); + } + } + + private async waitChargingStationAvailable(connectorId: number): Promise { + if (!this.chargingStation.isChargingStationAvailable()) { + logger.info( + `${this.logPrefix( + connectorId, + )} transaction loop waiting for charging station to be available`, + ); + do { + await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME); + } while (!this.chargingStation.isChargingStationAvailable()); + } + } + + private async waitConnectorAvailable(connectorId: number): Promise { + if (!this.chargingStation.isConnectorAvailable(connectorId)) { + logger.info( + `${this.logPrefix( + connectorId, + )} transaction loop waiting for connector ${connectorId} to be available`, + ); + do { + await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME); + } while (!this.chargingStation.isConnectorAvailable(connectorId)); + } + } + private initializeConnectorsStatus(): void { if (this.chargingStation.hasEvses) { for (const [evseId, evseStatus] of this.chargingStation.evses) {