X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationWorkerBroadcastChannel.ts;h=1c7121ecc7f54b731655afc1c0f499445ae72973;hb=32e1ad3b16c388b9c6aea81b649fef40dc2d21e1;hp=7c9883bd4277995e3abce9386327583b4479d09e;hpb=d270cc878c61c42098557a0e03cc1620f74112de;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 7c9883bd..1c7121ec 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -4,15 +4,20 @@ import { StandardParametersKey } from '../types/ocpp/Configuration'; import { type BootNotificationRequest, type DataTransferRequest, + type DiagnosticsStatusNotificationRequest, + type FirmwareStatusNotificationRequest, type HeartbeatRequest, type MeterValuesRequest, RequestCommand, + RequestParams, type StatusNotificationRequest, } from '../types/ocpp/Requests'; import { type BootNotificationResponse, type DataTransferResponse, DataTransferStatus, + type DiagnosticsStatusNotificationResponse, + type FirmwareStatusNotificationResponse, type HeartbeatResponse, type MeterValuesResponse, RegistrationStatusEnumType, @@ -53,7 +58,9 @@ type CommandResponse = | StatusNotificationResponse | HeartbeatResponse | MeterValuesResponse - | DataTransferResponse; + | DataTransferResponse + | DiagnosticsStatusNotificationResponse + | FirmwareStatusNotificationResponse; type CommandHandler = ( requestPayload?: BroadcastChannelRequestPayload @@ -65,6 +72,9 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca constructor(chargingStation: ChargingStation) { super(); + const requestParams: RequestParams = { + throwError: true, + }; this.commandHandlers = new Map([ [BroadcastChannelProcedureName.START_CHARGING_STATION, () => this.chargingStation.start()], [ @@ -95,7 +105,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< StartTransactionRequest, StartTransactionResponse - >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload), + >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload, requestParams), ], [ BroadcastChannelProcedureName.STOP_TRANSACTION, @@ -109,6 +119,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca true ), ...requestPayload, + requestParams, }), ], [ @@ -117,7 +128,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< AuthorizeRequest, AuthorizeResponse - >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload), + >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload, requestParams), ], [ BroadcastChannelProcedureName.BOOT_NOTIFICATION, @@ -135,6 +146,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca }, { skipBufferingOnError: true, + throwError: true, } ); return this.chargingStation.bootNotificationResponse; @@ -146,7 +158,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< StatusNotificationRequest, StatusNotificationResponse - >(this.chargingStation, RequestCommand.STATUS_NOTIFICATION, requestPayload), + >( + this.chargingStation, + RequestCommand.STATUS_NOTIFICATION, + requestPayload, + requestParams + ), ], [ BroadcastChannelProcedureName.HEARTBEAT, @@ -154,7 +171,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< HeartbeatRequest, HeartbeatResponse - >(this.chargingStation, RequestCommand.HEARTBEAT, requestPayload), + >(this.chargingStation, RequestCommand.HEARTBEAT, requestPayload, requestParams), ], [ BroadcastChannelProcedureName.METER_VALUES, @@ -179,6 +196,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca ), ], ...requestPayload, + requestParams, }); }, ], @@ -188,7 +206,33 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< DataTransferRequest, DataTransferResponse - >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload), + >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload, requestParams), + ], + [ + BroadcastChannelProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION, + async (requestPayload?: BroadcastChannelRequestPayload) => + this.chargingStation.ocppRequestService.requestHandler< + DiagnosticsStatusNotificationRequest, + DiagnosticsStatusNotificationResponse + >( + this.chargingStation, + RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, + requestPayload, + requestParams + ), + ], + [ + BroadcastChannelProcedureName.FIRMWARE_STATUS_NOTIFICATION, + async (requestPayload?: BroadcastChannelRequestPayload) => + this.chargingStation.ocppRequestService.requestHandler< + FirmwareStatusNotificationRequest, + FirmwareStatusNotificationResponse + >( + this.chargingStation, + RequestCommand.FIRMWARE_STATUS_NOTIFICATION, + requestPayload, + requestParams + ), ], ]); this.chargingStation = chargingStation; @@ -221,7 +265,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca let commandResponse: CommandResponse | void; try { commandResponse = await this.commandHandler(command, requestPayload); - if (commandResponse === undefined || commandResponse === null) { + if ( + commandResponse === undefined || + commandResponse === null || + Utils.isEmptyObject(commandResponse as CommandResponse) + ) { responsePayload = { hashId: this.chargingStation.stationInfo.hashId, status: ResponseStatus.SUCCESS,