X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FAutomaticTransactionGenerator.js;h=1bb56425b1a89e88991cf2eb3b7b1ee7800945c0;hb=bec64e8b13ebf62d6838d1f3fb647a5b06f170fb;hp=ebb0a8e0a5d17baf73bb1de4733e8717559bc2b8;hpb=d3a7883e3b5f20baee6fff45ee599341300d7564;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/AutomaticTransactionGenerator.js b/src/charging-station/AutomaticTransactionGenerator.js index ebb0a8e0..1bb56425 100644 --- a/src/charging-station/AutomaticTransactionGenerator.js +++ b/src/charging-station/AutomaticTransactionGenerator.js @@ -1,4 +1,5 @@ const logger = require('../utils/Logger'); +const Constants = require('../utils/Constants'); const Utils = require('../utils/Utils'); const {performance, PerformanceObserver} = require('perf_hooks'); @@ -24,22 +25,10 @@ class AutomaticTransactionGenerator { return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG:'); } - async stop() { - logger.info(this._basicFormatLog() + ' ATG OVER => STOPPING ALL TRANSACTIONS'); - for (const connector in this._chargingStation._connectors) { - if (this._chargingStation._connectors[connector].transactionStarted) { - logger.info(this._basicFormatLog(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._connectors[connector].transactionId); - await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId); - } - } - this._timeToStop = true; - } - async start() { this._timeToStop = false; if (this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours && this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours > 0) { - logger.info(this._basicFormatLog() + ' ATG will stop in ' + Utils.secondstoHHMMSS(this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600)); setTimeout(() => { this.stop(); }, this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600 * 1000); @@ -49,6 +38,18 @@ class AutomaticTransactionGenerator { this.startConnector(connector); } } + logger.info(this._basicFormatLog() + ' ATG started and will stop in ' + Utils.secondstoHHMMSS(this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600)); + } + + async stop(reason = '') { + logger.info(this._basicFormatLog() + ' ATG OVER => STOPPING ALL TRANSACTIONS'); + for (const connector in this._chargingStation._connectors) { + if (this._chargingStation._connectors[connector].transactionStarted) { + logger.info(this._basicFormatLog(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._connectors[connector].transactionId); + await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId, reason); + } + } + this._timeToStop = true; } async startConnector(connectorId) { @@ -68,7 +69,7 @@ class AutomaticTransactionGenerator { const startResponse = await startTransaction(connectorId, this); if (startResponse.idTagInfo.status !== 'Accepted') { logger.info(this._basicFormatLog(connectorId) + ' transaction rejected'); - await Utils.sleep(2000); + await Utils.sleep(Constants.CHARGING_STATION_ATG_WAIT_TIME); } else { // Wait until end of transaction const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration,