X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=cf055beb949d05f5844c86a450fd6cfc27c7f8ee;hb=366f75f699490d7e6a49714a0517b9ffe7176052;hp=e3899cd5db97ffca80caaa8dc2cbe0b88ddcb829;hpb=991fb26bd3814b583395f5d2623acfae7a3ee3f0;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 e3899cd5..cf055beb 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -2,11 +2,11 @@ import type { JSONSchemaType } from 'ajv'; -import { type ChargingStation, getIdTagsFile } from '../../../charging-station'; +import { OCPP16Constants } from './OCPP16Constants'; +import { type ChargingStation, hasFeatureProfile } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { type ClearChargingProfileRequest, - type ConnectorStatus, CurrentType, ErrorType, type JsonType, @@ -15,9 +15,9 @@ import { MeterValueContext, MeterValueLocation, MeterValueUnit, - OCPP16AuthorizationStatus, - type OCPP16AuthorizeRequest, - type OCPP16AuthorizeResponse, + OCPP16AvailabilityType, + type OCPP16ChangeAvailabilityResponse, + OCPP16ChargePointStatus, type OCPP16ChargingProfile, type OCPP16IncomingRequestCommand, type OCPP16MeterValue, @@ -37,12 +37,10 @@ import { DCElectricUtils, convertToFloat, convertToInt, - formatDurationMilliSeconds, getRandomFloatFluctuatedRounded, getRandomFloatRounded, getRandomInteger, isNotEmptyArray, - isNotEmptyString, isNullOrUndefined, isUndefined, logger, @@ -56,7 +54,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 @@ -727,9 +725,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: ${formatDurationMilliSeconds( - interval, - )}(${roundTo(interval, 4)}ms)`, + }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${interval}ms`, ); } } @@ -796,6 +792,29 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { return meterValues; } + public static changeAvailability = async ( + chargingStation: ChargingStation, + connectorId: number, + chargePointStatus: OCPP16ChargePointStatus, + availabilityType: OCPP16AvailabilityType, + ): Promise => { + let response: OCPP16ChangeAvailabilityResponse = + OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED; + const connectorStatus = chargingStation.getConnectorStatus(connectorId)!; + if (connectorStatus?.transactionStarted === true) { + response = OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED; + } + connectorStatus.availability = availabilityType; + if (response === OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) { + await OCPP16ServiceUtils.sendAndSetConnectorStatus( + chargingStation, + connectorId, + chargePointStatus, + ); + } + return response; + }; + public static setChargingProfile( chargingStation: ChargingStation, connectorId: number, @@ -889,29 +908,6 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ); } - public static async isIdTagAuthorized( - chargingStation: ChargingStation, - connectorId: number, - idTag: string, - ): Promise { - let authorized = false; - const connectorStatus: ConnectorStatus = chargingStation.getConnectorStatus(connectorId)!; - if (OCPP16ServiceUtils.isIdTagLocalAuthorized(chargingStation, idTag)) { - connectorStatus.localAuthorizeIdTag = idTag; - connectorStatus.idTagLocalAuthorized = true; - authorized = true; - } else if (chargingStation.getMustAuthorizeAtRemoteStart() === true) { - connectorStatus.authorizeIdTag = idTag; - authorized = await OCPP16ServiceUtils.isIdTagRemoteAuthorized(chargingStation, idTag); - } else { - logger.warn( - `${chargingStation.logPrefix()} The charging station configuration expects authorize at - remote start transaction but local authorization or authorize isn't enabled`, - ); - } - return authorized; - } - private static buildSampledValue( sampledValueTemplate: SampledValueTemplate, value: number, @@ -987,30 +983,4 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { return MeterValueUnit.VOLT; } } - - private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean { - return ( - chargingStation.getLocalAuthListEnabled() === true && - chargingStation.hasIdTags() === true && - isNotEmptyString( - chargingStation.idTagsCache - .getIdTags(getIdTagsFile(chargingStation.stationInfo)!) - ?.find((tag) => tag === idTag), - ) - ); - } - - private static async isIdTagRemoteAuthorized( - chargingStation: ChargingStation, - idTag: string, - ): Promise { - const authorizeResponse: OCPP16AuthorizeResponse = - await chargingStation.ocppRequestService.requestHandler< - OCPP16AuthorizeRequest, - OCPP16AuthorizeResponse - >(chargingStation, OCPP16RequestCommand.AUTHORIZE, { - idTag: idTag, - }); - return authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED; - } }