Refine README.md
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index 51887b1ba830ed66e2190093b439928f01da8474..c216ed6bec8bae64bb3f2ae84bab9db91ba16d3b 100644 (file)
@@ -16,7 +16,11 @@ import { ChargingProfileKindType, RecurrencyKindType } from '../types/ocpp/1.6/C
 import { ChargingProfile, ChargingSchedulePeriod } from '../types/ocpp/ChargingProfile';
 import { StandardParametersKey } from '../types/ocpp/Configuration';
 import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
-import { BootNotificationRequest } from '../types/ocpp/Requests';
+import {
+  BootNotificationRequest,
+  IncomingRequestCommand,
+  RequestCommand,
+} from '../types/ocpp/Requests';
 import { WebSocketCloseEventStatusString } from '../types/WebSocket';
 import { WorkerProcessType } from '../types/Worker';
 import Configuration from '../utils/Configuration';
@@ -530,6 +534,28 @@ export class ChargingStationUtils {
     );
   }
 
+  public static isCommandSupported(
+    command: RequestCommand | IncomingRequestCommand,
+    stationInfo: ChargingStationInfo
+  ): boolean {
+    if (
+      Object.values(IncomingRequestCommand).includes(command as IncomingRequestCommand) &&
+      !stationInfo?.commandsSupport?.incomingCommands
+    ) {
+      return true;
+    }
+    if (
+      Object.values(RequestCommand).includes(command as RequestCommand) &&
+      !stationInfo?.commandsSupport?.outgoingCommands
+    ) {
+      return true;
+    }
+    return (
+      ((stationInfo?.commandsSupport?.incomingCommands[command] as boolean) ?? false) ||
+      ((stationInfo?.commandsSupport?.outgoingCommands[command] as boolean) ?? false)
+    );
+  }
+
   private static getRandomSerialNumberSuffix(params?: {
     randomBytesLength?: number;
     upperCase?: boolean;