From 1b6498baa159ac6ebd4eda9008cde367640bf3ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 7 May 2022 23:58:02 +0200 Subject: [PATCH] Factor out power limitation calculation in metervalues MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16ServiceUtils.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 2ad75f1d..721ae1c2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -302,12 +302,11 @@ export class OCPP16ServiceUtils { } measurand value`; const powerMeasurandValues = {} as MeasurandValues; const unitDivider = powerSampledValueTemplate?.unit === MeterValueUnit.KILO_WATT ? 1000 : 1; - const connectorMaximumPower = Math.round( - chargingStation.getConnectorMaximumAvailablePower(connectorId) - ); + const connectorMaximumAvailablePower = + chargingStation.getConnectorMaximumAvailablePower(connectorId); + const connectorMaximumPower = Math.round(connectorMaximumAvailablePower); const connectorMaximumPowerPerPhase = Math.round( - chargingStation.getConnectorMaximumAvailablePower(connectorId) / - chargingStation.getNumberOfPhases() + connectorMaximumAvailablePower / chargingStation.getNumberOfPhases() ); switch (chargingStation.getCurrentOutType()) { case CurrentType.AC: @@ -481,12 +480,14 @@ export class OCPP16ServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER } measurand value`; const currentMeasurandValues: MeasurandValues = {} as MeasurandValues; + const connectorMaximumAvailablePower = + chargingStation.getConnectorMaximumAvailablePower(connectorId); let connectorMaximumAmperage: number; switch (chargingStation.getCurrentOutType()) { case CurrentType.AC: connectorMaximumAmperage = ACElectricUtils.amperagePerPhaseFromPower( chargingStation.getNumberOfPhases(), - chargingStation.getConnectorMaximumAvailablePower(connectorId), + connectorMaximumAvailablePower, chargingStation.getVoltageOut() ); if (chargingStation.getNumberOfPhases() === 3) { @@ -549,7 +550,7 @@ export class OCPP16ServiceUtils { break; case CurrentType.DC: connectorMaximumAmperage = DCElectricUtils.amperage( - chargingStation.getConnectorMaximumAvailablePower(connectorId), + connectorMaximumAvailablePower, chargingStation.getVoltageOut() ); currentMeasurandValues.allPhases = currentSampledValueTemplate.value @@ -628,8 +629,10 @@ export class OCPP16ServiceUtils { ); const unitDivider = energySampledValueTemplate?.unit === MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1; + const connectorMaximumAvailablePower = + chargingStation.getConnectorMaximumAvailablePower(connectorId); const connectorMaximumEnergyRounded = Utils.roundTo( - (chargingStation.getConnectorMaximumAvailablePower(connectorId) * interval) / (3600 * 1000), + (connectorMaximumAvailablePower * interval) / (3600 * 1000), 2 ); const energyValueRounded = energySampledValueTemplate.value -- 2.34.1