From: Jérôme Benoit Date: Mon, 7 Mar 2022 22:26:23 +0000 (+0100) Subject: Convert sendAuthorize to OCPP message sending handler X-Git-Tag: v1.1.52~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2e3d65ae7245bce98c6a29be76985503dc6de29b;p=e-mobility-charging-stations-simulator.git Convert sendAuthorize to OCPP message sending handler Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index cf2f4277..eb45b056 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -11,6 +11,7 @@ import { import type ChargingStation from './ChargingStation'; import Constants from '../utils/Constants'; import PerformanceStatistics from '../performance/PerformanceStatistics'; +import { RequestCommand } from '../types/ocpp/Requests'; import { Status } from '../types/AutomaticTransactionGenerator'; import Utils from '../utils/Utils'; import logger from '../utils/Logger'; @@ -269,11 +270,15 @@ export default class AutomaticTransactionGenerator { if (this.chargingStation.hasAuthorizedTags()) { const idTag = this.chargingStation.getRandomIdTag(); if (this.chargingStation.getAutomaticTransactionGeneratorRequireAuthorize()) { + this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag; // Authorize idTag - const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize( - connectorId, - idTag - ); + const authorizeResponse: AuthorizeResponse = + (await this.chargingStation.ocppRequestService.sendMessageHandler( + RequestCommand.AUTHORIZE, + { + idTag, + } + )) as AuthorizeResponse; this.connectorsStatus.get(connectorId).authorizeRequests++; if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++; diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index ed91c87a..13dac32d 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -34,6 +34,7 @@ import { import { Client, FTPResponse } from 'basic-ftp'; import { OCPP16AuthorizationStatus, + OCPP16AuthorizeResponse, OCPP16StopTransactionReason, } from '../../../types/ocpp/1.6/Transaction'; @@ -535,10 +536,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer true; authorized = true; } else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) { - const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize( - transactionConnectorId, - commandPayload.idTag - ); + this.chargingStation.getConnectorStatus(transactionConnectorId).authorizeIdTag = + commandPayload.idTag; + const authorizeResponse: OCPP16AuthorizeResponse = + (await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.AUTHORIZE, + { + idTag: commandPayload.idTag, + } + )) as OCPP16AuthorizeResponse; if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { authorized = true; } diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 295447b0..241e42f5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -2,7 +2,6 @@ import { AuthorizeRequest, - OCPP16AuthorizeResponse, OCPP16StartTransactionResponse, OCPP16StopTransactionReason, OCPP16StopTransactionResponse, @@ -23,8 +22,6 @@ import type ChargingStation from '../../ChargingStation'; import Constants from '../../../utils/Constants'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { JsonType } from '../../../types/JsonType'; -import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; -import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import OCPPError from '../../../exception/OCPPError'; @@ -63,21 +60,6 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } - public async sendAuthorize( - connectorId: number, - idTag?: string - ): Promise { - const payload: AuthorizeRequest = { - ...(!Utils.isUndefined(idTag) ? { idTag } : { idTag: Constants.DEFAULT_IDTAG }), - }; - this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag; - return (await this.sendMessage( - Utils.generateUUID(), - payload, - OCPP16RequestCommand.AUTHORIZE - )) as OCPP16AuthorizeResponse; - } - public async sendStartTransaction( connectorId: number, idTag?: string diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 41e7a6ea..4abf7ad3 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,9 +1,3 @@ -import { - AuthorizeResponse, - StartTransactionResponse, - StopTransactionReason, - StopTransactionResponse, -} from '../../types/ocpp/Transaction'; import { DiagnosticsStatus, IncomingRequestCommand, @@ -11,10 +5,12 @@ import { ResponseType, SendParams, } from '../../types/ocpp/Requests'; +import { + StartTransactionResponse, + StopTransactionReason, + StopTransactionResponse, +} from '../../types/ocpp/Transaction'; -import { BootNotificationResponse } from '../../types/ocpp/Responses'; -import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode'; -import { ChargePointStatus } from '../../types/ocpp/ChargePointStatus'; import type ChargingStation from '../ChargingStation'; import Constants from '../../utils/Constants'; import { EmptyObject } from '../../types/EmptyObject'; @@ -333,7 +329,6 @@ export default abstract class OCPPRequestService { params?: SendParams ): Promise; - public abstract sendAuthorize(connectorId: number, idTag?: string): Promise; public abstract sendStartTransaction( connectorId: number, idTag?: string