X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationWorkerBroadcastChannel.ts;h=00780f2f6ed0000c352b0d417ea567ddc2ea1382;hb=83e00df1c1ba02de8b637ca4cb0464eb909ebb18;hp=4f6719667075cfa094ca0ef9608fef05dc9a220a;hpb=5083d31a6f03f617f91fbed2497e379058df9e49;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 4f671966..00780f2f 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -2,31 +2,34 @@ import BaseError from '../exception/BaseError'; import type OCPPError from '../exception/OCPPError'; import { StandardParametersKey } from '../types/ocpp/Configuration'; import { - HeartbeatRequest, - MeterValuesRequest, + type BootNotificationRequest, + type HeartbeatRequest, + type MeterValuesRequest, RequestCommand, type StatusNotificationRequest, } from '../types/ocpp/Requests'; -import type { - HeartbeatResponse, - MeterValuesResponse, - StatusNotificationResponse, +import { + type BootNotificationResponse, + type HeartbeatResponse, + type MeterValuesResponse, + RegistrationStatus, + type StatusNotificationResponse, } from '../types/ocpp/Responses'; import { AuthorizationStatus, - AuthorizeRequest, - AuthorizeResponse, - StartTransactionRequest, - StartTransactionResponse, - StopTransactionRequest, - StopTransactionResponse, + type AuthorizeRequest, + type AuthorizeResponse, + type StartTransactionRequest, + type StartTransactionResponse, + type StopTransactionRequest, + type StopTransactionResponse, } from '../types/ocpp/Transaction'; import { BroadcastChannelProcedureName, - BroadcastChannelRequest, - BroadcastChannelRequestPayload, - BroadcastChannelResponsePayload, - MessageEvent, + type BroadcastChannelRequest, + type BroadcastChannelRequestPayload, + type BroadcastChannelResponsePayload, + type MessageEvent, } from '../types/WorkerBroadcastChannel'; import { ResponseStatus } from '../ui/web/src/types/UIProtocol'; import Constants from '../utils/Constants'; @@ -43,6 +46,7 @@ type CommandResponse = | StartTransactionResponse | StopTransactionResponse | AuthorizeResponse + | BootNotificationResponse | StatusNotificationResponse | HeartbeatResponse | MeterValuesResponse; @@ -96,13 +100,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca StopTransactionRequest, StartTransactionResponse >(this.chargingStation, RequestCommand.STOP_TRANSACTION, { + meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( + requestPayload.transactionId, + true + ), ...requestPayload, - meterStop: - requestPayload.meterStop ?? - this.chargingStation.getEnergyActiveImportRegisterByTransactionId( - requestPayload.transactionId, - true - ), }), ], [ @@ -113,6 +115,27 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca AuthorizeResponse >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload), ], + [ + BroadcastChannelProcedureName.BOOT_NOTIFICATION, + async (requestPayload?: BroadcastChannelRequestPayload) => { + this.chargingStation.bootNotificationResponse = + await this.chargingStation.ocppRequestService.requestHandler< + BootNotificationRequest, + BootNotificationResponse + >( + this.chargingStation, + RequestCommand.BOOT_NOTIFICATION, + { + ...this.chargingStation.bootNotificationRequest, + ...requestPayload, + }, + { + skipBufferingOnError: true, + } + ); + return this.chargingStation.bootNotificationResponse; + }, + ], [ BroadcastChannelProcedureName.STATUS_NOTIFICATION, async (requestPayload?: BroadcastChannelRequestPayload) => @@ -141,8 +164,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca MeterValuesRequest, MeterValuesResponse >(this.chargingStation, RequestCommand.METER_VALUES, { - ...requestPayload, - meterValue: requestPayload.meterValue ?? [ + meterValue: [ OCPP16ServiceUtils.buildMeterValue( this.chargingStation, requestPayload.connectorId, @@ -152,6 +174,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca : Constants.DEFAULT_METER_VALUES_INTERVAL ), ], + ...requestPayload, }); }, ], @@ -288,6 +311,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca return ResponseStatus.SUCCESS; } return ResponseStatus.FAILURE; + case BroadcastChannelProcedureName.BOOT_NOTIFICATION: + if (commandResponse?.status === RegistrationStatus.ACCEPTED) { + return ResponseStatus.SUCCESS; + } + return ResponseStatus.FAILURE; case BroadcastChannelProcedureName.STATUS_NOTIFICATION: case BroadcastChannelProcedureName.METER_VALUES: if (Utils.isEmptyObject(commandResponse) === true) {