Be consistent in variables naming.
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.js
index 90576e9e16aaf8e0ea33e6de1ced1efde4b0e56f..1bb56425b1a89e88991cf2eb3b7b1ee7800945c0 100644 (file)
@@ -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');
 
@@ -28,7 +29,6 @@ class AutomaticTransactionGenerator {
     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);
@@ -38,14 +38,15 @@ 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(type = '') {
+  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, type ? type + 'Reset' : '');
+        await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId, reason);
       }
     }
     this._timeToStop = true;
@@ -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,