X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationWorkerBroadcastChannel.ts;h=8d6cb1c62ac7ff647f1cbbf8a6cf6a240c1520ea;hb=59395dc149654128f2996f4999bccb66270f54e4;hp=0eecb7b1bf16838fc81c9eaed0bce0f0970e192c;hpb=91a7d3eac062df6c73d8443a542568c1fe69ec1b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 0eecb7b1..8d6cb1c6 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -1,21 +1,30 @@ +import type ChargingStation from './ChargingStation'; +import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; +import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; +import WorkerBroadcastChannel from './WorkerBroadcastChannel'; import BaseError from '../exception/BaseError'; import type OCPPError from '../exception/OCPPError'; import { StandardParametersKey } from '../types/ocpp/Configuration'; import { type BootNotificationRequest, type DataTransferRequest, + type DiagnosticsStatusNotificationRequest, + type FirmwareStatusNotificationRequest, type HeartbeatRequest, type MeterValuesRequest, RequestCommand, + type RequestParams, type StatusNotificationRequest, } from '../types/ocpp/Requests'; import { type BootNotificationResponse, type DataTransferResponse, DataTransferStatus, + type DiagnosticsStatusNotificationResponse, + type FirmwareStatusNotificationResponse, type HeartbeatResponse, type MeterValuesResponse, - RegistrationStatus, + RegistrationStatusEnumType, type StatusNotificationResponse, } from '../types/ocpp/Responses'; import { @@ -38,10 +47,6 @@ import { import Constants from '../utils/Constants'; import logger from '../utils/Logger'; import Utils from '../utils/Utils'; -import type ChargingStation from './ChargingStation'; -import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; -import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; -import WorkerBroadcastChannel from './WorkerBroadcastChannel'; const moduleName = 'ChargingStationWorkerBroadcastChannel'; @@ -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, @@ -103,13 +113,18 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< StopTransactionRequest, StartTransactionResponse - >(this.chargingStation, RequestCommand.STOP_TRANSACTION, { - meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( - requestPayload.transactionId, - true - ), - ...requestPayload, - }), + >( + this.chargingStation, + RequestCommand.STOP_TRANSACTION, + { + meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( + requestPayload.transactionId, + true + ), + ...requestPayload, + }, + requestParams + ), ], [ BroadcastChannelProcedureName.AUTHORIZE, @@ -117,7 +132,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 +150,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca }, { skipBufferingOnError: true, + throwError: true, } ); return this.chargingStation.bootNotificationResponse; @@ -146,7 +162,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 +175,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, @@ -167,19 +188,26 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca return this.chargingStation.ocppRequestService.requestHandler< MeterValuesRequest, MeterValuesResponse - >(this.chargingStation, RequestCommand.METER_VALUES, { - meterValue: [ - OCPP16ServiceUtils.buildMeterValue( - this.chargingStation, - requestPayload.connectorId, - this.chargingStation.getConnectorStatus(requestPayload.connectorId)?.transactionId, - configuredMeterValueSampleInterval - ? Utils.convertToInt(configuredMeterValueSampleInterval.value) * 1000 - : Constants.DEFAULT_METER_VALUES_INTERVAL - ), - ], - ...requestPayload, - }); + >( + this.chargingStation, + RequestCommand.METER_VALUES, + { + meterValue: [ + // FIXME: Implement OCPP version agnostic helpers + OCPP16ServiceUtils.buildMeterValue( + this.chargingStation, + requestPayload.connectorId, + this.chargingStation.getConnectorStatus(requestPayload.connectorId) + ?.transactionId, + configuredMeterValueSampleInterval + ? Utils.convertToInt(configuredMeterValueSampleInterval.value) * 1000 + : Constants.DEFAULT_METER_VALUES_INTERVAL + ), + ], + ...requestPayload, + }, + requestParams + ); }, ], [ @@ -188,7 +216,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; @@ -213,7 +267,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; } @@ -221,7 +275,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, @@ -324,7 +382,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca } return ResponseStatus.FAILURE; case BroadcastChannelProcedureName.BOOT_NOTIFICATION: - if (commandResponse?.status === RegistrationStatus.ACCEPTED) { + if (commandResponse?.status === RegistrationStatusEnumType.ACCEPTED) { return ResponseStatus.SUCCESS; } return ResponseStatus.FAILURE;