From: Jérôme Benoit Date: Tue, 30 Aug 2022 21:58:33 +0000 (+0200) Subject: Fix meterStop type in stop transaction payload X-Git-Tag: v1.1.69~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=07989fad0a792547969c7a544d0093f4cb6338d3;p=e-mobility-charging-stations-simulator.git Fix meterStop type in stop transaction payload Signed-off-by: Jérôme Benoit --- 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;