From 9bd87386d65158edef865cafd0daabff91822b87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 20 Jun 2021 13:49:51 +0200 Subject: [PATCH] Add tunable for phase line to line voltage MeterValues MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also improve MeterValues template parsing logs Signed-off-by: Jérôme Benoit --- README.md | 9 ++++++++ src/charging-station/ChargingStation.ts | 18 ++++++++++----- .../ocpp/1.6/OCPP16RequestService.ts | 22 ++++++++++--------- src/types/ChargingStationTemplate.ts | 1 + 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a16ad55b..a4a39038 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ outOfOrderEndMeterValues | true/false | false | boolean | send Transaction.End M meteringPerTransaction | true/false | true | boolean | disable metering on a per transaction basis transactionDataMeterValues | true/false | false | boolean | enable transaction data MeterValues at stop transaction mainVoltageMeterValues | true/false | true | boolean | include charging station main voltage MeterValues on three phased charging stations +phaseLineToLineVoltage | true/false | true | boolean | include charging station line to line voltage MeterValues on three phased charging stations Configuration | | | ChargingStationConfiguration | charging stations OCPP configuration parameters AutomaticTransactionGenerator | | | AutomaticTransactionGenerator | charging stations ATG configuration Connectors | | | Connectors | charging stations connectors configuration @@ -125,6 +126,14 @@ Connectors | | | Connectors | charging stations connectors configuration "1": { "bootStatus": "Available", "MeterValues": [ + ... + { + "unit": "W", + "measurand": "Power.Active.Import", + "phase": "L1-N", + "value": "5000", + "fluctuationPercent": "10" + }, ... { "unit": "A", diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6bab3d86..8be54a78 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -121,7 +121,7 @@ export default class ChargingStation { } public getCurrentOutType(): CurrentOutType | undefined { - return !Utils.isUndefined(this.stationInfo.currentOutType) ? this.stationInfo.currentOutType : CurrentOutType.AC; + return this.stationInfo.currentOutType ?? CurrentOutType.AC; } public getVoltageOut(): number | undefined { @@ -169,6 +169,10 @@ export default class ChargingStation { return this.stationInfo.mainVoltageMeterValues ?? true; } + public getPhaseLineToLineVoltage(): boolean { + return this.stationInfo.phaseLineToLineVoltage ?? false; + } + public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined { if (this.getMeteringPerTransaction()) { for (const connector in this.connectors) { @@ -211,11 +215,14 @@ export default class ChargingStation { public getSampledValueTemplate(connectorId: number, measurand: MeterValueMeasurand = MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER, phase?: MeterValuePhase): SampledValueTemplate | undefined { if (!Constants.SUPPORTED_MEASURANDS.includes(measurand)) { - logger.warn(`${this.logPrefix()} Unsupported MeterValues measurand ${measurand} in template on connectorId ${connectorId}`); + logger.warn(`${this.logPrefix()} Trying to get unsupported MeterValues measurand ${measurand} ${phase ? `on phase ${phase} ` : ''}in template on connectorId ${connectorId}`); + return; + } + if (measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER && !this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(measurand)) { + logger.warn(`${this.logPrefix()} Trying to get MeterValues measurand ${measurand} ${phase ? `on phase ${phase} ` : ''}in template on connectorId ${connectorId} not found in '${StandardParametersKey.MeterValuesSampledData}' OCPP parameter`); return; } const sampledValueTemplates: SampledValueTemplate[] = this.getConnector(connectorId).MeterValues; - let defaultMeasurandFound = false; for (let index = 0; !Utils.isEmptyArray(sampledValueTemplates) && index < sampledValueTemplates.length; index++) { if (phase && sampledValueTemplates[index]?.phase === phase && sampledValueTemplates[index]?.measurand === measurand && this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(measurand)) { @@ -225,12 +232,11 @@ export default class ChargingStation { return sampledValueTemplates[index]; } else if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER && (!sampledValueTemplates[index].measurand || sampledValueTemplates[index].measurand === measurand)) { - defaultMeasurandFound = true; return sampledValueTemplates[index]; } } - if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER && !defaultMeasurandFound) { - logger.error(`${this.logPrefix()} Missing MeterValues for default measurand ${MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER} in template on connectorId ${connectorId}`); + if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER) { + logger.error(`${this.logPrefix()} Missing MeterValues for default measurand ${measurand} in template on connectorId ${connectorId}`); } logger.debug(`${this.logPrefix()} No MeterValues for measurand ${measurand} ${phase ? `on phase ${phase} ` : ''}in template on connectorId ${connectorId}`); } diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index f011a54c..628c1203 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -139,7 +139,6 @@ export default class OCPP16RequestService extends OCPPRequestService { if (self.chargingStation.getNumberOfPhases() !== 3 || (self.chargingStation.getNumberOfPhases() === 3 && self.chargingStation.getMainVoltageMeterValues())) { meterValue.sampledValue.push(OCPP16ServiceUtils.buildSampledValue(voltageSampledValueTemplate, voltageMeasurandValue)); } - const defaultVoltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(VoltageOut.VOLTAGE_400, fluctuationPercent); for (let phase = 1; self.chargingStation.getNumberOfPhases() === 3 && phase <= self.chargingStation.getNumberOfPhases(); phase++) { const phaseLineToNeutralValue = `L${phase}-N`; const voltagePhaseLineToNeutralSampledValueTemplate = self.chargingStation.getSampledValueTemplate(connectorId, OCPP16MeterValueMeasurand.VOLTAGE, @@ -152,16 +151,19 @@ export default class OCPP16RequestService extends OCPPRequestService { } meterValue.sampledValue.push(OCPP16ServiceUtils.buildSampledValue(voltagePhaseLineToNeutralSampledValueTemplate ?? voltageSampledValueTemplate, voltagePhaseLineToNeutralMeasurandValue ?? voltageMeasurandValue, null, phaseLineToNeutralValue as OCPP16MeterValuePhase)); - const phaseLineToLineValue = `L${phase}-L${(phase + 1) % self.chargingStation.getNumberOfPhases() !== 0 ? (phase + 1) % self.chargingStation.getNumberOfPhases() : self.chargingStation.getNumberOfPhases()}`; - const voltagePhaseLineToLineSampledValueTemplate = self.chargingStation.getSampledValueTemplate(connectorId, OCPP16MeterValueMeasurand.VOLTAGE, phaseLineToLineValue as OCPP16MeterValuePhase); - let voltagePhaseLineToLineMeasurandValue: number; - if (voltagePhaseLineToLineSampledValueTemplate) { - const voltagePhaseLineToLineSampledValueTemplateValue = voltagePhaseLineToLineSampledValueTemplate.value ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) : VoltageOut.VOLTAGE_400; - const fluctuationPhaseLineToLinePercent = voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; - voltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(voltagePhaseLineToLineSampledValueTemplateValue, fluctuationPhaseLineToLinePercent); + if (self.chargingStation.getPhaseLineToLineVoltage()) { + const phaseLineToLineValue = `L${phase}-L${(phase + 1) % self.chargingStation.getNumberOfPhases() !== 0 ? (phase + 1) % self.chargingStation.getNumberOfPhases() : self.chargingStation.getNumberOfPhases()}`; + const voltagePhaseLineToLineSampledValueTemplate = self.chargingStation.getSampledValueTemplate(connectorId, OCPP16MeterValueMeasurand.VOLTAGE, phaseLineToLineValue as OCPP16MeterValuePhase); + let voltagePhaseLineToLineMeasurandValue: number; + if (voltagePhaseLineToLineSampledValueTemplate) { + const voltagePhaseLineToLineSampledValueTemplateValue = voltagePhaseLineToLineSampledValueTemplate.value ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) : VoltageOut.VOLTAGE_400; + const fluctuationPhaseLineToLinePercent = voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; + voltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(voltagePhaseLineToLineSampledValueTemplateValue, fluctuationPhaseLineToLinePercent); + } + const defaultVoltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(VoltageOut.VOLTAGE_400, fluctuationPercent); + meterValue.sampledValue.push(OCPP16ServiceUtils.buildSampledValue(voltagePhaseLineToLineSampledValueTemplate ?? voltageSampledValueTemplate, + voltagePhaseLineToLineMeasurandValue ?? defaultVoltagePhaseLineToLineMeasurandValue, null, phaseLineToLineValue as OCPP16MeterValuePhase)); } - meterValue.sampledValue.push(OCPP16ServiceUtils.buildSampledValue(voltagePhaseLineToLineSampledValueTemplate ?? voltageSampledValueTemplate, - voltagePhaseLineToLineMeasurandValue ?? defaultVoltagePhaseLineToLineMeasurandValue, null, phaseLineToLineValue as OCPP16MeterValuePhase)); } } // Power.Active.Import measurand diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 3b08cdae..0c90c622 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -63,6 +63,7 @@ export default interface ChargingStationTemplate { meteringPerTransaction?: boolean; transactionDataMeterValues?: boolean; mainVoltageMeterValues?: boolean; + phaseLineToLineVoltage?: boolean; Configuration?: ChargingStationConfiguration; AutomaticTransactionGenerator: AutomaticTransactionGenerator; Connectors: Connectors; -- 2.34.1