Enforce SupportedFeatureProfiles check on some OCPP commands
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 29 Mar 2022 08:54:20 +0000 (10:54 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 29 Mar 2022 08:54:20 +0000 (10:54 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
12 files changed:
README.md
src/assets/station-templates/abb-atg.station-template.json
src/assets/station-templates/abb.station-template.json
src/assets/station-templates/evlink.station-template.json
src/assets/station-templates/keba.station-template.json
src/assets/station-templates/schneider-imredd.station-template.json
src/assets/station-templates/schneider.station-template.json
src/assets/station-templates/virtual-simple-atg.station-template.json
src/assets/station-templates/virtual-simple.station-template.json
src/assets/station-templates/virtual.station-template.json
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index aa55b80426b8f6683d63af5582fc66226c0a651b..1be6067358cadb4fec31d5da37da7d1e29a0e8fa 100644 (file)
--- a/README.md
+++ b/README.md
@@ -298,7 +298,7 @@ make SUBMODULES_INIT=true
 #### Smart Charging Profile
 
 - :white_check_mark: ClearChargingProfile
-- :white_check_mark: GetCompositeSchedule
+- :x: GetCompositeSchedule
 - :white_check_mark: SetChargingProfile
 
 #### Remote Trigger Profile
index f4c3c52b45ac4fb1e0ea0e79c2d8f8145c845f90..8deb8d6ff4a49259a22d83a26c26b005d89c1fe9 100644 (file)
@@ -28,7 +28,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index 93b59b62bac3cc753fa75e75f307e9dede059c72..81f2d099c7a3b17c7be589205bdcf3e3b3dc8a1f 100644 (file)
@@ -28,7 +28,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index b96f1ae08c5b1b62d6665e1e9bf90a2eac788d1d..fbaa37e193408d4d02c9af3585d3865e5a13dba2 100644 (file)
@@ -19,7 +19,7 @@
       {
         "key": "MeterValuesSampledData",
         "readonly": false,
-        "value": "Energy.Active.Import.Register"
+        "value": "Energy.Active.Import.Register,Current.Import,Voltage"
       },
       {
         "key": "MeterValueSampleInterval",
@@ -29,7 +29,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index 3bc060b59637989682a622e7b7e6f7d587ec596d..a76741d99f195f12c3f5002f63aa5cf5e741d4a5 100644 (file)
@@ -25,7 +25,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index 34bba08f2aa9ec4ac8265fff575017a3c6d04841..63ee8c01b3f60efb271cda5f27dafd4338a7226d 100644 (file)
@@ -18,7 +18,7 @@
       {
         "key": "MeterValuesSampledData",
         "readonly": false,
-        "value": "Energy.Active.Import.Register"
+        "value": "Energy.Active.Import.Register,Current.Import,Voltage"
       },
       {
         "key": "MeterValueSampleInterval",
@@ -28,7 +28,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index 17e205181e9d368c8db182f95ada5d4f20c621b1..2482a4392bd9994c0c3192acb398ee4f6a70052b 100644 (file)
@@ -28,7 +28,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index 79d0cb4b5a139ef1111fd397213967eb93f11a3b..666be37bb6d0dbba88aa67640098f1450149b9b1 100644 (file)
@@ -14,7 +14,7 @@
       {
         "key": "MeterValuesSampledData",
         "readonly": false,
-        "value": "SoC,Energy.Active.Import.Register"
+        "value": "SoC,Energy.Active.Import.Register,Voltage"
       },
       {
         "key": "MeterValueSampleInterval",
@@ -24,7 +24,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index d3939c8e91b6674f7e63b58e085823d80cac7519..ccec3ee55d1ebf74e2892c3e448e42ac01ba6d0f 100644 (file)
@@ -24,7 +24,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index d330a85cc1a6e7263d8e57c09b980af9b7c7f774..1ecf8875b8ed7868213a2f7cfbf1b358aefeaf0c 100644 (file)
@@ -24,7 +24,7 @@
       {
         "key": "SupportedFeatureProfiles",
         "readonly": true,
-        "value": "Core,LocalAuthListManagement"
+        "value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
       },
       {
         "key": "LocalAuthListEnabled",
index bceba844bf39cd51b38a5562a201de5e8ebdbd73..bf7943f5e91412c4262216bb5d906828e2ff7f53 100644 (file)
@@ -369,7 +369,7 @@ export default class ChargingStation {
     }
     if (
       measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
-      !this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
+      !this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
         measurand
       )
     ) {
@@ -400,7 +400,7 @@ export default class ChargingStation {
         phase &&
         sampledValueTemplates[index]?.phase === phase &&
         sampledValueTemplates[index]?.measurand === measurand &&
-        this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
+        this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
           measurand
         )
       ) {
@@ -409,7 +409,7 @@ export default class ChargingStation {
         !phase &&
         !sampledValueTemplates[index].phase &&
         sampledValueTemplates[index]?.measurand === measurand &&
-        this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
+        this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
           measurand
         )
       ) {
@@ -837,6 +837,12 @@ export default class ChargingStation {
     this.stopMeterValues(connectorId);
   }
 
+  public hasFeatureProfile(featureProfile: SupportedFeatureProfiles) {
+    return this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)?.value.includes(
+      featureProfile
+    );
+  }
+
   public bufferMessage(message: string): void {
     this.messageBuffer.add(message);
   }
@@ -1230,7 +1236,7 @@ export default class ChargingStation {
     if (!this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)) {
       this.addConfigurationKey(
         StandardParametersKey.SupportedFeatureProfiles,
-        `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.Local_Auth_List_Management},${SupportedFeatureProfiles.Smart_Charging}`
+        `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.Firmware_Management},${SupportedFeatureProfiles.Local_Auth_List_Management},${SupportedFeatureProfiles.Smart_Charging},${SupportedFeatureProfiles.Remote_Trigger}`
       );
     }
     this.addConfigurationKey(
@@ -1270,7 +1276,7 @@ export default class ChargingStation {
     }
     if (
       !this.getConfigurationKey(StandardParametersKey.LocalAuthListEnabled) &&
-      this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles).value.includes(
+      this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)?.value.includes(
         SupportedFeatureProfiles.Local_Auth_List_Management
       )
     ) {
index 7e04e6bf4b6423e745682c2f7f6ff035a2590b01..a9aaab7975e0a5645f9de4c7f7b2fdec5673e16e 100644 (file)
@@ -54,6 +54,10 @@ import {
   OCPP16MeterValuesRequest,
   OCPP16MeterValuesResponse,
 } from '../../../types/ocpp/1.6/MeterValues';
+import {
+  OCPP16StandardParametersKey,
+  OCPP16SupportedFeatureProfiles,
+} from '../../../types/ocpp/1.6/Configuration';
 
 import type ChargingStation from '../../ChargingStation';
 import Constants from '../../../utils/Constants';
@@ -65,7 +69,6 @@ import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointE
 import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
-import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
 import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
 import OCPPError from '../../../exception/OCPPError';
 import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
@@ -378,6 +381,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private handleRequestSetChargingProfile(
     commandPayload: SetChargingProfileRequest
   ): SetChargingProfileResponse {
+    if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Smart_Charging)) {
+      logger.error(
+        `${this.chargingStation.logPrefix()} Trying to set charging profile(s) without '${
+          OCPP16SupportedFeatureProfiles.Smart_Charging
+        }' feature enabled in ${
+          OCPP16StandardParametersKey.SupportedFeatureProfiles
+        } in configuration`
+      );
+      return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED;
+    }
     if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) {
       logger.error(
         `${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
@@ -417,6 +430,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private handleRequestClearChargingProfile(
     commandPayload: ClearChargingProfileRequest
   ): ClearChargingProfileResponse {
+    if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Smart_Charging)) {
+      logger.error(
+        `${this.chargingStation.logPrefix()} Trying to clear charging profile(s) without '${
+          OCPP16SupportedFeatureProfiles.Smart_Charging
+        }' feature enabled in ${
+          OCPP16StandardParametersKey.SupportedFeatureProfiles
+        } in configuration`
+      );
+      return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
+    }
     const connectorStatus = this.chargingStation.getConnectorStatus(commandPayload.connectorId);
     if (!connectorStatus) {
       logger.error(
@@ -804,6 +827,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private async handleRequestGetDiagnostics(
     commandPayload: GetDiagnosticsRequest
   ): Promise<GetDiagnosticsResponse> {
+    if (
+      !this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Firmware_Management)
+    ) {
+      logger.error(
+        `${this.chargingStation.logPrefix()} Trying to get diagnostics without '${
+          OCPP16SupportedFeatureProfiles.Firmware_Management
+        }' feature enabled in ${
+          OCPP16StandardParametersKey.SupportedFeatureProfiles
+        } in configuration`
+      );
+      return Constants.OCPP_RESPONSE_EMPTY;
+    }
     logger.debug(
       this.chargingStation.logPrefix() +
         ' ' +
@@ -911,6 +946,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
   private handleRequestTriggerMessage(
     commandPayload: OCPP16TriggerMessageRequest
   ): OCPP16TriggerMessageResponse {
+    if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Remote_Trigger)) {
+      logger.error(
+        `${this.chargingStation.logPrefix()} Trying to remote trigger message without '${
+          OCPP16SupportedFeatureProfiles.Remote_Trigger
+        }' feature enabled in ${
+          OCPP16StandardParametersKey.SupportedFeatureProfiles
+        } in configuration`
+      );
+      return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
+    }
     try {
       switch (commandPayload.requestedMessage) {
         case MessageTrigger.BootNotification: