X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=734bfcd26f872069c4a8995ab56ff4656e6a370f;hb=c6dcc3311af6547a0d2d618b8c27a84424c27b4b;hp=63339cf245db3a7ed84bbae3961be76eee14ae42;hpb=77684af8bb6c39f9c1e2eb8e0f9ac8c0f1dd7855;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 63339cf2..734bfcd2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -194,6 +194,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ? (phase + 1) % chargingStation.getNumberOfPhases() : chargingStation.getNumberOfPhases() }`; + const voltagePhaseLineToLineValueRounded = roundTo( + Math.sqrt(chargingStation.getNumberOfPhases()) * + chargingStation.stationInfo.voltageOut!, + 2, + ); const voltagePhaseLineToLineSampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate( chargingStation, @@ -207,11 +212,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { voltagePhaseLineToLineSampledValueTemplate.value, ) ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) - : roundTo( - Math.sqrt(chargingStation.getNumberOfPhases()) * - chargingStation.stationInfo.voltageOut!, - 2, - ); + : voltagePhaseLineToLineValueRounded; const fluctuationPhaseLineToLinePercent = voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; @@ -221,8 +222,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ); } const defaultVoltagePhaseLineToLineMeasurandValue = getRandomFloatFluctuatedRounded( - Math.sqrt(chargingStation.getNumberOfPhases()) * - chargingStation.stationInfo.voltageOut!, + voltagePhaseLineToLineValueRounded, fluctuationPercent, ); meterValue.sampledValue.push( @@ -287,7 +287,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { const connectorMaximumPowerPerPhase = Math.round( connectorMaximumAvailablePower / chargingStation.getNumberOfPhases(), ); - const connectorMinimumPower = Math.round(powerSampledValueTemplate.minimumValue!) ?? 0; + const connectorMinimumPower = Math.round(powerSampledValueTemplate.minimumValue ?? 0); const connectorMinimumPowerPerPhase = Math.round( connectorMinimumPower / chargingStation.getNumberOfPhases(), ); @@ -300,9 +300,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerSampledValueTemplate.value, connectorMaximumPower / unitDivider, + connectorMinimumPower / unitDivider, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumPower / unitDivider, }, ) / chargingStation.getNumberOfPhases(), powerSampledValueTemplate.fluctuationPercent ?? @@ -314,9 +316,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerPerPhaseSampledValueTemplates.L1.value, connectorMaximumPowerPerPhase / unitDivider, + connectorMinimumPowerPerPhase / unitDivider, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumPowerPerPhase / unitDivider, }, ), powerPerPhaseSampledValueTemplates.L1.fluctuationPercent ?? @@ -328,9 +332,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerPerPhaseSampledValueTemplates.L2.value, connectorMaximumPowerPerPhase / unitDivider, + connectorMinimumPowerPerPhase / unitDivider, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumPowerPerPhase / unitDivider, }, ), powerPerPhaseSampledValueTemplates.L2.fluctuationPercent ?? @@ -342,9 +348,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerPerPhaseSampledValueTemplates.L3.value, connectorMaximumPowerPerPhase / unitDivider, + connectorMinimumPowerPerPhase / unitDivider, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumPowerPerPhase / unitDivider, }, ), powerPerPhaseSampledValueTemplates.L3.fluctuationPercent ?? @@ -372,14 +380,16 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { connectorMinimumPowerPerPhase / unitDivider, ); } else { - powerMeasurandValues.L1 = powerSampledValueTemplate.value + powerMeasurandValues.L1 = isNotEmptyString(powerSampledValueTemplate.value) ? getRandomFloatFluctuatedRounded( OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerSampledValueTemplate.value, connectorMaximumPower / unitDivider, + connectorMinimumPower / unitDivider, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumPower / unitDivider, }, ), powerSampledValueTemplate.fluctuationPercent ?? @@ -403,9 +413,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerSampledValueTemplate.value, connectorMaximumPower / unitDivider, + connectorMinimumPower / unitDivider, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumPower / unitDivider, }, ), powerSampledValueTemplate.fluctuationPercent ?? @@ -552,9 +564,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentSampledValueTemplate.value, connectorMaximumAmperage, + connectorMinimumAmperage, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumAmperage, }, ), currentSampledValueTemplate.fluctuationPercent ?? @@ -566,9 +580,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentPerPhaseSampledValueTemplates.L1.value, connectorMaximumAmperage, + connectorMinimumAmperage, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumAmperage, }, ), currentPerPhaseSampledValueTemplates.L1.fluctuationPercent ?? @@ -580,9 +596,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentPerPhaseSampledValueTemplates.L2.value, connectorMaximumAmperage, + connectorMinimumAmperage, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumAmperage, }, ), currentPerPhaseSampledValueTemplates.L2.fluctuationPercent ?? @@ -594,9 +612,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentPerPhaseSampledValueTemplates.L3.value, connectorMaximumAmperage, + connectorMinimumAmperage, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumAmperage, }, ), currentPerPhaseSampledValueTemplates.L3.fluctuationPercent ?? @@ -620,9 +640,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentSampledValueTemplate.value, connectorMaximumAmperage, + connectorMinimumAmperage, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumAmperage, }, ), currentSampledValueTemplate.fluctuationPercent ?? @@ -648,9 +670,11 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentSampledValueTemplate.value, connectorMaximumAmperage, + connectorMinimumAmperage, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, + fallbackValue: connectorMinimumAmperage, }, ), currentSampledValueTemplate.fluctuationPercent ?? @@ -740,20 +764,25 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { (connectorMaximumAvailablePower * interval) / (3600 * 1000), 2, ); + const connectorMinimumEnergyRounded = roundTo( + energySampledValueTemplate.minimumValue ?? 0, + 2, + ); const energyValueRounded = isNotEmptyString(energySampledValueTemplate.value) - ? // Cumulate the fluctuated value around the static one - getRandomFloatFluctuatedRounded( + ? getRandomFloatFluctuatedRounded( OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( energySampledValueTemplate.value, connectorMaximumEnergyRounded, + connectorMinimumEnergyRounded, { limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, unitMultiplier: unitDivider, + fallbackValue: connectorMinimumEnergyRounded, }, ), energySampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, ) - : getRandomFloatRounded(connectorMaximumEnergyRounded); + : getRandomFloatRounded(connectorMaximumEnergyRounded, connectorMinimumEnergyRounded); // Persist previous value on connector if (connector) { if ( @@ -780,12 +809,16 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ), ); const sampledValuesIndex = meterValue.sampledValue.length - 1; - if (energyValueRounded > connectorMaximumEnergyRounded || debug) { + if ( + energyValueRounded > connectorMaximumEnergyRounded || + energyValueRounded < connectorMinimumEnergyRounded || + debug + ) { logger.error( `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${interval}ms`, + }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${connectorMinimumEnergyRounded}/${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${interval}ms`, ); } }