From 07989fad0a792547969c7a544d0093f4cb6338d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 30 Aug 2022 23:58:33 +0200 Subject: [PATCH] Fix meterStop type in stop transaction payload MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 5 ++- src/charging-station/ChargingStation.ts | 40 +++++++++++++------ .../ChargingStationWorkerBroadcastChannel.ts | 3 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 10 ++++- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index d9f0e249..703b2d0b 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -369,7 +369,10 @@ export default class AutomaticTransactionGenerator { StopTransactionResponse >(this.chargingStation, RequestCommand.STOP_TRANSACTION, { transactionId, - meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), + meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( + transactionId, + true + ), idTag: this.chargingStation.getTransactionIdTag(transactionId), reason, }); diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 3129ae55..0c2123a6 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -331,22 +331,18 @@ export default class ChargingStation { } } - public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number { - const transactionConnectorStatus = this.getConnectorStatus( - this.getConnectorIdByTransactionId(transactionId) + public getEnergyActiveImportRegisterByTransactionId( + transactionId: number, + meterStop = false + ): number { + return this.getEnergyActiveImportRegister( + this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)), + meterStop ); - if (this.getMeteringPerTransaction()) { - return transactionConnectorStatus?.transactionEnergyActiveImportRegisterValue ?? 0; - } - return transactionConnectorStatus?.energyActiveImportRegisterValue ?? 0; } public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number { - const connectorStatus = this.getConnectorStatus(connectorId); - if (this.getMeteringPerTransaction()) { - return connectorStatus?.transactionEnergyActiveImportRegisterValue ?? 0; - } - return connectorStatus?.energyActiveImportRegisterValue ?? 0; + return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId)); } public getAuthorizeRemoteTxRequests(): boolean { @@ -1577,6 +1573,24 @@ export default class ChargingStation { logger.error(this.logPrefix() + ' WebSocket error:', error); } + private getEnergyActiveImportRegister( + connectorStatus: ConnectorStatus, + meterStop = false + ): number { + if (this.getMeteringPerTransaction()) { + return ( + (meterStop === true + ? Math.round(connectorStatus?.transactionEnergyActiveImportRegisterValue) + : connectorStatus?.transactionEnergyActiveImportRegisterValue) ?? 0 + ); + } + return ( + (meterStop === true + ? Math.round(connectorStatus?.energyActiveImportRegisterValue) + : connectorStatus?.energyActiveImportRegisterValue) ?? 0 + ); + } + private getUseConnectorId0(stationInfo?: ChargingStationInfo): boolean | undefined { const localStationInfo = stationInfo ?? this.stationInfo; return !Utils.isUndefined(localStationInfo.useConnectorId0) @@ -1811,7 +1825,7 @@ export default class ChargingStation { StopTransactionResponse >(this, RequestCommand.STOP_TRANSACTION, { transactionId, - meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId), + meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId, true), idTag: this.getTransactionIdTag(transactionId), reason, }); diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 64332533..1d788505 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -133,7 +133,8 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca >(this.chargingStation, RequestCommand.STOP_TRANSACTION, { transactionId: requestPayload.transactionId, meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( - requestPayload.transactionId + requestPayload.transactionId, + true ), idTag: this.chargingStation.getTransactionIdTag(requestPayload.transactionId), reason: StopTransactionReason.NONE, diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index f02709a5..0589da01 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -440,7 +440,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16StopTransactionResponse >(chargingStation, OCPP16RequestCommand.STOP_TRANSACTION, { transactionId, - meterStop: chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), + meterStop: chargingStation.getEnergyActiveImportRegisterByTransactionId( + transactionId, + true + ), idTag: chargingStation.getTransactionIdTag(transactionId), reason: OCPP16StopTransactionReason.UNLOCK_COMMAND, }); @@ -1004,7 +1007,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16StopTransactionResponse >(chargingStation, OCPP16RequestCommand.STOP_TRANSACTION, { transactionId, - meterStop: chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), + meterStop: chargingStation.getEnergyActiveImportRegisterByTransactionId( + transactionId, + true + ), idTag: chargingStation.getTransactionIdTag(transactionId), }); return Constants.OCPP_RESPONSE_ACCEPTED; -- 2.34.1