Add runtime persitence on OCPP parameters.
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 15 Oct 2020 22:48:24 +0000 (00:48 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 15 Oct 2020 22:48:24 +0000 (00:48 +0200)
And more type convertion fixes.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
12 files changed:
src/assets/station/abb.station
src/assets/station/evlink.station
src/assets/station/keba.station
src/assets/station/schneider-imredd.station
src/assets/station/schneider.station
src/assets/station/siemens.mougins69.station
src/assets/station/virtual-simple-atg.station
src/assets/station/virtual-simple.station
src/assets/station/virtual.station
src/charging-station/ChargingStation.js
src/utils/Configuration.js
src/utils/Utils.js

index 0106ad209dc12fdad64dd7673d8b3e3b3b3c978f..67b4214fe8ae3ed51215fd25e23a62754d1085b2 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 2},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 30},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 30},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index 72e4fb2b07a95ed6ecac9d5394d70da68c38a2dd..2424c0e5ae66887caa49a443adf411a62dadfac6 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 1},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 20},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 20},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index 876b9c96679bd7a68c3bd19a9bf85033fc525ac7..6a61cc3bced3788ad0778a93093ce631889e6c7e 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 2},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 30},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 30},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index 9af157febe03503732a3bf06209f57c44ff21e59..ade470fa229de99464760ce1768f941dea05c8ae 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 2},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 20},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 20},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index 9af157febe03503732a3bf06209f57c44ff21e59..ade470fa229de99464760ce1768f941dea05c8ae 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 2},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 20},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 20},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index f90d83a49a8c737d81b4f7411e80d0b15aaf5b14..aa58d1f28ebc941d58de27a1a9ddabed7368be4e 100644 (file)
@@ -11,7 +11,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 2},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 30},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 30},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index 7af070bfbf4ca655b8511a57e3d40759d2c9681b..d0da727b57597912132b70dac1a2b8425b4cf2c0 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 3},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 30},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 30},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index 5187e04ad5e34ce0265d2ec9efb6004cc87b1963..107cb9eb83ce15053e0851ab25ab5041d4687ceb 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 3},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 30},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 30},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index d9153b9c2983f8b2ef7499c2809941618ed8d686..107ad594cb887461a328693ff9aba0985c88d33a 100644 (file)
@@ -10,7 +10,7 @@
     "Configuration": { "configurationKey": [
             { "key": "NumberOfConnectors", "readonly": true, "value": 9},
             { "key": "param1", "readonly": false, "value": "test"},
-            { "key": "meterValueInterval", "readonly": false, "value": 30},
+            { "key": "MeterValueSampleInterval", "readonly": false, "value": 30},
             { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false}
         ]
     },
index ea6fbabeef83eaa7e79a6085e7971f08d3e0c7eb..0411a1a1f12c88bb457b4246f10d7b30131e37a9 100644 (file)
@@ -72,7 +72,7 @@ class ChargingStation {
 
   _getAuthorizeRemoteTxRequests() {
     const authorizeRemoteTxRequests = this._configuration.configurationKey.find((configElement) => configElement.key === 'AuthorizeRemoteTxRequests');
-    return authorizeRemoteTxRequests ? authorizeRemoteTxRequests.value : false;
+    return authorizeRemoteTxRequests ? Utils.convertToBoolean(authorizeRemoteTxRequests.value) : false;
   }
 
   _buildChargingStation(index, stationTemplate) {
@@ -401,6 +401,7 @@ class ChargingStation {
   }
 
   handleResponseStartTransaction(payload, requestPayload) {
+    // Reset connector transaction related attributes
     this._connectors[requestPayload.connectorId].transactionStarted = false;
     this._connectors[requestPayload.connectorId].idTag = requestPayload.idTag;
 
@@ -413,9 +414,9 @@ class ChargingStation {
           this._connectors[connector].lastSoC = 0;
           logger.info(this._basicFormatLog() + ' Transaction ' + this._connectors[connector].transactionId + ' STARTED on ' + this._stationInfo.name + '#' + requestPayload.connectorId + ' with idTag ' + requestPayload.idTag);
           this.sendStatusNotification(requestPayload.connectorId, 'Charging');
-          const configuredMeterInterval = this._configuration.configurationKey.find((value) => value.key === 'meterValueInterval');
+          const configuredMeterValueSampleInterval = this._configuration.configurationKey.find((value) => value.key === 'MeterValueSampleInterval');
           this.startMeterValues(requestPayload.connectorId,
-              (configuredMeterInterval ? configuredMeterInterval.value * 1000 : 60000),
+              (configuredMeterValueSampleInterval ? configuredMeterValueSampleInterval.value * 1000 : 60000),
               this);
         }
       }
@@ -491,8 +492,9 @@ class ChargingStation {
 
   async handleChangeConfiguration(commandPayload) {
     const keyToChange = this._configuration.configurationKey.find((element) => element.key === commandPayload.key);
-    if (keyToChange) {
-      keyToChange.value = commandPayload.value;
+    if (keyToChange && !Utils.convertToBoolean(keyToChange.readonly)) {
+      const keyIndex = this._configuration.configurationKey.indexOf(keyToChange);
+      this._configuration.configurationKey[keyIndex].value = commandPayload.value;
       return Constants.OCPP_RESPONSE_ACCEPTED;
     }
     return Constants.OCPP_RESPONSE_REJECTED;
@@ -586,7 +588,7 @@ class ChargingStation {
           // Persist previous value in connector
           const connector = self._connectors[connectorID];
           let consumption;
-          consumption = Utils.getRandomInt(self._stationInfo.maxPower / 3600000 * interval, 3);
+          consumption = Utils.getRandomInt(self._stationInfo.maxPower / 3600000 * interval, 4);
           if (connector && connector.lastConsumptionValue >= 0) {
             connector.lastConsumptionValue += consumption;
           } else {
index 65915f04a28ab3b3d4ea3e7fd8cb654622ff8ddb..5833d7e2007e43af8acdd988c4e1e85378079a8a 100644 (file)
@@ -61,9 +61,9 @@ class Configuration {
     return (Configuration.getConfig().hasOwnProperty('errorFile') ? Configuration.getConfig().errorFile : 'error.log');
   }
 
-  static getMeterValueInterval() {
+  static getMeterValueSampleInterval() {
     // Read conf
-    return (Configuration.getChargingStationConfiguration().hasOwnProperty('meterValueInterval') ? Configuration.getChargingStationConfiguration().meterValueInterval * 1000 : 60000);
+    return (Configuration.getChargingStationConfiguration().hasOwnProperty('MeterValueSampleInterval') ? Configuration.getChargingStationConfiguration().MeterValueSampleInterval * 1000 : 60000);
   }
 
   static getAutomaticTransactionConfiguration() {
index 85b2d4748d91c52daab0dfbcff866f63fdedbbac..e85090d49626156d4e2fdb913781762448bdcc8a 100644 (file)
@@ -100,6 +100,22 @@ class Utils {
     return changedID;
   }
 
+  static convertToBoolean(value) {
+    let result = false;
+    // Check boolean
+    if (value) {
+      // Check the type
+      if (typeof value === 'boolean') {
+        // Already a boolean
+        result = value;
+      } else {
+        // Convert
+        result = (value === 'true');
+      }
+    }
+    return result;
+  }
+
   static getRandomInt(max, min) {
     if (min) {
       return Math.floor((Math.random() * (max - min)) + min);