X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=02cbac8d48ae1710c638e592ea4f9b5569ea4f56;hb=74ed61d9509bdf19991b404c0db95af2f7302c70;hp=537449dfbcc55a3149f5c25792ac3982b1640c3c;hpb=c4ab56bac3353a08b0b7e058e9edfcfc0e629c94;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 537449df..02cbac8d 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -123,7 +123,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${socMinimumValue}/${ meterValue.sampledValue[sampledValuesIndex].value - }/${socMaximumValue}}`, + }/${socMaximumValue}`, ); } } @@ -136,7 +136,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { if (voltageSampledValueTemplate) { const voltageSampledValueTemplateValue = voltageSampledValueTemplate.value ? parseInt(voltageSampledValueTemplate.value) - : chargingStation.getVoltageOut(); + : chargingStation.stationInfo.voltageOut!; const fluctuationPercent = voltageSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; const voltageMeasurandValue = getRandomFloatFluctuatedRounded( @@ -145,7 +145,8 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ); if ( chargingStation.getNumberOfPhases() !== 3 || - (chargingStation.getNumberOfPhases() === 3 && chargingStation.getMainVoltageMeterValues()) + (chargingStation.getNumberOfPhases() === 3 && + chargingStation.stationInfo?.mainVoltageMeterValues) ) { meterValue.sampledValue.push( OCPP16ServiceUtils.buildSampledValue(voltageSampledValueTemplate, voltageMeasurandValue), @@ -169,7 +170,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { const voltagePhaseLineToNeutralSampledValueTemplateValue = voltagePhaseLineToNeutralSampledValueTemplate.value ? parseInt(voltagePhaseLineToNeutralSampledValueTemplate.value) - : chargingStation.getVoltageOut(); + : chargingStation.stationInfo.voltageOut!; const fluctuationPhaseToNeutralPercent = voltagePhaseLineToNeutralSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; @@ -186,7 +187,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { phaseLineToNeutralValue as OCPP16MeterValuePhase, ), ); - if (chargingStation.getPhaseLineToLineVoltageMeterValues()) { + if (chargingStation.stationInfo?.phaseLineToLineVoltageMeterValues) { const phaseLineToLineValue = `L${phase}-L${ (phase + 1) % chargingStation.getNumberOfPhases() !== 0 ? (phase + 1) % chargingStation.getNumberOfPhases() @@ -265,7 +266,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { const errMsg = `MeterValues measurand ${ powerSampledValueTemplate.measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: Unknown ${chargingStation.getCurrentOutType()} currentOutType in template file ${ + }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${ chargingStation.templateFile }, cannot calculate ${ powerSampledValueTemplate.measurand ?? @@ -283,7 +284,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { const connectorMinimumPowerPerPhase = Math.round( connectorMinimumPower / chargingStation.getNumberOfPhases(), ); - switch (chargingStation.getCurrentOutType()) { + switch (chargingStation.stationInfo?.currentOutType) { case CurrentType.AC: if (chargingStation.getNumberOfPhases() === 3) { const defaultFluctuatedPowerPerPhase = @@ -292,7 +293,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerSampledValueTemplate.value, connectorMaximumPower / unitDivider, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ) / chargingStation.getNumberOfPhases(), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -303,7 +307,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerPerPhaseSampledValueTemplates.L1.value, connectorMaximumPowerPerPhase / unitDivider, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), powerPerPhaseSampledValueTemplates.L1.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -314,7 +321,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerPerPhaseSampledValueTemplates.L2.value, connectorMaximumPowerPerPhase / unitDivider, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), powerPerPhaseSampledValueTemplates.L2.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -325,7 +335,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerPerPhaseSampledValueTemplates.L3.value, connectorMaximumPowerPerPhase / unitDivider, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), powerPerPhaseSampledValueTemplates.L3.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -357,7 +370,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerSampledValueTemplate.value, connectorMaximumPower / unitDivider, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -380,7 +396,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( powerSampledValueTemplate.value, connectorMaximumPower / unitDivider, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -501,7 +520,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { const errMsg = `MeterValues measurand ${ currentSampledValueTemplate.measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: Unknown ${chargingStation.getCurrentOutType()} currentOutType in template file ${ + }: Unknown ${chargingStation.stationInfo?.currentOutType} currentOutType in template file ${ chargingStation.templateFile }, cannot calculate ${ currentSampledValueTemplate.measurand ?? @@ -512,12 +531,12 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { chargingStation.getConnectorMaximumAvailablePower(connectorId); const connectorMinimumAmperage = currentSampledValueTemplate.minimumValue ?? 0; let connectorMaximumAmperage: number; - switch (chargingStation.getCurrentOutType()) { + switch (chargingStation.stationInfo?.currentOutType) { case CurrentType.AC: connectorMaximumAmperage = ACElectricUtils.amperagePerPhaseFromPower( chargingStation.getNumberOfPhases(), connectorMaximumAvailablePower, - chargingStation.getVoltageOut(), + chargingStation.stationInfo.voltageOut!, ); if (chargingStation.getNumberOfPhases() === 3) { const defaultFluctuatedAmperagePerPhase = @@ -526,7 +545,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentSampledValueTemplate.value, connectorMaximumAmperage, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), currentSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -537,7 +559,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentPerPhaseSampledValueTemplates.L1.value, connectorMaximumAmperage, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), currentPerPhaseSampledValueTemplates.L1.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -548,7 +573,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentPerPhaseSampledValueTemplates.L2.value, connectorMaximumAmperage, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), currentPerPhaseSampledValueTemplates.L2.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -559,7 +587,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentPerPhaseSampledValueTemplates.L3.value, connectorMaximumAmperage, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), currentPerPhaseSampledValueTemplates.L3.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -582,7 +613,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentSampledValueTemplate.value, connectorMaximumAmperage, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), currentSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -600,14 +634,17 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { case CurrentType.DC: connectorMaximumAmperage = DCElectricUtils.amperage( connectorMaximumAvailablePower, - chargingStation.getVoltageOut(), + chargingStation.stationInfo.voltageOut!, ); currentMeasurandValues.allPhases = currentSampledValueTemplate.value ? getRandomFloatFluctuatedRounded( OCPP16ServiceUtils.getLimitFromSampledValueTemplateCustomValue( currentSampledValueTemplate.value, connectorMaximumAmperage, - { limitationEnabled: chargingStation.getCustomValueLimitationMeterValues() }, + { + limitationEnabled: + chargingStation.stationInfo?.customValueLimitationMeterValues, + }, ), currentSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT, @@ -703,7 +740,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { energySampledValueTemplate.value, connectorMaximumEnergyRounded, { - limitationEnabled: chargingStation.getCustomValueLimitationMeterValues(), + limitationEnabled: chargingStation.stationInfo?.customValueLimitationMeterValues, unitMultiplier: unitDivider, }, ), @@ -935,21 +972,21 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { public static composeChargingSchedules = ( chargingScheduleHigher: OCPP16ChargingSchedule | undefined, chargingScheduleLower: OCPP16ChargingSchedule | undefined, - targetInterval: Interval, + compositeInterval: Interval, ): OCPP16ChargingSchedule | undefined => { if (!chargingScheduleHigher && !chargingScheduleLower) { return undefined; } if (chargingScheduleHigher && !chargingScheduleLower) { - return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher, targetInterval); + return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher, compositeInterval); } if (!chargingScheduleHigher && chargingScheduleLower) { - return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower, targetInterval); + return OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower, compositeInterval); } const compositeChargingScheduleHigher: OCPP16ChargingSchedule | undefined = - OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher!, targetInterval); + OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleHigher!, compositeInterval); const compositeChargingScheduleLower: OCPP16ChargingSchedule | undefined = - OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower!, targetInterval); + OCPP16ServiceUtils.composeChargingSchedule(chargingScheduleLower!, compositeInterval); const compositeChargingScheduleHigherInterval: Interval = { start: compositeChargingScheduleHigher!.startSchedule!, end: addSeconds( @@ -1086,7 +1123,6 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { }, ) ) { - schedulePeriod.startPeriod = 0; return false; } if ( @@ -1106,7 +1142,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { } return true; }) - .map((schedulePeriod) => { + .map((schedulePeriod, index) => { + if (index === 0 && schedulePeriod.startPeriod !== 0) { + schedulePeriod.startPeriod = 0; + } return { ...schedulePeriod, startPeriod: higherFirst @@ -1165,25 +1204,28 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { private static composeChargingSchedule = ( chargingSchedule: OCPP16ChargingSchedule, - targetInterval: Interval, + compositeInterval: Interval, ): OCPP16ChargingSchedule | undefined => { const chargingScheduleInterval: Interval = { start: chargingSchedule.startSchedule!, end: addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), }; - if (areIntervalsOverlapping(chargingScheduleInterval, targetInterval)) { + if (areIntervalsOverlapping(chargingScheduleInterval, compositeInterval)) { chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); - if (isBefore(chargingScheduleInterval.start, targetInterval.start)) { + if (isBefore(chargingScheduleInterval.start, compositeInterval.start)) { return { ...chargingSchedule, - startSchedule: targetInterval.start as Date, - duration: differenceInSeconds(chargingScheduleInterval.end, targetInterval.start as Date), - chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter( - (schedulePeriod, index) => { + startSchedule: compositeInterval.start as Date, + duration: differenceInSeconds( + chargingScheduleInterval.end, + compositeInterval.start as Date, + ), + chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod + .filter((schedulePeriod, index) => { if ( isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, - targetInterval, + compositeInterval, ) ) { return true; @@ -1192,32 +1234,39 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { index < chargingSchedule.chargingSchedulePeriod.length - 1 && !isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod), - targetInterval, + compositeInterval, ) && isWithinInterval( addSeconds( chargingScheduleInterval.start, chargingSchedule.chargingSchedulePeriod[index + 1].startPeriod, ), - targetInterval, + compositeInterval, ) ) { - schedulePeriod.startPeriod = 0; return true; } return false; - }, - ), + }) + .map((schedulePeriod, index) => { + if (index === 0 && schedulePeriod.startPeriod !== 0) { + schedulePeriod.startPeriod = 0; + } + return schedulePeriod; + }), }; } - if (isAfter(chargingScheduleInterval.end, targetInterval.end)) { + if (isAfter(chargingScheduleInterval.end, compositeInterval.end)) { return { ...chargingSchedule, - duration: differenceInSeconds(targetInterval.end as Date, chargingScheduleInterval.start), + duration: differenceInSeconds( + compositeInterval.end as Date, + chargingScheduleInterval.start, + ), chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter((schedulePeriod) => isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, - targetInterval, + compositeInterval, ), ), }; @@ -1232,12 +1281,12 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { context?: MeterValueContext, phase?: OCPP16MeterValuePhase, ): OCPP16SampledValue { - const sampledValueValue = value ?? sampledValueTemplate?.value ?? null; - const sampledValueContext = context ?? sampledValueTemplate?.context ?? null; + const sampledValueValue = value ?? sampledValueTemplate?.value; + const sampledValueContext = context ?? sampledValueTemplate?.context; const sampledValueLocation = sampledValueTemplate?.location ?? OCPP16ServiceUtils.getMeasurandDefaultLocation(sampledValueTemplate.measurand!); - const sampledValuePhase = phase ?? sampledValueTemplate?.phase ?? null; + const sampledValuePhase = phase ?? sampledValueTemplate?.phase; return { ...(!isNullOrUndefined(sampledValueTemplate.unit) && { unit: sampledValueTemplate.unit,