X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=2813d39aad5c0ca89f4e6af9ffc31615182b4dfc;hb=9a3b8d9fcb673461f651ca0993d708583528b296;hp=1430de0701cf5bcb356b484adc8581c812ec7725;hpb=3a33b6a907a44aabd721d3c63e6c5984f4f60c28;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 1430de07..2813d39a 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( @@ -154,6 +154,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 +217,6 @@ export default abstract class OCPPRequestService { resolve(payload); } catch (error) { reject(error); - throw error; } finally { self.chargingStation.requests.delete(messageId); } @@ -303,6 +307,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,13 +333,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 sendDiagnosticsStatusNotification( - diagnosticsStatus: DiagnosticsStatus - ): Promise; + ): Promise; }