Convert sendStartTransaction to OCPP message sending handler
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Mar 2022 22:45:34 +0000 (23:45 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Mar 2022 22:45:34 +0000 (23:45 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index eb45b056b80d6625e18be881b0d515789b95048c..d76ff970a2445fdb0c0039e35175459e5f4641b5 100644 (file)
@@ -284,10 +284,13 @@ export default class AutomaticTransactionGenerator {
           this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
           logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
           // Start transaction
-          startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(
-            connectorId,
-            idTag
-          );
+          startResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
+            RequestCommand.START_TRANSACTION,
+            {
+              connectorId,
+              idTag,
+            }
+          )) as StartTransactionResponse;
           PerformanceStatistics.endMeasure(measureId, beginId);
           return startResponse;
         }
@@ -297,15 +300,21 @@ export default class AutomaticTransactionGenerator {
       }
       logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
       // Start transaction
-      startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(
-        connectorId,
-        idTag
-      );
+      startResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
+        RequestCommand.START_TRANSACTION,
+        {
+          connectorId,
+          idTag,
+        }
+      )) as StartTransactionResponse;
       PerformanceStatistics.endMeasure(measureId, beginId);
       return startResponse;
     }
     logger.info(this.logPrefix(connectorId) + ' start transaction without an idTag');
-    startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(connectorId);
+    startResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
+      RequestCommand.START_TRANSACTION,
+      { connectorId }
+    )) as StartTransactionResponse;
     PerformanceStatistics.endMeasure(measureId, beginId);
     return startResponse;
   }
index 13dac32d883e0b61a2a03152cf04828f7a8ee499..6aae66f6a01ae8ddce12660ee1b086f6e1bae63f 100644 (file)
@@ -35,6 +35,7 @@ import { Client, FTPResponse } from 'basic-ftp';
 import {
   OCPP16AuthorizationStatus,
   OCPP16AuthorizeResponse,
+  OCPP16StartTransactionResponse,
   OCPP16StopTransactionReason,
 } from '../../../types/ocpp/1.6/Transaction';
 
@@ -566,10 +567,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               ).transactionRemoteStarted = true;
               if (
                 (
-                  await this.chargingStation.ocppRequestService.sendStartTransaction(
-                    transactionConnectorId,
-                    commandPayload.idTag
-                  )
+                  (await this.chargingStation.ocppRequestService.sendMessageHandler(
+                    OCPP16RequestCommand.START_TRANSACTION,
+                    {
+                      connectorId: transactionConnectorId,
+                      idTag: commandPayload.idTag,
+                    }
+                  )) as OCPP16StartTransactionResponse
                 ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
               ) {
                 logger.debug(
@@ -609,10 +613,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
             true;
           if (
             (
-              await this.chargingStation.ocppRequestService.sendStartTransaction(
-                transactionConnectorId,
-                commandPayload.idTag
-              )
+              (await this.chargingStation.ocppRequestService.sendMessageHandler(
+                OCPP16RequestCommand.START_TRANSACTION,
+                {
+                  connectorId: transactionConnectorId,
+                  idTag: commandPayload.idTag,
+                }
+              )) as OCPP16StartTransactionResponse
             ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
           ) {
             logger.debug(
index 241e42f5d4e62533dcb512936fe3d7f4345d60a3..ca024649fc4582bcc00eb35060b16423fb40d685 100644 (file)
@@ -60,23 +60,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
     );
   }
 
-  public async sendStartTransaction(
-    connectorId: number,
-    idTag?: string
-  ): Promise<OCPP16StartTransactionResponse> {
-    const payload: StartTransactionRequest = {
-      connectorId,
-      ...(!Utils.isUndefined(idTag) ? { idTag } : { idTag: Constants.DEFAULT_IDTAG }),
-      meterStart: this.chargingStation.getEnergyActiveImportRegisterByConnectorId(connectorId),
-      timestamp: new Date().toISOString(),
-    };
-    return (await this.sendMessage(
-      Utils.generateUUID(),
-      payload,
-      OCPP16RequestCommand.START_TRANSACTION
-    )) as OCPP16StartTransactionResponse;
-  }
-
   public async sendStopTransaction(
     transactionId: number,
     meterStop: number,
index 4abf7ad31a2dbc5c3ad5f17debc84d8cd6b0b6e2..f4a1d1699b9649c6fdf02159a359d4f186c1834b 100644 (file)
@@ -5,11 +5,7 @@ import {
   ResponseType,
   SendParams,
 } from '../../types/ocpp/Requests';
-import {
-  StartTransactionResponse,
-  StopTransactionReason,
-  StopTransactionResponse,
-} from '../../types/ocpp/Transaction';
+import { StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction';
 
 import type ChargingStation from '../ChargingStation';
 import Constants from '../../utils/Constants';
@@ -329,11 +325,6 @@ export default abstract class OCPPRequestService {
     params?: SendParams
   ): Promise<ResponseType>;
 
-  public abstract sendStartTransaction(
-    connectorId: number,
-    idTag?: string
-  ): Promise<StartTransactionResponse>;
-
   public abstract sendStopTransaction(
     transactionId: number,
     meterStop: number,