From e7454a1f193140bdd635fd3b8b489c51b774f9d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 7 Mar 2022 23:45:34 +0100 Subject: [PATCH] Convert sendStartTransaction 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 --- .../AutomaticTransactionGenerator.ts | 27 ++++++++++++------- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 23 ++++++++++------ .../ocpp/1.6/OCPP16RequestService.ts | 17 ------------ .../ocpp/OCPPRequestService.ts | 11 +------- 4 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index eb45b056..d76ff970 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -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; } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 13dac32d..6aae66f6 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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( diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 241e42f5..ca024649 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -60,23 +60,6 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } - public async sendStartTransaction( - connectorId: number, - idTag?: string - ): Promise { - 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, diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 4abf7ad3..f4a1d169 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -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; - public abstract sendStartTransaction( - connectorId: number, - idTag?: string - ): Promise; - public abstract sendStopTransaction( transactionId: number, meterStop: number, -- 2.34.1