From: Jérôme Benoit Date: Thu, 11 Aug 2022 20:24:12 +0000 (+0200) Subject: Improve supported OCPP commands filtering X-Git-Tag: v1.1.65~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7645760b75ac201b8ec0b8378b986cabacce7807;hp=db7d7aa671a7fef2555f0528023d327353b944fd;p=e-mobility-charging-stations-simulator.git Improve supported OCPP commands filtering Signed-off-by: Jérôme Benoit --- diff --git a/src/assets/station-templates/chargex.station-template.json b/src/assets/station-templates/chargex.station-template.json index 057d25df..2630278b 100644 --- a/src/assets/station-templates/chargex.station-template.json +++ b/src/assets/station-templates/chargex.station-template.json @@ -12,7 +12,6 @@ "outOfOrderEndMeterValues": true, "commandsSupport": { "incomingCommands": { - "Authorize": true, "Reset": true, "GetConfiguration": true, "ChangeConfiguration": true, diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index c216ed6b..ad145f0b 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -536,24 +536,38 @@ export class ChargingStationUtils { public static isCommandSupported( command: RequestCommand | IncomingRequestCommand, - stationInfo: ChargingStationInfo + chargingStation: ChargingStation ): boolean { + const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes( + command as IncomingRequestCommand + ); + const isRequestCommand = Object.values(RequestCommand).includes(command as RequestCommand); if ( - Object.values(IncomingRequestCommand).includes(command as IncomingRequestCommand) && - !stationInfo?.commandsSupport?.incomingCommands + isIncomingRequestCommand && + !chargingStation.stationInfo?.commandsSupport?.incomingCommands ) { return true; - } - if ( - Object.values(RequestCommand).includes(command as RequestCommand) && - !stationInfo?.commandsSupport?.outgoingCommands + } else if ( + isIncomingRequestCommand && + chargingStation.stationInfo?.commandsSupport?.incomingCommands + ) { + return ( + (chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] as boolean) ?? + false + ); + } else if ( + isRequestCommand && + !chargingStation.stationInfo?.commandsSupport?.outgoingCommands ) { return true; + } else if (isRequestCommand && chargingStation.stationInfo?.commandsSupport?.outgoingCommands) { + return ( + (chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] as boolean) ?? + false + ); } - return ( - ((stationInfo?.commandsSupport?.incomingCommands[command] as boolean) ?? false) || - ((stationInfo?.commandsSupport?.outgoingCommands[command] as boolean) ?? false) - ); + logger.error(`${chargingStation.logPrefix()} Unknown OCPP command '${command}'`); + return false; } private static getRandomSerialNumberSuffix(params?: { diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 172aa8dd..7495ff0c 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -159,7 +159,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ) { if ( this.incomingRequestHandlers.has(commandName) && - ChargingStationUtils.isCommandSupported(commandName, chargingStation.stationInfo) + ChargingStationUtils.isCommandSupported(commandName, chargingStation) ) { try { // Call the method to build the response diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 78ff8888..1c98bc37 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -31,7 +31,7 @@ export default class OCPP16RequestService extends OCPPRequestService { ): Promise { if ( Object.values(OCPP16RequestCommand).includes(commandName) && - ChargingStationUtils.isCommandSupported(commandName, chargingStation.stationInfo) + ChargingStationUtils.isCommandSupported(commandName, chargingStation) ) { return (await this.sendMessage( chargingStation, diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 47021ca6..3af8a1fc 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -68,7 +68,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { if (chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) { if ( this.responseHandlers.has(commandName) && - ChargingStationUtils.isCommandSupported(commandName, chargingStation.stationInfo) + ChargingStationUtils.isCommandSupported(commandName, chargingStation) ) { try { await this.responseHandlers.get(commandName)(chargingStation, payload, requestPayload);