+ [
+ OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16GetCompositeScheduleRequest>(
+ 'assets/json-schemas/ocpp/1.6/GetCompositeSchedule.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileRequest>(
+ 'assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ClearChargingProfileRequest>(
+ 'assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ChangeAvailabilityRequest>(
+ 'assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<RemoteStartTransactionRequest>(
+ 'assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<RemoteStopTransactionRequest>(
+ 'assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageRequest>(
+ 'assets/json-schemas/ocpp/1.6/TriggerMessage.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.DATA_TRANSFER,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferRequest>(
+ 'assets/json-schemas/ocpp/1.6/DataTransfer.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareRequest>(
+ 'assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.RESERVE_NOW,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ReserveNowRequest>(
+ 'assets/json-schemas/ocpp/1.6/ReserveNow.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP16IncomingRequestCommand.CANCEL_RESERVATION,
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16CancelReservationRequest>(
+ 'assets/json-schemas/ocpp/1.6/CancelReservation.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ]
+ ])
+ // Handle incoming request events
+ this.on(
+ OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
+ (
+ chargingStation: ChargingStation,
+ request: RemoteStartTransactionRequest,
+ response: GenericResponse
+ ) => {
+ if (response.status === GenericStatus.Accepted) {
+ const { connectorId, idTag } = request
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ chargingStation.getConnectorStatus(connectorId)!.transactionRemoteStarted = true
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16StartTransactionRequest, OCPP16StartTransactionResponse>(
+ chargingStation,
+ OCPP16RequestCommand.START_TRANSACTION,
+ {
+ connectorId,
+ idTag
+ }
+ )
+ .then(response => {
+ if (response.status === OCPP16AuthorizationStatus.ACCEPTED) {
+ logger.debug(
+ `${chargingStation.logPrefix()} Remote start transaction ACCEPTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId} for idTag '${idTag}'`
+ )
+ } else {
+ logger.debug(
+ `${chargingStation.logPrefix()} Remote start transaction REJECTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId} for idTag '${idTag}'`
+ )
+ }
+ })
+ .catch(error => {
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.constructor: Remote start transaction error:`,
+ error
+ )
+ })
+ }
+ }
+ )
+ this.on(
+ OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
+ (
+ chargingStation: ChargingStation,
+ request: RemoteStopTransactionRequest,
+ response: GenericResponse
+ ) => {
+ if (response.status === GenericStatus.Accepted) {
+ const { transactionId } = request
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const connectorId = chargingStation.getConnectorIdByTransactionId(transactionId)!
+ OCPP16ServiceUtils.remoteStopTransaction(chargingStation, connectorId)
+ .then(response => {
+ if (response.status === GenericStatus.Accepted) {
+ logger.debug(
+ `${chargingStation.logPrefix()} Remote stop transaction ACCEPTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId} for transaction '${transactionId}'`
+ )
+ } else {
+ logger.debug(
+ `${chargingStation.logPrefix()} Remote stop transaction REJECTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId} for transaction '${transactionId}'`
+ )
+ }
+ })
+ .catch(error => {
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.constructor: Remote stop transaction error:`,
+ error
+ )
+ })
+ }
+ }
+ )
+ this.on(
+ OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
+ (
+ chargingStation: ChargingStation,
+ request: OCPP16TriggerMessageRequest,
+ response: OCPP16TriggerMessageResponse
+ ) => {
+ if (response.status !== OCPP16TriggerMessageStatus.ACCEPTED) {
+ return
+ }
+ const { requestedMessage, connectorId } = request
+ const errorHandler = (error: Error): void => {
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.constructor: Trigger ${requestedMessage} error:`,
+ error
+ )
+ }
+ switch (requestedMessage) {
+ case OCPP16MessageTrigger.BootNotification:
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
+ chargingStation,
+ OCPP16RequestCommand.BOOT_NOTIFICATION,
+ chargingStation.bootNotificationRequest,
+ { skipBufferingOnError: true, triggerMessage: true }
+ )
+ .then(response => {
+ chargingStation.bootNotificationResponse = response
+ })
+ .catch(errorHandler)
+ break
+ case OCPP16MessageTrigger.Heartbeat:
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
+ chargingStation,
+ OCPP16RequestCommand.HEARTBEAT,
+ undefined,
+ {
+ triggerMessage: true
+ }
+ )
+ .catch(errorHandler)
+ break
+ case OCPP16MessageTrigger.StatusNotification:
+ if (connectorId != null) {
+ chargingStation.ocppRequestService
+ .requestHandler<OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse>(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: chargingStation.getConnectorStatus(connectorId)?.status
+ },
+ {
+ triggerMessage: true
+ }
+ )
+ .catch(errorHandler)
+ } else if (chargingStation.hasEvses) {
+ for (const evseStatus of chargingStation.evses.values()) {
+ for (const [id, connectorStatus] of evseStatus.connectors) {
+ chargingStation.ocppRequestService
+ .requestHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: id,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: connectorStatus.status
+ },
+ {
+ triggerMessage: true
+ }
+ )
+ .catch(errorHandler)
+ }
+ }
+ } else {
+ for (const [id, connectorStatus] of chargingStation.connectors) {
+ chargingStation.ocppRequestService
+ .requestHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: id,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: connectorStatus.status
+ },
+ {
+ triggerMessage: true
+ }
+ )
+ .catch(errorHandler)
+ }
+ }
+ break
+ }
+ }
+ )
+ this.validatePayload = this.validatePayload.bind(this)