Fix missing template files loading error.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 21 Oct 2020 20:42:39 +0000 (22:42 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 21 Oct 2020 20:42:39 +0000 (22:42 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/assets/config-template.json
src/charging-station/AutomaticTransactionGenerator.js
src/charging-station/ChargingStation.js

index 831f88da78f0758f7ada0fc6e9229a645fda69e4..69659bbc109d21c780b2f8491049902b21affa0b 100644 (file)
@@ -10,7 +10,7 @@
   "workerPoolSize": 16,
   "stationTemplateURLs": [
     {
-      "file": "./src/assets/station-templates/siemens.mougins69.station-template.json",
+      "file": "./src/assets/station-templates/siemens.station-template.json",
       "numberOfStation": 1
     },
     {
index d0843ebc4ba16107d2d29d162170b9b9d5d618e5..ed7cf3ce5e841a7309568c5385eda6e15324abf6 100644 (file)
@@ -44,9 +44,9 @@ class AutomaticTransactionGenerator {
   async stop(reason = '') {
     logger.info(this._logPrefix() + ' ATG OVER => STOPPING ALL TRANSACTIONS');
     for (const connector in this._chargingStation._connectors) {
-      if (this._chargingStation._connectors[connector].transactionStarted) {
-        logger.info(this._logPrefix(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._connectors[connector].transactionId);
-        await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId, reason);
+      if (this._chargingStation._getConnector(connector).transactionStarted) {
+        logger.info(this._logPrefix(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._getConnector(connector).transactionId);
+        await this._chargingStation.sendStopTransaction(this._chargingStation._getConnector(connector).transactionId, reason);
       }
     }
     this._timeToStop = true;
@@ -74,11 +74,11 @@ class AutomaticTransactionGenerator {
           // Wait until end of transaction
           const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration,
               this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
-          logger.info(this._logPrefix(connectorId) + ' transaction ' + this._chargingStation._connectors[connectorId].transactionId + ' will stop in ' + Utils.secondstoHHMMSS(wait / 1000));
+          logger.info(this._logPrefix(connectorId) + ' transaction ' + this._chargingStation._getConnector(connectorId).transactionId + ' will stop in ' + Utils.secondstoHHMMSS(wait / 1000));
           await Utils.sleep(wait);
           // Stop transaction
-          if (this._chargingStation._connectors[connectorId].transactionStarted) {
-            logger.info(this._logPrefix(connectorId) + ' stop transaction ' + this._chargingStation._connectors[connectorId].transactionId);
+          if (this._chargingStation._getConnector(connectorId).transactionStarted) {
+            logger.info(this._logPrefix(connectorId) + ' stop transaction ' + this._chargingStation._getConnector(connectorId).transactionId);
             const stopTransaction = performance.timerify(this.stopTransaction);
             this._performanceObserver.observe({entryTypes: ['function']});
             await stopTransaction(connectorId, this);
@@ -104,7 +104,7 @@ class AutomaticTransactionGenerator {
 
   // eslint-disable-next-line class-methods-use-this
   async stopTransaction(connectorId, self) {
-    await self._chargingStation.sendStopTransaction(self._chargingStation._connectors[connectorId].transactionId);
+    await self._chargingStation.sendStopTransaction(self._chargingStation._getConnector(connectorId).transactionId);
   }
 }
 
index dc484cf98fb15e3752c931a763c02150fd4fcc98..f5a67fe9fb6f56215c90db46cbd7e0b39dcde5b5 100644 (file)
@@ -40,7 +40,8 @@ class ChargingStation {
       stationTemplateFromFile = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
       fs.closeSync(fileDescriptor);
     } catch (error) {
-      logger.error(this._logPrefix() + ' Template file loading error: ' + error);
+      logger.error('Template file ' + this._stationTemplateFile + ' loading error: ' + error);
+      throw error;
     }
     const stationTemplate = stationTemplateFromFile || {};
     if (!Utils.isEmptyArray(stationTemplateFromFile.power)) {
@@ -99,7 +100,7 @@ class ChargingStation {
     delete this._stationInfo.Connectors;
     // Initialize transaction attributes on connectors
     for (const connector in this._connectors) {
-      if (!this._connectors[connector].transactionStarted) {
+      if (!this._getConnector(connector).transactionStarted) {
         this._initTransactionOnConnector(connector);
       }
     }
@@ -135,7 +136,8 @@ class ChargingStation {
         authorizedTags = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
         fs.closeSync(fileDescriptor);
       } catch (error) {
-        logger.error(this._logPrefix() + ' Authorization file loading error: ' + error);
+        logger.error(this._logPrefix() + ' Authorization file ' + authorizationFile + ' loading error: ' + error);
+        throw error;
       }
     } else {
       logger.info(this._logPrefix() + ' No authorization file given in template file ' + this._stationTemplateFile);
@@ -219,9 +221,9 @@ class ChargingStation {
     this._startHeartbeat(this);
     // Initialize connectors status
     for (const connector in this._connectors) {
-      if (!this._connectors[connector].transactionStarted) {
-        if (this._connectors[connector].bootStatus) {
-          this.sendStatusNotificationWithTimeout(connector, this._connectors[connector].bootStatus);
+      if (!this._getConnector(connector).transactionStarted) {
+        if (this._getConnector(connector).bootStatus) {
+          this.sendStatusNotificationWithTimeout(connector, this._getConnector(connector).bootStatus);
         } else {
           this.sendStatusNotificationWithTimeout(connector, 'Available');
         }
@@ -289,15 +291,15 @@ class ChargingStation {
   }
 
   async _startMeterValues(connectorId, interval) {
-    if (!this._connectors[connectorId].transactionStarted) {
+    if (!this._getConnector(connectorId).transactionStarted) {
       logger.error(`${this._logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction started`);
       return;
-    } else if (this._connectors[connectorId].transactionStarted && !this._connectors[connectorId].transactionId) {
+    } else if (this._getConnector(connectorId).transactionStarted && !this._getConnector(connectorId).transactionId) {
       logger.error(`${this._logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction id`);
       return;
     }
     if (interval > 0) {
-      this._connectors[connectorId].transactionSetInterval = setInterval(async () => {
+      this._getConnector(connectorId).transactionSetInterval = setInterval(async () => {
         const sendMeterValues = performance.timerify(this.sendMeterValues);
         this._performanceObserver.observe({
           entryTypes: ['function'],
@@ -341,8 +343,8 @@ class ChargingStation {
       await this._automaticTransactionGeneration.stop(reason);
     } else {
       for (const connector in this._connectors) {
-        if (this._connectors[connector].transactionStarted) {
-          await this.sendStopTransaction(this._connectors[connector].transactionId, reason);
+        if (this._getConnector(connector).transactionStarted) {
+          await this.sendStopTransaction(this._getConnector(connector).transactionId, reason);
         }
       }
     }
@@ -582,7 +584,7 @@ class ChargingStation {
         sampledValueLcl.sampledValue = [meterValuesClone];
       }
       for (let index = 0; index < sampledValueLcl.sampledValue.length; index++) {
-        const connector = self._connectors[connectorId];
+        const connector = self._getConnector(connectorId);
         // SoC measurand
         if (sampledValueLcl.sampledValue[index].measurand && sampledValueLcl.sampledValue[index].measurand === 'SoC' && self._getConfigurationKey('MeterValuesSampledData').value.includes('SoC')) {
           sampledValueLcl.sampledValue[index].value = !Utils.isUndefined(sampledValueLcl.sampledValue[index].value) ?
@@ -628,7 +630,7 @@ class ChargingStation {
 
       const payload = {
         connectorId,
-        transactionId: self._connectors[connectorId].transactionId,
+        transactionId: self._getConnector(connectorId).transactionId,
         meterValue: [sampledValueLcl],
       };
       await self.sendMessage(Utils.generateUUID(), payload, Constants.OCPP_JSON_CALL_MESSAGE, 'MeterValues');
@@ -731,22 +733,22 @@ class ChargingStation {
   }
 
   _initTransactionOnConnector(connectorId) {
-    this._connectors[connectorId].transactionStarted = false;
-    this._connectors[connectorId].transactionId = null;
-    this._connectors[connectorId].idTag = null;
-    this._connectors[connectorId].lastEnergyActiveImportRegisterValue = -1;
+    this._getConnector(connectorId).transactionStarted = false;
+    this._getConnector(connectorId).transactionId = null;
+    this._getConnector(connectorId).idTag = null;
+    this._getConnector(connectorId).lastEnergyActiveImportRegisterValue = -1;
   }
 
   _resetTransactionOnConnector(connectorId) {
     this._initTransactionOnConnector(connectorId);
-    if (this._connectors[connectorId].transactionSetInterval) {
-      clearInterval(this._connectors[connectorId].transactionSetInterval);
+    if (this._getConnector(connectorId).transactionSetInterval) {
+      clearInterval(this._getConnector(connectorId).transactionSetInterval);
     }
   }
 
   handleResponseStartTransaction(payload, requestPayload) {
-    if (this._connectors[requestPayload.connectorId].transactionStarted) {
-      logger.debug(this._logPrefix() + ' Try to start a transaction on an already used connector ' + requestPayload.connectorId + ': %s', this._connectors[requestPayload.connectorId]);
+    if (this._getConnector(requestPayload.connectorId).transactionStarted) {
+      logger.debug(this._logPrefix() + ' Try to start a transaction on an already used connector ' + requestPayload.connectorId + ': %s', this._getConnector(requestPayload.connectorId));
       return;
     }
 
@@ -762,10 +764,10 @@ class ChargingStation {
       return;
     }
     if (payload.idTagInfo && payload.idTagInfo.status === 'Accepted') {
-      this._connectors[transactionConnectorId].transactionStarted = true;
-      this._connectors[transactionConnectorId].transactionId = payload.transactionId;
-      this._connectors[transactionConnectorId].idTag = requestPayload.idTag;
-      this._connectors[transactionConnectorId].lastEnergyActiveImportRegisterValue = 0;
+      this._getConnector(requestPayload.connectorId).transactionStarted = true;
+      this._getConnector(requestPayload.connectorId).transactionId = payload.transactionId;
+      this._getConnector(requestPayload.connectorId).idTag = requestPayload.idTag;
+      this._getConnector(requestPayload.connectorId).lastEnergyActiveImportRegisterValue = 0;
       this.sendStatusNotification(requestPayload.connectorId, 'Charging');
       logger.info(this._logPrefix() + ' Transaction ' + payload.transactionId + ' STARTED on ' + this._stationInfo.name + '#' + requestPayload.connectorId + ' for idTag ' + requestPayload.idTag);
       if (this._stationInfo.powerSharedByConnectors) {
@@ -784,7 +786,7 @@ class ChargingStation {
   handleResponseStopTransaction(payload, requestPayload) {
     let transactionConnectorId;
     for (const connector in this._connectors) {
-      if (this._connectors[connector].transactionId === requestPayload.transactionId) {
+      if (this._getConnector(connector).transactionId === requestPayload.transactionId) {
         transactionConnectorId = connector;
         break;
       }
@@ -976,7 +978,7 @@ class ChargingStation {
 
   async handleRemoteStopTransaction(commandPayload) {
     for (const connector in this._connectors) {
-      if (this._connectors[connector].transactionId === commandPayload.transactionId) {
+      if (this._getConnector(connector).transactionId === commandPayload.transactionId) {
         this.sendStopTransaction(commandPayload.transactionId);
         return Constants.OCPP_RESPONSE_ACCEPTED;
       }