From 0f3d5941398b0cada28c2093110868f4d3c70266 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Mar 2022 11:46:02 +0100 Subject: [PATCH] Convert sendMeterValues to OCPP message sending handler MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 11 +++++++++-- .../ocpp/1.6/OCPP16RequestService.ts | 19 ------------------- .../ocpp/OCPPRequestService.ts | 7 ------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index e90bd60b..c0501b76 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 => { - 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 ); diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 7ef652f0..87d77104 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -57,25 +57,6 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } - public async sendMeterValues( - connectorId: number, - transactionId: number, - interval: number - ): Promise { - 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, diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 4fe2c141..dc5bf9b5 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -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; - public abstract sendMeterValues( - connectorId: number, - transactionId: number, - interval: number - ): Promise; - public abstract sendTransactionBeginMeterValues( connectorId: number, transactionId: number, -- 2.34.1