Ensure start transaction payload is always compliant with OCA specs
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 15 Jan 2023 11:52:30 +0000 (12:52 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 15 Jan 2023 11:52:30 +0000 (12:52 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.cfignore
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/2.0/OCPP20RequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index 12957ca081a3c3b531312b7701071e2bae277028..f23ccd1462c60e987138f5f19bf47c8d28a8ebc6 100644 (file)
--- a/.cfignore
+++ b/.cfignore
@@ -11,6 +11,7 @@
 .husky
 .editorconfig
 .vscode
+*.code-workspace
 .clinic
 *.clinic-*
 .tscache
 *tags-template.*
 *config-template.*
 *cf-template.*
+manifest-*.yml
 *.tar.gz
 *.mta
 rollup.config.js
 rollup.config.mjs
+mikro-orm.config.ts
 mta.yaml
 mta_archives
 docker
index ee1ebff4f92006375f0880f5c67cc36ae74122cf..ad68f09cb9265eefd84969387c6fe1f64449f32e 100644 (file)
@@ -341,16 +341,16 @@ export default class ChargingStation {
 
   public getEnergyActiveImportRegisterByTransactionId(
     transactionId: number,
-    meterStop = false
+    rounded = false
   ): number {
     return this.getEnergyActiveImportRegister(
       this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)),
-      meterStop
+      rounded
     );
   }
 
-  public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number {
-    return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId));
+  public getEnergyActiveImportRegisterByConnectorId(connectorId: number, rounded = false): number {
+    return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId), rounded);
   }
 
   public getAuthorizeRemoteTxRequests(): boolean {
@@ -1637,19 +1637,16 @@ export default class ChargingStation {
     logger.error(this.logPrefix() + ' WebSocket error:', error);
   }
 
-  private getEnergyActiveImportRegister(
-    connectorStatus: ConnectorStatus,
-    meterStop = false
-  ): number {
+  private getEnergyActiveImportRegister(connectorStatus: ConnectorStatus, rounded = false): number {
     if (this.getMeteringPerTransaction() === true) {
       return (
-        (meterStop === true
+        (rounded === true
           ? Math.round(connectorStatus?.transactionEnergyActiveImportRegisterValue)
           : connectorStatus?.transactionEnergyActiveImportRegisterValue) ?? 0
       );
     }
     return (
-      (meterStop === true
+      (rounded === true
         ? Math.round(connectorStatus?.energyActiveImportRegisterValue)
         : connectorStatus?.energyActiveImportRegisterValue) ?? 0
     );
index 9979c70aa8101f41facf955a637b5d3fc2bd5b52..15b2f2dd64e8ba130d8a31268d04ff82fa501f19 100644 (file)
@@ -116,15 +116,10 @@ export default class OCPP16RequestService extends OCPPRequestService {
     params?: RequestParams
   ): Promise<ResponseType> {
     if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) {
-      const requestPayload = this.buildRequestPayload<RequestType>(
-        chargingStation,
-        commandName,
-        commandParams
-      );
       return (await this.sendMessage(
         chargingStation,
         Utils.generateUUID(),
-        requestPayload,
+        this.buildRequestPayload<RequestType>(chargingStation, commandName, commandParams),
         commandName,
         params
       )) as unknown as ResponseType;
@@ -165,7 +160,8 @@ export default class OCPP16RequestService extends OCPPRequestService {
         return {
           idTag: Constants.DEFAULT_IDTAG,
           meterStart: chargingStation.getEnergyActiveImportRegisterByConnectorId(
-            commandParams?.connectorId as number
+            commandParams?.connectorId as number,
+            true
           ),
           timestamp: new Date(),
           ...commandParams,
index eddbcf8da142d243c3c28910ea10b798a25359e4..ccacc0fa541a06efba86a58f763229297623e837 100644 (file)
@@ -64,15 +64,10 @@ export default class OCPP20RequestService extends OCPPRequestService {
     params?: RequestParams
   ): Promise<ResponseType> {
     if (OCPP20ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) {
-      const requestPayload = this.buildRequestPayload<RequestType>(
-        chargingStation,
-        commandName,
-        commandParams
-      );
       return (await this.sendMessage(
         chargingStation,
         Utils.generateUUID(),
-        requestPayload,
+        this.buildRequestPayload<RequestType>(chargingStation, commandName, commandParams),
         commandName,
         params
       )) as unknown as ResponseType;
index b72c2a8c2da99460627fee6cb9d9fc7de8b87e3a..c885a68e52a6f535886e103686f021f6b87bce89 100644 (file)
@@ -249,15 +249,21 @@ export default abstract class OCPPRequestService {
             const beginId = PerformanceStatistics.beginMeasure(commandName as string);
             try {
               chargingStation.wsConnection.send(messageToSend);
+              logger.debug(
+                `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
+                  messageType
+                )} payload: ${messageToSend}`
+              );
             } catch (error) {
+              logger.error(
+                `${chargingStation.logPrefix()} >> Command '${commandName}' failed to send ${this.getMessageTypeString(
+                  messageType
+                )} payload: ${messageToSend}:`,
+                error
+              );
               sendError = true;
             }
             PerformanceStatistics.endMeasure(commandName as string, beginId);
-            logger.debug(
-              `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
-                messageType
-              )} payload: ${messageToSend}`
-            );
           }
           const wsClosedOrErrored =
             chargingStation.isWebSocketConnectionOpened() === false || sendError === true;