Convert sendMeterValues to OCPP message sending handler
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 8 Mar 2022 10:46:02 +0000 (11:46 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 8 Mar 2022 10:46:02 +0000 (11:46 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index e90bd60be551901839c5963fe5938d5fb14eef82..c0501b76089b10d36a705a9e799ecf77a3da6508 100644 (file)
@@ -23,7 +23,7 @@ import {
   SupportedFeatureProfiles,
   VendorDefaultParametersKey,
 } from '../types/ocpp/Configuration';
-import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
+import { MeterValue, MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
 import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
 import WebSocket, { ClientOptions, Data, OPEN, RawData } from 'ws';
 
@@ -455,11 +455,18 @@ export default class ChargingStation {
       this.getConnectorStatus(connectorId).transactionSetInterval = setInterval(
         // eslint-disable-next-line @typescript-eslint/no-misused-promises
         async (): Promise<void> => {
-          await this.ocppRequestService.sendMeterValues(
+          // FIXME: Implement OCPP version agnostic helpers
+          const meterValue: MeterValue = OCPP16ServiceUtils.buildMeterValue(
+            this,
             connectorId,
             this.getConnectorStatus(connectorId).transactionId,
             interval
           );
+          await this.ocppRequestService.sendMessageHandler(RequestCommand.METER_VALUES, {
+            connectorId,
+            transactionId: this.getConnectorStatus(connectorId).transactionId,
+            meterValue: [meterValue],
+          });
         },
         interval
       );
index 7ef652f01383e5ddf1a484021bbc062a8e6d5ee3..87d7710460bd651e4e6dd5e7a591510232952860 100644 (file)
@@ -57,25 +57,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
     );
   }
 
-  public async sendMeterValues(
-    connectorId: number,
-    transactionId: number,
-    interval: number
-  ): Promise<void> {
-    const meterValue: OCPP16MeterValue = OCPP16ServiceUtils.buildMeterValue(
-      this.chargingStation,
-      connectorId,
-      transactionId,
-      interval
-    );
-    const payload: MeterValuesRequest = {
-      connectorId,
-      transactionId,
-      meterValue: [meterValue],
-    };
-    await this.sendMessage(Utils.generateUUID(), payload, OCPP16RequestCommand.METER_VALUES);
-  }
-
   public async sendTransactionBeginMeterValues(
     connectorId: number,
     transactionId: number,
index 4fe2c14155dde77ff6cd88a38f2170cad9a69307..dc5bf9b507f4270fadf0e060c579b1333e296e29 100644 (file)
@@ -5,7 +5,6 @@ import {
   ResponseType,
   SendParams,
 } from '../../types/ocpp/Requests';
-import { StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction';
 
 import type ChargingStation from '../ChargingStation';
 import Constants from '../../utils/Constants';
@@ -325,12 +324,6 @@ export default abstract class OCPPRequestService {
     params?: SendParams
   ): Promise<ResponseType>;
 
-  public abstract sendMeterValues(
-    connectorId: number,
-    transactionId: number,
-    interval: number
-  ): Promise<void>;
-
   public abstract sendTransactionBeginMeterValues(
     connectorId: number,
     transactionId: number,