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,
- RegistrationStatus,
+ RegistrationStatusEnumType,
type StatusNotificationResponse,
} from '../types/ocpp/Responses';
import {
type StopTransactionRequest,
type StopTransactionResponse,
} from '../types/ocpp/Transaction';
+import { ResponseStatus } from '../types/UIProtocol';
import {
BroadcastChannelProcedureName,
type BroadcastChannelRequest,
type BroadcastChannelResponsePayload,
type MessageEvent,
} from '../types/WorkerBroadcastChannel';
-import { ResponseStatus } from '../ui/web/src/types/UIProtocol';
import Constants from '../utils/Constants';
import logger from '../utils/Logger';
import Utils from '../utils/Utils';
| BootNotificationResponse
| StatusNotificationResponse
| HeartbeatResponse
- | MeterValuesResponse;
+ | MeterValuesResponse
+ | DataTransferResponse
+ | DiagnosticsStatusNotificationResponse
+ | FirmwareStatusNotificationResponse;
type CommandHandler = (
requestPayload?: BroadcastChannelRequestPayload
constructor(chargingStation: ChargingStation) {
super();
+ const requestParams: RequestParams = {
+ throwError: true,
+ };
this.commandHandlers = new Map<BroadcastChannelProcedureName, CommandHandler>([
[BroadcastChannelProcedureName.START_CHARGING_STATION, () => this.chargingStation.start()],
[
this.chargingStation.ocppRequestService.requestHandler<
StartTransactionRequest,
StartTransactionResponse
- >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload),
+ >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload, requestParams),
],
[
BroadcastChannelProcedureName.STOP_TRANSACTION,
true
),
...requestPayload,
+ requestParams,
}),
],
[
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,
),
],
...requestPayload,
+ requestParams,
});
},
],
+ [
+ BroadcastChannelProcedureName.DATA_TRANSFER,
+ async (requestPayload?: BroadcastChannelRequestPayload) =>
+ this.chargingStation.ocppRequestService.requestHandler<
+ DataTransferRequest,
+ DataTransferResponse
+ >(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;
this.onmessage = this.requestHandler.bind(this) as (message: MessageEvent) => void;
}
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;
}
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,
[
BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
- ].includes(command) === true && delete requestPayload.connectorIds;
+ ].includes(command) === false && delete requestPayload.connectorIds;
}
private commandResponseToResponsePayload(
}
return ResponseStatus.FAILURE;
case BroadcastChannelProcedureName.BOOT_NOTIFICATION:
- if (commandResponse?.status === RegistrationStatus.ACCEPTED) {
+ if (commandResponse?.status === RegistrationStatusEnumType.ACCEPTED) {
+ return ResponseStatus.SUCCESS;
+ }
+ return ResponseStatus.FAILURE;
+ case BroadcastChannelProcedureName.DATA_TRANSFER:
+ if (commandResponse?.status === DataTransferStatus.ACCEPTED) {
return ResponseStatus.SUCCESS;
}
return ResponseStatus.FAILURE;