From 2cc5d5ec705dae9c7b88be0733dddc22d652a17e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 15 Jan 2023 17:33:53 +0100 Subject: [PATCH] Move OCPP log message formatting helper into static helpers class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 2 +- src/charging-station/ocpp/OCPPRequestService.ts | 17 +++-------------- src/charging-station/ocpp/OCPPServiceUtils.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 15 deletions(-) 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 -- 2.34.1