From 7645760b75ac201b8ec0b8378b986cabacce7807 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 11 Aug 2022 22:24:12 +0200 Subject: [PATCH] Improve supported OCPP commands filtering MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../chargex.station-template.json | 1 - src/charging-station/ChargingStationUtils.ts | 36 +++++++++++++------ .../ocpp/1.6/OCPP16IncomingRequestService.ts | 2 +- .../ocpp/1.6/OCPP16RequestService.ts | 2 +- .../ocpp/1.6/OCPP16ResponseService.ts | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) 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); -- 2.34.1