Fix meterStop type in stop transaction payload
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 30 Aug 2022 21:58:33 +0000 (23:58 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 30 Aug 2022 21:58:33 +0000 (23:58 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index d9f0e249047c8c10168e0fb92115d0b61269015c..703b2d0b371179367644857eb0b187dd78af552d 100644 (file)
@@ -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,
       });
index 3129ae556daa5b639cfc654a02a2070e92b5e70d..0c2123a6fb123d693fedb4ad7e7540c9f8a65ccc 100644 (file)
@@ -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,
             });
index 64332533d4dfc606f9b551e5f3f0de8aa85c66ab..1d788505d541e00c00b0fadb46de0a4f889a0180 100644 (file)
@@ -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,
index f02709a5963d8f5c21acdf7f92716f907739fdb4..0589da01c4d6fc3452009275ac1e64a4bffe0b3a 100644 (file)
@@ -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;