From 2cace1a546e371a9326f84179d0e2384275048bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 19 Jan 2023 21:40:29 +0100 Subject: [PATCH] Ensure a transaction is always stopped, whatever is the CSMS response. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit OCPP specs compliance Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16ResponseService.ts | 128 +++++++++--------- 1 file changed, 63 insertions(+), 65 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 0af8ad16..d7772bdc 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -614,72 +614,70 @@ export default class OCPP16ResponseService extends OCPPResponseService { ); return; } - if (payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { - chargingStation.getBeginEndMeterValues() === true && - chargingStation.getOcppStrictCompliance() === false && - chargingStation.getOutOfOrderEndMeterValues() === true && - (await chargingStation.ocppRequestService.requestHandler< - OCPP16MeterValuesRequest, - OCPP16MeterValuesResponse - >(chargingStation, OCPP16RequestCommand.METER_VALUES, { - connectorId: transactionConnectorId, - transactionId: requestPayload.transactionId, - meterValue: [ - OCPP16ServiceUtils.buildTransactionEndMeterValue( - chargingStation, - transactionConnectorId, - requestPayload.meterStop - ), - ], - })); - if ( - chargingStation.isChargingStationAvailable() === false || - chargingStation.isConnectorAvailable(transactionConnectorId) === false - ) { - await chargingStation.ocppRequestService.requestHandler< - OCPP16StatusNotificationRequest, - OCPP16StatusNotificationResponse - >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { - connectorId: transactionConnectorId, - status: OCPP16ChargePointStatus.UNAVAILABLE, - errorCode: OCPP16ChargePointErrorCode.NO_ERROR, - }); - chargingStation.getConnectorStatus(transactionConnectorId).status = - OCPP16ChargePointStatus.UNAVAILABLE; - } else { - await chargingStation.ocppRequestService.requestHandler< - OCPP16BootNotificationRequest, - OCPP16BootNotificationResponse - >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { - connectorId: transactionConnectorId, - status: OCPP16ChargePointStatus.AVAILABLE, - errorCode: OCPP16ChargePointErrorCode.NO_ERROR, - }); - chargingStation.getConnectorStatus(transactionConnectorId).status = - OCPP16ChargePointStatus.AVAILABLE; - } - if (chargingStation.stationInfo.powerSharedByConnectors) { - chargingStation.powerDivider--; - } - chargingStation.resetConnectorStatus(transactionConnectorId); - logger.info( - chargingStation.logPrefix() + - ' Transaction ' + - requestPayload.transactionId.toString() + - ' STOPPED on ' + - chargingStation.stationInfo.chargingStationId + - '#' + - transactionConnectorId.toString() - ); + chargingStation.getBeginEndMeterValues() === true && + chargingStation.getOcppStrictCompliance() === false && + chargingStation.getOutOfOrderEndMeterValues() === true && + (await chargingStation.ocppRequestService.requestHandler< + OCPP16MeterValuesRequest, + OCPP16MeterValuesResponse + >(chargingStation, OCPP16RequestCommand.METER_VALUES, { + connectorId: transactionConnectorId, + transactionId: requestPayload.transactionId, + meterValue: [ + OCPP16ServiceUtils.buildTransactionEndMeterValue( + chargingStation, + transactionConnectorId, + requestPayload.meterStop + ), + ], + })); + if ( + chargingStation.isChargingStationAvailable() === false || + chargingStation.isConnectorAvailable(transactionConnectorId) === false + ) { + await chargingStation.ocppRequestService.requestHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { + connectorId: transactionConnectorId, + status: OCPP16ChargePointStatus.UNAVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); + chargingStation.getConnectorStatus(transactionConnectorId).status = + OCPP16ChargePointStatus.UNAVAILABLE; } else { - logger.warn( - chargingStation.logPrefix() + - ' Stopping transaction id ' + - requestPayload.transactionId.toString() + - " REJECTED with status '" + - payload.idTagInfo?.status + - "'" - ); + await chargingStation.ocppRequestService.requestHandler< + OCPP16BootNotificationRequest, + OCPP16BootNotificationResponse + >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { + connectorId: transactionConnectorId, + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); + chargingStation.getConnectorStatus(transactionConnectorId).status = + OCPP16ChargePointStatus.AVAILABLE; + } + if (chargingStation.stationInfo.powerSharedByConnectors) { + chargingStation.powerDivider--; + } + chargingStation.resetConnectorStatus(transactionConnectorId); + const logMsg = + chargingStation.logPrefix() + + ' Transaction ' + + requestPayload.transactionId.toString() + + ' STOPPED on ' + + chargingStation.stationInfo.chargingStationId + + '#' + + transactionConnectorId.toString() + + " with status '" + + payload.idTagInfo?.status ?? 'undefined' + "'"; + if ( + Utils.isNullOrUndefined(payload.idTagInfo) || + payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED + ) { + logger.info(logMsg); + } else { + logger.warn(logMsg); } } -- 2.34.1