Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
const connectorMaximumPowerPerPhase = Math.round(
connectorMaximumAvailablePower / chargingStation.getNumberOfPhases(),
);
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(),
);
const connectorMinimumPowerPerPhase = Math.round(
connectorMinimumPower / chargingStation.getNumberOfPhases(),
);
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerSampledValueTemplate.value,
connectorMaximumPower / unitDivider,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerSampledValueTemplate.value,
connectorMaximumPower / unitDivider,
+ connectorMinimumPower / unitDivider,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumPower / unitDivider,
+ fallbackValue: connectorMinimumPower / unitDivider,
},
) / chargingStation.getNumberOfPhases(),
powerSampledValueTemplate.fluctuationPercent ??
},
) / chargingStation.getNumberOfPhases(),
powerSampledValueTemplate.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerPerPhaseSampledValueTemplates.L1.value,
connectorMaximumPowerPerPhase / unitDivider,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerPerPhaseSampledValueTemplates.L1.value,
connectorMaximumPowerPerPhase / unitDivider,
+ connectorMinimumPowerPerPhase / unitDivider,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumPowerPerPhase / unitDivider,
+ fallbackValue: connectorMinimumPowerPerPhase / unitDivider,
},
),
powerPerPhaseSampledValueTemplates.L1.fluctuationPercent ??
},
),
powerPerPhaseSampledValueTemplates.L1.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerPerPhaseSampledValueTemplates.L2.value,
connectorMaximumPowerPerPhase / unitDivider,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerPerPhaseSampledValueTemplates.L2.value,
connectorMaximumPowerPerPhase / unitDivider,
+ connectorMinimumPowerPerPhase / unitDivider,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumPowerPerPhase / unitDivider,
+ fallbackValue: connectorMinimumPowerPerPhase / unitDivider,
},
),
powerPerPhaseSampledValueTemplates.L2.fluctuationPercent ??
},
),
powerPerPhaseSampledValueTemplates.L2.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerPerPhaseSampledValueTemplates.L3.value,
connectorMaximumPowerPerPhase / unitDivider,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerPerPhaseSampledValueTemplates.L3.value,
connectorMaximumPowerPerPhase / unitDivider,
+ connectorMinimumPowerPerPhase / unitDivider,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumPowerPerPhase / unitDivider,
+ fallbackValue: connectorMinimumPowerPerPhase / unitDivider,
},
),
powerPerPhaseSampledValueTemplates.L3.fluctuationPercent ??
},
),
powerPerPhaseSampledValueTemplates.L3.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerSampledValueTemplate.value,
connectorMaximumPower / unitDivider,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerSampledValueTemplate.value,
connectorMaximumPower / unitDivider,
+ connectorMinimumPower / unitDivider,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumPower / unitDivider,
+ fallbackValue: connectorMinimumPower / unitDivider,
},
),
powerSampledValueTemplate.fluctuationPercent ??
},
),
powerSampledValueTemplate.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerSampledValueTemplate.value,
connectorMaximumPower / unitDivider,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
powerSampledValueTemplate.value,
connectorMaximumPower / unitDivider,
+ connectorMinimumPower / unitDivider,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumPower / unitDivider,
+ fallbackValue: connectorMinimumPower / unitDivider,
},
),
powerSampledValueTemplate.fluctuationPercent ??
},
),
powerSampledValueTemplate.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentSampledValueTemplate.value,
connectorMaximumAmperage,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentSampledValueTemplate.value,
connectorMaximumAmperage,
+ connectorMinimumAmperage,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumAmperage,
+ fallbackValue: connectorMinimumAmperage,
},
),
currentSampledValueTemplate.fluctuationPercent ??
},
),
currentSampledValueTemplate.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentPerPhaseSampledValueTemplates.L1.value,
connectorMaximumAmperage,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentPerPhaseSampledValueTemplates.L1.value,
connectorMaximumAmperage,
+ connectorMinimumAmperage,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumAmperage,
+ fallbackValue: connectorMinimumAmperage,
},
),
currentPerPhaseSampledValueTemplates.L1.fluctuationPercent ??
},
),
currentPerPhaseSampledValueTemplates.L1.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentPerPhaseSampledValueTemplates.L2.value,
connectorMaximumAmperage,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentPerPhaseSampledValueTemplates.L2.value,
connectorMaximumAmperage,
+ connectorMinimumAmperage,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumAmperage,
+ fallbackValue: connectorMinimumAmperage,
},
),
currentPerPhaseSampledValueTemplates.L2.fluctuationPercent ??
},
),
currentPerPhaseSampledValueTemplates.L2.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentPerPhaseSampledValueTemplates.L3.value,
connectorMaximumAmperage,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentPerPhaseSampledValueTemplates.L3.value,
connectorMaximumAmperage,
+ connectorMinimumAmperage,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumAmperage,
+ fallbackValue: connectorMinimumAmperage,
},
),
currentPerPhaseSampledValueTemplates.L3.fluctuationPercent ??
},
),
currentPerPhaseSampledValueTemplates.L3.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentSampledValueTemplate.value,
connectorMaximumAmperage,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentSampledValueTemplate.value,
connectorMaximumAmperage,
+ connectorMinimumAmperage,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumAmperage,
+ fallbackValue: connectorMinimumAmperage,
},
),
currentSampledValueTemplate.fluctuationPercent ??
},
),
currentSampledValueTemplate.fluctuationPercent ??
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentSampledValueTemplate.value,
connectorMaximumAmperage,
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
currentSampledValueTemplate.value,
connectorMaximumAmperage,
+ connectorMinimumAmperage,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
{
limitationEnabled:
chargingStation.stationInfo?.customValueLimitationMeterValues,
- defaultValue: connectorMinimumAmperage,
+ fallbackValue: connectorMinimumAmperage,
},
),
currentSampledValueTemplate.fluctuationPercent ??
},
),
currentSampledValueTemplate.fluctuationPercent ??
(connectorMaximumAvailablePower * interval) / (3600 * 1000),
2,
);
(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(
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
energySampledValueTemplate.value,
connectorMaximumEnergyRounded,
const energyValueRounded = isNotEmptyString(energySampledValueTemplate.value)
? // Cumulate the fluctuated value around the static one
getRandomFloatFluctuatedRounded(
OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue(
energySampledValueTemplate.value,
connectorMaximumEnergyRounded,
+ connectorMinimumEnergyRounded,
{
limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues,
unitMultiplier: unitDivider,
{
limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues,
unitMultiplier: unitDivider,
+ fallbackValue: connectorMinimumEnergyRounded,
},
),
energySampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT,
)
},
),
energySampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT,
)
- : getRandomFloatRounded(connectorMaximumEnergyRounded);
+ : getRandomFloatRounded(connectorMaximumEnergyRounded, connectorMinimumEnergyRounded);
// Persist previous value on connector
if (connector) {
if (
// Persist previous value on connector
if (connector) {
if (
),
);
const sampledValuesIndex = meterValue.sampledValue.length - 1;
),
);
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
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`,
isNotEmptyString,
logPrefix,
logger,
isNotEmptyString,
logPrefix,
logger,
min,
} from '../../utils';
min,
} from '../../utils';
protected static getLimitFromSampledValueTemplateCustomValue(
value: string,
protected static getLimitFromSampledValueTemplateCustomValue(
value: string,
- limit: number,
- options?: { limitationEnabled?: boolean; unitMultiplier?: number; defaultValue?: number },
+ maxLimit: number,
+ minLimit: number,
+ options?: { limitationEnabled?: boolean; fallbackValue?: number; unitMultiplier?: number },
): number {
options = {
...{
limitationEnabled: true,
unitMultiplier: 1,
): number {
options = {
...{
limitationEnabled: true,
unitMultiplier: 1,
},
...options,
};
const parsedValue = parseInt(value);
if (options?.limitationEnabled) {
},
...options,
};
const parsedValue = parseInt(value);
if (options?.limitationEnabled) {
- return min((!isNaN(parsedValue) ? parsedValue : Infinity) * options.unitMultiplier!, limit);
+ return max(
+ min((!isNaN(parsedValue) ? parsedValue : Infinity) * options.unitMultiplier!, maxLimit),
+ minLimit,
+ );
- return (!isNaN(parsedValue) ? parsedValue : options.defaultValue!) * options.unitMultiplier!;
+ return (!isNaN(parsedValue) ? parsedValue : options.fallbackValue!) * options.unitMultiplier!;
}
private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {
}
private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean {