X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=c73c32dc2ce940f9c017550183a44dd45a3a7a43;hb=66dd344779f5258bbf4c76b386d005c0c2160b11;hp=23381f9ec3dd63e5e47faed0301fc6fecbc01f75;hpb=041936041d9803859ac2faad9316c20e49b658c9;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 23381f9e..c73c32dc 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -2,7 +2,7 @@ import type { JSONSchemaType } from 'ajv'; -import type { ChargingStation } from '../../../charging-station'; +import { type ChargingStation, ChargingStationUtils } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { CurrentType, @@ -13,6 +13,9 @@ import { MeterValueContext, MeterValueLocation, MeterValueUnit, + OCPP16AuthorizationStatus, + type OCPP16AuthorizeRequest, + type OCPP16AuthorizeResponse, type OCPP16ChargingProfile, type OCPP16IncomingRequestCommand, type OCPP16MeterValue, @@ -837,6 +840,30 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ); } + public static async isIdTagAuthorized( + chargingStation: ChargingStation, + connectorId: number, + idTag: string, + parentIdTag?: string + ): Promise { + let authorized = false; + const 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, @@ -912,4 +939,30 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { return MeterValueUnit.VOLT; } } + + private static isIdTagLocalAuthorized(chargingStation: ChargingStation, idTag: string): boolean { + return ( + chargingStation.getLocalAuthListEnabled() === true && + chargingStation.hasIdTags() === true && + Utils.isNotEmptyString( + chargingStation.idTagsCache + .getIdTags(ChargingStationUtils.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; + } }