Improve supported OCPP commands filtering
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 11 Aug 2022 20:24:12 +0000 (22:24 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 11 Aug 2022 20:24:12 +0000 (22:24 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/assets/station-templates/chargex.station-template.json
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts

index 057d25df40a5c171b53c5cd5a93c983209039330..2630278b0b4bd9ca8a3aefa775b2c7ac71dbdb01 100644 (file)
@@ -12,7 +12,6 @@
   "outOfOrderEndMeterValues": true,
   "commandsSupport": {
     "incomingCommands": {
-      "Authorize": true,
       "Reset": true,
       "GetConfiguration": true,
       "ChangeConfiguration": true,
index c216ed6bec8bae64bb3f2ae84bab9db91ba16d3b..ad145f0b0f8b2cd3be8eb07ae087044484a9a7f1 100644 (file)
@@ -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?: {
index 172aa8dd4a55ec95b1ccf845bcc668f848841b01..7495ff0ceb69ddc30fffbe51fc5fe519d1159bb9 100644 (file)
@@ -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
index 78ff888890826396efe75610dfa6e3f50a632e3f..1c98bc37d4c6b25f2b897f07aea86fa0414014ab 100644 (file)
@@ -31,7 +31,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
   ): Promise<Response> {
     if (
       Object.values(OCPP16RequestCommand).includes(commandName) &&
-      ChargingStationUtils.isCommandSupported(commandName, chargingStation.stationInfo)
+      ChargingStationUtils.isCommandSupported(commandName, chargingStation)
     ) {
       return (await this.sendMessage(
         chargingStation,
index 47021ca6014f8f90c4488b72e9591f19b29afadf..3af8a1fc5b8d3dcdb6f3f5bbdfa01b7664848667 100644 (file)
@@ -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);