X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16IncomingRequestService.ts;h=fe25221050a8afa02e2f4b0091217c5726116b2b;hb=3024d5b2497e97bdd355243a5d236fa3f7a4d874;hp=d92d526e4a062884a55021b0e858767ee267e68e;hpb=8946ba9db13e225292a62b8f4bdcd1419792697a;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index d92d526e..fe252210 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -26,6 +26,7 @@ import { getConnectorChargingProfiles, prepareChargingProfileKind, removeExpiredReservations, + resetAuthorizeConnectorStatus, setConfigurationKeyValue } from '../../../charging-station/index.js' import { OCPPError } from '../../../exception/index.js' @@ -431,7 +432,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } ) .then(response => { - if (response.status === OCPP16AuthorizationStatus.ACCEPTED) { + if (response.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) { logger.debug( `${chargingStation.logPrefix()} Remote start transaction ACCEPTED on ${ chargingStation.stationInfo?.chargingStationId @@ -510,15 +511,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { switch (requestedMessage) { case OCPP16MessageTrigger.BootNotification: chargingStation.ocppRequestService - .requestHandler( - chargingStation, - OCPP16RequestCommand.BOOT_NOTIFICATION, - chargingStation.bootNotificationRequest as OCPP16BootNotificationRequest, - { skipBufferingOnError: true, triggerMessage: true } - ) - .then(response => { - chargingStation.bootNotificationResponse = response - }) + .requestHandler< + OCPP16BootNotificationRequest, + OCPP16BootNotificationResponse + >(chargingStation, OCPP16RequestCommand.BOOT_NOTIFICATION, chargingStation.bootNotificationRequest as OCPP16BootNotificationRequest, { skipBufferingOnError: true, triggerMessage: true }) .catch(errorHandler) break case OCPP16MessageTrigger.Heartbeat: @@ -655,7 +651,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { // Throw exception throw new OCPPError( ErrorType.NOT_IMPLEMENTED, - `'${commandName}' is not implemented to handle request PDU ${JSON.stringify( + `${commandName} is not implemented to handle request PDU ${JSON.stringify( commandPayload, undefined, 2 @@ -1304,7 +1300,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion commandPayload.retrieveDate = convertToDate(commandPayload.retrieveDate)! const { retrieveDate } = commandPayload - if (chargingStation.stationInfo?.firmwareStatus !== OCPP16FirmwareStatus.Installed) { + if ( + chargingStation.stationInfo?.firmwareStatus != null && + chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed + ) { logger.warn( `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress` ) @@ -1663,19 +1662,28 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion commandPayload.expiryDate = convertToDate(commandPayload.expiryDate)! const { reservationId, idTag, connectorId } = commandPayload + if (!chargingStation.hasConnector(connectorId)) { + logger.error( + `${chargingStation.logPrefix()} Trying to reserve a non existing connector id ${connectorId}` + ) + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + if (connectorId > 0 && !chargingStation.isConnectorAvailable(connectorId)) { + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + if (connectorId === 0 && !chargingStation.getReserveConnectorZeroSupported()) { + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + if (!(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, connectorId, idTag))) { + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const connectorStatus = chargingStation.getConnectorStatus(connectorId)! + resetAuthorizeConnectorStatus(connectorStatus) let response: OCPP16ReserveNowResponse try { - if (connectorId > 0 && !chargingStation.isConnectorAvailable(connectorId)) { - return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED - } - if (connectorId === 0 && !chargingStation.getReserveConnectorZeroSupported()) { - return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED - } - if (!(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, connectorId, idTag))) { - return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED - } await removeExpiredReservations(chargingStation) - switch (chargingStation.getConnectorStatus(connectorId)?.status) { + switch (connectorStatus.status) { case OCPP16ChargePointStatus.Faulted: response = OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED break