From: Jérôme Benoit Date: Tue, 8 Mar 2022 10:46:02 +0000 (+0100) Subject: Convert sendMeterValues to OCPP message sending handler X-Git-Tag: v1.1.52~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0f3d5941398b0cada28c2093110868f4d3c70266;p=e-mobility-charging-stations-simulator.git Convert sendMeterValues to OCPP message sending handler Signed-off-by: Jérôme Benoit --- 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,