From a6e68f340a9c5837c767b316dee5d5121188dc47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 16 Oct 2020 00:48:24 +0200 Subject: [PATCH] Add runtime persitence on OCPP parameters. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit And more type convertion fixes. Signed-off-by: Jérôme Benoit --- src/assets/station/abb.station | 2 +- src/assets/station/evlink.station | 2 +- src/assets/station/keba.station | 2 +- src/assets/station/schneider-imredd.station | 2 +- src/assets/station/schneider.station | 2 +- src/assets/station/siemens.mougins69.station | 2 +- src/assets/station/virtual-simple-atg.station | 2 +- src/assets/station/virtual-simple.station | 2 +- src/assets/station/virtual.station | 2 +- src/charging-station/ChargingStation.js | 14 ++++++++------ src/utils/Configuration.js | 4 ++-- src/utils/Utils.js | 16 ++++++++++++++++ 12 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/assets/station/abb.station b/src/assets/station/abb.station index 0106ad20..67b4214f 100644 --- a/src/assets/station/abb.station +++ b/src/assets/station/abb.station @@ -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} ] }, diff --git a/src/assets/station/evlink.station b/src/assets/station/evlink.station index 72e4fb2b..2424c0e5 100644 --- a/src/assets/station/evlink.station +++ b/src/assets/station/evlink.station @@ -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} ] }, diff --git a/src/assets/station/keba.station b/src/assets/station/keba.station index 876b9c96..6a61cc3b 100644 --- a/src/assets/station/keba.station +++ b/src/assets/station/keba.station @@ -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} ] }, diff --git a/src/assets/station/schneider-imredd.station b/src/assets/station/schneider-imredd.station index 9af157fe..ade470fa 100644 --- a/src/assets/station/schneider-imredd.station +++ b/src/assets/station/schneider-imredd.station @@ -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} ] }, diff --git a/src/assets/station/schneider.station b/src/assets/station/schneider.station index 9af157fe..ade470fa 100644 --- a/src/assets/station/schneider.station +++ b/src/assets/station/schneider.station @@ -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} ] }, diff --git a/src/assets/station/siemens.mougins69.station b/src/assets/station/siemens.mougins69.station index f90d83a4..aa58d1f2 100644 --- a/src/assets/station/siemens.mougins69.station +++ b/src/assets/station/siemens.mougins69.station @@ -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} ] }, diff --git a/src/assets/station/virtual-simple-atg.station b/src/assets/station/virtual-simple-atg.station index 7af070bf..d0da727b 100644 --- a/src/assets/station/virtual-simple-atg.station +++ b/src/assets/station/virtual-simple-atg.station @@ -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} ] }, diff --git a/src/assets/station/virtual-simple.station b/src/assets/station/virtual-simple.station index 5187e04a..107cb9eb 100644 --- a/src/assets/station/virtual-simple.station +++ b/src/assets/station/virtual-simple.station @@ -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} ] }, diff --git a/src/assets/station/virtual.station b/src/assets/station/virtual.station index d9153b9c..107ad594 100644 --- a/src/assets/station/virtual.station +++ b/src/assets/station/virtual.station @@ -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} ] }, diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index ea6fbabe..0411a1a1 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -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 { diff --git a/src/utils/Configuration.js b/src/utils/Configuration.js index 65915f04..5833d7e2 100644 --- a/src/utils/Configuration.js +++ b/src/utils/Configuration.js @@ -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() { diff --git a/src/utils/Utils.js b/src/utils/Utils.js index 85b2d474..e85090d4 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -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); -- 2.34.1