Hook the OCPP 2.0 stack into the main code
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationWorkerBroadcastChannel.ts
index 0a0bd532f1a5326c087a92cd2a530a0efe4581f1..63b261d5db5b7a857686c63ce95f7ed47917f067 100644 (file)
@@ -3,6 +3,7 @@ import type OCPPError from '../exception/OCPPError';
 import { StandardParametersKey } from '../types/ocpp/Configuration';
 import {
   type BootNotificationRequest,
+  type DataTransferRequest,
   type HeartbeatRequest,
   type MeterValuesRequest,
   RequestCommand,
@@ -10,6 +11,8 @@ import {
 } from '../types/ocpp/Requests';
 import {
   type BootNotificationResponse,
+  type DataTransferResponse,
+  DataTransferStatus,
   type HeartbeatResponse,
   type MeterValuesResponse,
   RegistrationStatus,
@@ -49,7 +52,8 @@ type CommandResponse =
   | BootNotificationResponse
   | StatusNotificationResponse
   | HeartbeatResponse
-  | MeterValuesResponse;
+  | MeterValuesResponse
+  | DataTransferResponse;
 
 type CommandHandler = (
   requestPayload?: BroadcastChannelRequestPayload
@@ -178,6 +182,14 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           });
         },
       ],
+      [
+        BroadcastChannelProcedureName.DATA_TRANSFER,
+        async (requestPayload?: BroadcastChannelRequestPayload) =>
+          this.chargingStation.ocppRequestService.requestHandler<
+            DataTransferRequest,
+            DataTransferResponse
+          >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload),
+      ],
     ]);
     this.chargingStation = chargingStation;
     this.onmessage = this.requestHandler.bind(this) as (message: MessageEvent) => void;
@@ -201,7 +213,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
     }
     if (requestPayload?.hashId !== undefined) {
       logger.error(
-        `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead`
+        `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead`
       );
       return;
     }
@@ -316,6 +328,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           return ResponseStatus.SUCCESS;
         }
         return ResponseStatus.FAILURE;
+      case BroadcastChannelProcedureName.DATA_TRANSFER:
+        if (commandResponse?.status === DataTransferStatus.ACCEPTED) {
+          return ResponseStatus.SUCCESS;
+        }
+        return ResponseStatus.FAILURE;
       case BroadcastChannelProcedureName.STATUS_NOTIFICATION:
       case BroadcastChannelProcedureName.METER_VALUES:
         if (Utils.isEmptyObject(commandResponse) === true) {