X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=7f065d30bed7dd29c684edaa358c82c0866cbe9e;hb=d8093be156ab575dbd44546ef4646a6338a27358;hp=c3e708df176d8c08a8c7f8a85c1bd99e0927dbcd;hpb=a37fc6dc8267e22b2b2d35773525980b81f014e8;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 c3e708df..7f065d30 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -2,9 +2,10 @@ import type { JSONSchemaType } from 'ajv'; -import { type ChargingStation, getIdTagsFile } from '../../../charging-station'; +import { type ChargingStation, getIdTagsFile, hasFeatureProfile } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { + type ClearChargingProfileRequest, type ConnectorStatus, CurrentType, ErrorType, @@ -54,7 +55,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { featureProfile: OCPP16SupportedFeatureProfiles, command: OCPP16RequestCommand | OCPP16IncomingRequestCommand, ): boolean { - if (!chargingStation.hasFeatureProfile(featureProfile)) { + if (!hasFeatureProfile(chargingStation, featureProfile)) { logger.warn( `${chargingStation.logPrefix()} Trying to '${command}' without '${featureProfile}' feature enabled in ${ OCPP16StandardParametersKey.SupportedFeatureProfiles @@ -725,10 +726,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${roundTo( - interval / (3600 * 1000), - 4, - )}h`, + }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${interval}ms`, ); } } @@ -832,6 +830,49 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { !cpReplaced && chargingStation.getConnectorStatus(connectorId)?.chargingProfiles?.push(cp); } + public static clearChargingProfiles = ( + chargingStation: ChargingStation, + commandPayload: ClearChargingProfileRequest, + chargingProfiles: OCPP16ChargingProfile[] | undefined, + ): boolean => { + let clearedCP = false; + if (isNotEmptyArray(chargingProfiles)) { + chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { + let clearCurrentCP = false; + if (chargingProfile.chargingProfileId === commandPayload.id) { + clearCurrentCP = true; + } + if ( + !commandPayload.chargingProfilePurpose && + chargingProfile.stackLevel === commandPayload.stackLevel + ) { + clearCurrentCP = true; + } + if ( + !chargingProfile.stackLevel && + chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose + ) { + clearCurrentCP = true; + } + if ( + chargingProfile.stackLevel === commandPayload.stackLevel && + chargingProfile.chargingProfilePurpose === commandPayload.chargingProfilePurpose + ) { + clearCurrentCP = true; + } + if (clearCurrentCP) { + chargingProfiles.splice(index, 1); + logger.debug( + `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`, + chargingProfile, + ); + clearedCP = true; + } + }); + } + return clearedCP; + }; + public static parseJsonSchemaFile( relativePath: string, moduleName?: string,