From: Jérôme Benoit Date: Sun, 15 Jan 2023 16:33:53 +0000 (+0100) Subject: Move OCPP log message formatting helper into static helpers class X-Git-Tag: v1.1.90~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2cc5d5ec705dae9c7b88be0733dddc22d652a17e;p=e-mobility-charging-stations-simulator.git Move OCPP log message formatting helper into static helpers class Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index e531aa0f..84930a5f 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1568,7 +1568,7 @@ export default class ChargingStation { logger.debug( `${this.logPrefix()} << Command '${ requestCommandName ?? Constants.UNKNOWN_COMMAND - }' received error payload: ${JSON.stringify(request)}` + }' received error response payload: ${JSON.stringify(request)}` ); errorCallback(new OCPPError(errorType, errorMessage, requestCommandName, errorDetails)); break; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index c885a68e..023d5f95 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -250,13 +250,13 @@ export default abstract class OCPPRequestService { try { chargingStation.wsConnection.send(messageToSend); logger.debug( - `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString( + `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${OCPPServiceUtils.getMessageTypeString( messageType )} payload: ${messageToSend}` ); } catch (error) { logger.error( - `${chargingStation.logPrefix()} >> Command '${commandName}' failed to send ${this.getMessageTypeString( + `${chargingStation.logPrefix()} >> Command '${commandName}' failed to send ${OCPPServiceUtils.getMessageTypeString( messageType )} payload: ${messageToSend}:`, error @@ -344,7 +344,7 @@ export default abstract class OCPPRequestService { ); } logger.error( - `${chargingStation.logPrefix()} Error occurred at ${self.getMessageTypeString( + `${chargingStation.logPrefix()} Error occurred at ${OCPPServiceUtils.getMessageTypeString( messageType )} command ${commandName} with PDU %j:`, messagePayload, @@ -427,17 +427,6 @@ 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 handleSendMessageError( chargingStation: ChargingStation, commandName: RequestCommand | IncomingRequestCommand, diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 08618941..cf2aa07e 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -9,6 +9,7 @@ import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode'; import { StandardParametersKey } from '../../types/ocpp/Configuration'; import type { ConnectorStatusEnum } from '../../types/ocpp/ConnectorStatusEnum'; import { ErrorType } from '../../types/ocpp/ErrorType'; +import { MessageType } from '../../types/ocpp/MessageType'; import { MeterValueMeasurand, type MeterValuePhase } from '../../types/ocpp/MeterValues'; import { OCPPVersion } from '../../types/ocpp/OCPPVersion'; import { @@ -44,6 +45,17 @@ export class OCPPServiceUtils { return ErrorType.FORMAT_VIOLATION; } + public static 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'; + } + } + public static isRequestCommandSupported( chargingStation: ChargingStation, command: RequestCommand