X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=021e09f369edb855d5be7d161e512f073d3504a3;hb=9b75e3ab59b911697ad2f809e2aee6967a46e0c4;hp=dc5bf9b507f4270fadf0e060c579b1333e296e29;hpb=0f3d5941398b0cada28c2093110868f4d3c70266;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index dc5bf9b5..021e09f3 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,5 +1,4 @@ import { - DiagnosticsStatus, IncomingRequestCommand, RequestCommand, ResponseType, @@ -13,7 +12,6 @@ import { ErrorType } from '../../types/ocpp/ErrorType'; import { HandleErrorParams } from '../../types/Error'; import { JsonType } from '../../types/JsonType'; import { MessageType } from '../../types/ocpp/MessageType'; -import { MeterValue } from '../../types/ocpp/MeterValues'; import OCPPError from '../../exception/OCPPError'; import type OCPPResponseService from './OCPPResponseService'; import PerformanceStatistics from '../../performance/PerformanceStatistics'; @@ -36,6 +34,8 @@ export default abstract class OCPPRequestService { this.chargingStation = chargingStation; this.ocppResponseService = ocppResponseService; this.sendMessageHandler.bind(this); + this.sendResult.bind(this); + this.sendError.bind(this); } public static getInstance( @@ -43,13 +43,13 @@ export default abstract class OCPPRequestService { chargingStation: ChargingStation, ocppResponseService: OCPPResponseService ): T { - if (!OCPPRequestService.instances.has(chargingStation.id)) { + if (!OCPPRequestService.instances.has(chargingStation.hashId)) { OCPPRequestService.instances.set( - chargingStation.id, + chargingStation.hashId, new this(chargingStation, ocppResponseService) ); } - return OCPPRequestService.instances.get(chargingStation.id) as T; + return OCPPRequestService.instances.get(chargingStation.hashId) as T; } public async sendResult( @@ -126,7 +126,8 @@ export default abstract class OCPPRequestService { (!this.chargingStation.getOcppStrictCompliance() && this.chargingStation.isInUnknownState()) || this.chargingStation.isInAcceptedState() || - (this.chargingStation.isInPendingState() && params.triggerMessage) + (this.chargingStation.isInPendingState() && + (params.triggerMessage || messageType === MessageType.CALL_RESULT_MESSAGE)) ) { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; @@ -154,6 +155,11 @@ export default abstract class OCPPRequestService { // FIXME: Handle sending error this.chargingStation.wsConnection.send(messageToSend); PerformanceStatistics.endMeasure(commandName, beginId); + logger.debug( + `${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString( + messageType + )} payload: ${messageToSend}` + ); } else if (!params.skipBufferingOnError) { // Buffer it this.chargingStation.bufferMessage(messageToSend); @@ -212,7 +218,6 @@ export default abstract class OCPPRequestService { resolve(payload); } catch (error) { reject(error); - throw error; } finally { self.chargingStation.requests.delete(messageId); } @@ -303,6 +308,17 @@ export default abstract class OCPPRequestService { return messageToSend; } + private getMessageTypeString(messageType: MessageType): string { + switch (messageType) { + case MessageType.CALL_MESSAGE: + return 'request'; + case MessageType.CALL_RESULT_MESSAGE: + return 'response'; + case MessageType.CALL_ERROR_MESSAGE: + return 'error'; + } + } + private handleRequestError( commandName: RequestCommand | IncomingRequestCommand, error: Error, @@ -318,25 +334,10 @@ export default abstract class OCPPRequestService { } } - public abstract sendMessageHandler( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public abstract sendMessageHandler( commandName: RequestCommand, commandParams?: JsonType, params?: SendParams - ): Promise; - - public abstract sendTransactionBeginMeterValues( - connectorId: number, - transactionId: number, - beginMeterValue: MeterValue - ): Promise; - - public abstract sendTransactionEndMeterValues( - connectorId: number, - transactionId: number, - endMeterValue: MeterValue - ): Promise; - - public abstract sendDiagnosticsStatusNotification( - diagnosticsStatus: DiagnosticsStatus - ): Promise; + ): Promise; }