+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';
type HeartbeatRequest,
type MeterValuesRequest,
RequestCommand,
+ type RequestParams,
type StatusNotificationRequest,
} from '../types/ocpp/Requests';
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';
constructor(chargingStation: ChargingStation) {
super();
+ const requestParams: RequestParams = {
+ throwError: true,
+ };
this.commandHandlers = new Map<BroadcastChannelProcedureName, CommandHandler>([
[BroadcastChannelProcedureName.START_CHARGING_STATION, () => this.chargingStation.start()],
[
[
BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
(requestPayload?: BroadcastChannelRequestPayload) =>
- this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds),
+ this.chargingStation.startAutomaticTransactionGenerator(requestPayload?.connectorIds),
],
[
BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
(requestPayload?: BroadcastChannelRequestPayload) =>
- this.chargingStation.stopAutomaticTransactionGenerator(requestPayload.connectorIds),
+ this.chargingStation.stopAutomaticTransactionGenerator(requestPayload?.connectorIds),
],
[
BroadcastChannelProcedureName.START_TRANSACTION,
this.chargingStation.ocppRequestService.requestHandler<
StartTransactionRequest,
StartTransactionResponse
- >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload),
+ >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload, requestParams),
],
[
BroadcastChannelProcedureName.STOP_TRANSACTION,
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,
this.chargingStation.ocppRequestService.requestHandler<
AuthorizeRequest,
AuthorizeResponse
- >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload),
+ >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload, requestParams),
],
[
BroadcastChannelProcedureName.BOOT_NOTIFICATION,
},
{
skipBufferingOnError: true,
+ throwError: true,
}
);
return this.chargingStation.bootNotificationResponse;
this.chargingStation.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
- >(this.chargingStation, RequestCommand.STATUS_NOTIFICATION, requestPayload),
+ >(
+ this.chargingStation,
+ RequestCommand.STATUS_NOTIFICATION,
+ requestPayload,
+ requestParams
+ ),
],
[
BroadcastChannelProcedureName.HEARTBEAT,
this.chargingStation.ocppRequestService.requestHandler<
HeartbeatRequest,
HeartbeatResponse
- >(this.chargingStation, RequestCommand.HEARTBEAT, requestPayload),
+ >(this.chargingStation, RequestCommand.HEARTBEAT, requestPayload, requestParams),
],
[
BroadcastChannelProcedureName.METER_VALUES,
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
+ );
},
],
[
this.chargingStation.ocppRequestService.requestHandler<
DataTransferRequest,
DataTransferResponse
- >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload),
+ >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload, requestParams),
],
[
BroadcastChannelProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION,
this.chargingStation.ocppRequestService.requestHandler<
DiagnosticsStatusNotificationRequest,
DiagnosticsStatusNotificationResponse
- >(this.chargingStation, RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, requestPayload),
+ >(
+ this.chargingStation,
+ RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ requestPayload,
+ requestParams
+ ),
],
[
BroadcastChannelProcedureName.FIRMWARE_STATUS_NOTIFICATION,
this.chargingStation.ocppRequestService.requestHandler<
FirmwareStatusNotificationRequest,
FirmwareStatusNotificationResponse
- >(this.chargingStation, RequestCommand.FIRMWARE_STATUS_NOTIFICATION, requestPayload),
+ >(
+ this.chargingStation,
+ RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
+ requestPayload,
+ requestParams
+ ),
],
]);
this.chargingStation = chargingStation;