Fix OCPP message type definition and usage
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16ServiceUtils.ts
index 43b291be0680777088d9bef662cc1c16ab239999..2ad75f1d2234725f20cf239557c322f219bbfa04 100644 (file)
@@ -14,12 +14,19 @@ import {
   OCPP16MeterValuePhase,
   OCPP16SampledValue,
 } from '../../../types/ocpp/1.6/MeterValues';
+import {
+  OCPP16IncomingRequestCommand,
+  OCPP16RequestCommand,
+} from '../../../types/ocpp/1.6/Requests';
+import {
+  OCPP16StandardParametersKey,
+  OCPP16SupportedFeatureProfiles,
+} from '../../../types/ocpp/1.6/Configuration';
 
 import type ChargingStation from '../../ChargingStation';
 import Constants from '../../../utils/Constants';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
 import MeasurandValues from '../../../types/MeasurandValues';
-import { OCPP16RequestCommand } from '../../../types/ocpp/1.6/Requests';
 import OCPPError from '../../../exception/OCPPError';
 import Utils from '../../../utils/Utils';
 import logger from '../../../utils/Logger';
@@ -44,6 +51,22 @@ export class OCPP16ServiceUtils {
     }
   }
 
+  public static checkFeatureProfile(
+    chargingStation: ChargingStation,
+    featureProfile: OCPP16SupportedFeatureProfiles,
+    command: OCPP16RequestCommand | OCPP16IncomingRequestCommand
+  ): boolean {
+    if (!chargingStation.hasFeatureProfile(featureProfile)) {
+      logger.warn(
+        `${chargingStation.logPrefix()} Trying to '${command}' without '${featureProfile}' feature enabled in ${
+          OCPP16StandardParametersKey.SupportedFeatureProfiles
+        } in configuration`
+      );
+      return false;
+    }
+    return true;
+  }
+
   public static buildSampledValue(
     sampledValueTemplate: SampledValueTemplate,
     value: number,