+ public jsonIncomingRequestResponseSchemas: Map<
+ OCPP16IncomingRequestCommand,
+ JSONSchemaType<JsonObject>
+ >;
+
+ private responseHandlers: Map<OCPP16RequestCommand, ResponseHandler>;
+ private jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>;
+
+ public constructor() {
+ if (new.target?.name === moduleName) {
+ throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+ }
+ super(OCPPVersion.VERSION_16);
+ this.responseHandlers = new Map<OCPP16RequestCommand, ResponseHandler>([
+ [OCPP16RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
+ [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
+ [OCPP16RequestCommand.AUTHORIZE, this.handleResponseAuthorize.bind(this)],
+ [OCPP16RequestCommand.START_TRANSACTION, this.handleResponseStartTransaction.bind(this)],
+ [OCPP16RequestCommand.STOP_TRANSACTION, this.handleResponseStopTransaction.bind(this)],
+ [OCPP16RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this)],
+ [OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this)],
+ [OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ ]);
+ this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
+ [
+ OCPP16RequestCommand.BOOT_NOTIFICATION,
+ this.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/BootNotificationResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.HEARTBEAT,
+ this.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/HeartbeatResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.AUTHORIZE,
+ this.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/AuthorizeResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.START_TRANSACTION,
+ this.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/StartTransactionResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.STOP_TRANSACTION,
+ this.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/StopTransactionResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ this.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.METER_VALUES,
+ this.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/MeterValuesResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ this.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.DATA_TRANSFER,
+ this.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
+ ),
+ ],
+ [
+ OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
+ this.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json'
+ ),
+ ],
+ ]);
+ this.jsonIncomingRequestResponseSchemas = new Map([
+ [
+ OCPP16IncomingRequestCommand.RESET,
+ this.parseJsonSchemaFile<GenericResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ResetResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.CLEAR_CACHE,
+ this.parseJsonSchemaFile<GenericResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ClearCacheResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
+ this.parseJsonSchemaFile<ChangeAvailabilityResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
+ this.parseJsonSchemaFile<UnlockConnectorResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.GET_CONFIGURATION,
+ this.parseJsonSchemaFile<GetConfigurationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
+ this.parseJsonSchemaFile<ChangeConfigurationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
+ this.parseJsonSchemaFile<SetChargingProfileResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
+ this.parseJsonSchemaFile<ClearChargingProfileResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
+ this.parseJsonSchemaFile<GenericResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
+ this.parseJsonSchemaFile<GenericResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
+ this.parseJsonSchemaFile<GetDiagnosticsResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
+ this.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.DATA_TRANSFER,
+ this.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
+ ),
+ ],
+ [
+ OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
+ this.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json'
+ ),
+ ],
+ ]);
+ this.validatePayload.bind(this);
+ }
+
+ public async responseHandler(
+ chargingStation: ChargingStation,
+ commandName: OCPP16RequestCommand,
+ payload: JsonType,
+ requestPayload: JsonType
+ ): Promise<void> {
+ if (
+ chargingStation.isRegistered() === true ||
+ commandName === OCPP16RequestCommand.BOOT_NOTIFICATION
+ ) {
+ if (
+ this.responseHandlers.has(commandName) === true &&
+ OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true
+ ) {
+ try {
+ this.validatePayload(chargingStation, commandName, payload);
+ await this.responseHandlers.get(commandName)(chargingStation, payload, requestPayload);
+ } catch (error) {
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.responseHandler: Handle response error:`,
+ error
+ );
+ throw error;
+ }
+ } else {
+ // Throw exception
+ throw new OCPPError(
+ ErrorType.NOT_IMPLEMENTED,
+ `${commandName} is not implemented to handle response PDU ${JSON.stringify(
+ payload,
+ null,
+ 2
+ )}`,
+ commandName,
+ payload
+ );
+ }