From 54b1efe020d2472d36c5bc92ae09e23d75ab0947 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 2 May 2021 22:12:23 +0200 Subject: [PATCH] Fix heartbeat start + cleanups. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 8 ++++---- src/charging-station/ChargingStation.ts | 16 ++++++++-------- .../ocpp/1.6/OCCP16IncomingRequestService.ts | 4 ++-- .../ocpp/1.6/OCPP16ResponseService.ts | 8 ++++---- src/charging-station/ocpp/OCPPRequestService.ts | 6 +++--- .../{Statistics.ts => PerformanceStatistics.ts} | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) rename src/utils/{Statistics.ts => PerformanceStatistics.ts} (96%) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index e675550f..a1e55989 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -17,7 +17,7 @@ export default class AutomaticTransactionGenerator { if (this.chargingStation.getEnableStatistics()) { this.performanceObserver = new PerformanceObserver((list) => { const entry = list.getEntries()[0]; - this.chargingStation.statistics.logPerformance(entry, Constants.ENTITY_AUTOMATIC_TRANSACTION_GENERATOR); + this.chargingStation.performanceStatistics.logPerformance(entry, Constants.ENTITY_AUTOMATIC_TRANSACTION_GENERATOR); this.performanceObserver.disconnect(); }); } @@ -96,7 +96,7 @@ export default class AutomaticTransactionGenerator { startResponse = await this.startTransaction(connectorId, this); } if (startResponse?.idTagInfo?.status !== AuthorizationStatus.ACCEPTED) { - logger.info(this.logPrefix(connectorId) + ' transaction rejected'); + logger.warn(this.logPrefix(connectorId) + ' transaction rejected'); await Utils.sleep(Constants.CHARGING_STATION_ATG_WAIT_TIME); } else { // Wait until end of transaction @@ -154,8 +154,8 @@ export default class AutomaticTransactionGenerator { private logPrefix(connectorId: number = null): string { if (connectorId) { - return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG on connector #' + connectorId.toString() + ':'); + return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' | ATG on connector #' + connectorId.toString() + ':'); } - return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG:'); + return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' | ATG:'); } } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6bff621f..a5e31588 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -21,8 +21,8 @@ import OCPPError from './OcppError'; import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService'; import OCPPRequestService from './ocpp/OCPPRequestService'; import { OCPPVersion } from '../types/ocpp/OCPPVersion'; +import PerformanceStatistics from '../utils/PerformanceStatistics'; import { StandardParametersKey } from '../types/ocpp/Configuration'; -import Statistics from '../utils/Statistics'; import { StopTransactionReason } from '../types/ocpp/Transaction'; import Utils from '../utils/Utils'; import { WebSocketCloseEventStatusCode } from '../types/WebSocket'; @@ -41,7 +41,7 @@ export default class ChargingStation { public wsConnection: WebSocket; public requests: Requests; public messageQueue: string[]; - public statistics: Statistics; + public performanceStatistics: PerformanceStatistics; public heartbeatSetInterval: NodeJS.Timeout; public ocppIncomingRequestService: OCPPIncomingRequestService; public ocppRequestService: OCPPRequestService; @@ -74,7 +74,7 @@ export default class ChargingStation { } public logPrefix(): string { - return Utils.logPrefix(` ${this.stationInfo.chargingStationId}:`); + return Utils.logPrefix(` ${this.stationInfo.chargingStationId} |`); } public getRandomTagId(): string { @@ -181,7 +181,7 @@ export default class ChargingStation { }, this.getHeartbeatInterval()); logger.info(this.logPrefix() + ' Heartbeat started every ' + Utils.milliSecondsToHHMMSS(this.getHeartbeatInterval())); } else if (this.heartbeatSetInterval) { - logger.info(this.logPrefix() + ' Heartbeat every ' + Utils.milliSecondsToHHMMSS(this.getHeartbeatInterval()) + ' already started'); + logger.info(this.logPrefix() + ' Heartbeat already started every ' + Utils.milliSecondsToHHMMSS(this.getHeartbeatInterval())); } else { logger.error(`${this.logPrefix()} Heartbeat interval set to ${this.getHeartbeatInterval() ? Utils.milliSecondsToHHMMSS(this.getHeartbeatInterval()) : this.getHeartbeatInterval()}, not starting the heartbeat`); } @@ -465,10 +465,10 @@ export default class ChargingStation { } this.stationInfo.powerDivider = this.getPowerDivider(); if (this.getEnableStatistics()) { - this.statistics = new Statistics(this.stationInfo.chargingStationId); + this.performanceStatistics = new PerformanceStatistics(this.stationInfo.chargingStationId); this.performanceObserver = new PerformanceObserver((list) => { const entry = list.getEntries()[0]; - this.statistics.logPerformance(entry, Constants.ENTITY_CHARGING_STATION); + this.performanceStatistics.logPerformance(entry, Constants.ENTITY_CHARGING_STATION); this.performanceObserver.disconnect(); }); } @@ -530,7 +530,7 @@ export default class ChargingStation { // Incoming Message case MessageType.CALL_MESSAGE: if (this.getEnableStatistics()) { - this.statistics.addMessage(commandName, messageType); + this.performanceStatistics.addMessage(commandName, messageType); } // Process the call await this.ocppIncomingRequestService.handleRequest(messageId, commandName, commandPayload); @@ -733,7 +733,7 @@ export default class ChargingStation { } } if (this.getEnableStatistics()) { - this.statistics.start(); + this.performanceStatistics.start(); } } diff --git a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts index 6b844352..d74de14e 100644 --- a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts @@ -271,7 +271,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer logger.debug(this.chargingStation.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation.stationInfo.chargingStationId + '#' + transactionConnectorID.toString() + ' for idTag ' + commandPayload.idTag); return Constants.OCPP_RESPONSE_ACCEPTED; } - logger.error(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag); + logger.warn(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag); return Constants.OCPP_RESPONSE_REJECTED; } await this.chargingStation.ocppRequestService.sendStatusNotification(transactionConnectorID, OCPP16ChargePointStatus.PREPARING); @@ -287,7 +287,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer logger.debug(this.chargingStation.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation.stationInfo.chargingStationId + '#' + transactionConnectorID.toString() + ' for idTag ' + commandPayload.idTag); return Constants.OCPP_RESPONSE_ACCEPTED; } - logger.error(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on unavailable connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag); + logger.warn(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on unavailable connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag); return Constants.OCPP_RESPONSE_REJECTED; } diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index cf1c9212..b06f1c74 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -21,13 +21,13 @@ export default class OCPP16ResponseService extends OCPPResponseService { private handleResponseBootNotification(payload: OCPP16BootNotificationResponse, requestPayload: OCPP16BootNotificationRequest): void { if (payload.status === OCPP16RegistrationStatus.ACCEPTED) { - this.chargingStation.heartbeatSetInterval ? this.chargingStation.restartHeartbeat() : this.chargingStation.startHeartbeat(); this.chargingStation.addConfigurationKey(OCPP16StandardParametersKey.HeartBeatInterval, payload.interval.toString()); this.chargingStation.addConfigurationKey(OCPP16StandardParametersKey.HeartbeatInterval, payload.interval.toString(), false, false); + this.chargingStation.heartbeatSetInterval ? this.chargingStation.restartHeartbeat() : this.chargingStation.startHeartbeat(); } else if (payload.status === OCPP16RegistrationStatus.PENDING) { logger.info(this.chargingStation.logPrefix() + ' Charging station in pending state on the central server'); } else { - logger.info(this.chargingStation.logPrefix() + ' Charging station rejected by the central server'); + logger.warn(this.chargingStation.logPrefix() + ' Charging station rejected by the central server'); } } @@ -64,7 +64,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { const configuredMeterValueSampleInterval = this.chargingStation.getConfigurationKey(OCPP16StandardParametersKey.MeterValueSampleInterval); this.chargingStation.startMeterValues(connectorId, configuredMeterValueSampleInterval ? Utils.convertToInt(configuredMeterValueSampleInterval.value) * 1000 : 60000); } else { - logger.error(this.chargingStation.logPrefix() + ' Starting transaction id ' + payload.transactionId.toString() + ' REJECTED with status ' + payload?.idTagInfo?.status + ', idTag ' + requestPayload.idTag); + logger.warn(this.chargingStation.logPrefix() + ' Starting transaction id ' + payload.transactionId.toString() + ' REJECTED with status ' + payload?.idTagInfo?.status + ', idTag ' + requestPayload.idTag); this.chargingStation.resetTransactionOnConnector(connectorId); await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, OCPP16ChargePointStatus.AVAILABLE); this.chargingStation.getConnector(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; @@ -97,7 +97,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { logger.info(this.chargingStation.logPrefix() + ' Transaction ' + requestPayload.transactionId.toString() + ' STOPPED on ' + this.chargingStation.stationInfo.chargingStationId + '#' + transactionConnectorId.toString()); this.chargingStation.resetTransactionOnConnector(transactionConnectorId); } else { - logger.error(this.chargingStation.logPrefix() + ' Stopping transaction id ' + requestPayload.transactionId.toString() + ' REJECTED with status ' + payload.idTagInfo?.status); + logger.warn(this.chargingStation.logPrefix() + ' Stopping transaction id ' + requestPayload.transactionId.toString() + ' REJECTED with status ' + payload.idTagInfo?.status); } } diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 20163f7d..1a91cc8b 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -49,7 +49,7 @@ export default abstract class OCPPRequestService { // Check if wsConnection opened and charging station registered if (this.chargingStation.isWebSocketOpen() && (this.chargingStation.isRegistered() || commandName === RequestCommand.BOOT_NOTIFICATION)) { if (this.chargingStation.getEnableStatistics()) { - this.chargingStation.statistics.addMessage(commandName, messageType); + this.chargingStation.performanceStatistics.addMessage(commandName, messageType); } // Yes: Send Message this.chargingStation.wsConnection.send(messageToSend); @@ -76,7 +76,7 @@ export default abstract class OCPPRequestService { */ async function responseCallback(payload: Record | string, requestPayload: Record): Promise { if (self.chargingStation.getEnableStatistics()) { - self.chargingStation.statistics.addMessage(commandName, MessageType.CALL_RESULT_MESSAGE); + self.chargingStation.performanceStatistics.addMessage(commandName, MessageType.CALL_RESULT_MESSAGE); } // Send the response await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload); @@ -90,7 +90,7 @@ export default abstract class OCPPRequestService { */ function rejectCallback(error: OCPPError): void { if (self.chargingStation.getEnableStatistics()) { - self.chargingStation.statistics.addMessage(commandName, MessageType.CALL_ERROR_MESSAGE); + self.chargingStation.performanceStatistics.addMessage(commandName, MessageType.CALL_ERROR_MESSAGE); } logger.debug(`${self.chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams); // Build Exception diff --git a/src/utils/Statistics.ts b/src/utils/PerformanceStatistics.ts similarity index 96% rename from src/utils/Statistics.ts rename to src/utils/PerformanceStatistics.ts index 65e3be5b..d7a4388e 100644 --- a/src/utils/Statistics.ts +++ b/src/utils/PerformanceStatistics.ts @@ -8,7 +8,7 @@ import { PerformanceEntry } from 'perf_hooks'; import Utils from './Utils'; import logger from './Logger'; -export default class Statistics { +export default class PerformanceStatistics { private objId: string; private commandsStatistics: CommandStatistics; @@ -52,7 +52,7 @@ export default class Statistics { } break; default: - logger.error(`${this.logPrefix()} Wrong message type ${messageType}`); + logger.error(`${this.logPrefix()} wrong message type ${messageType}`); break; } } @@ -64,7 +64,7 @@ export default class Statistics { perfEntry.entryType = entry.entryType; perfEntry.startTime = entry.startTime; perfEntry.duration = entry.duration; - logger.info(`${this.logPrefix()} object ${className} method(s) performance entry: %j`, perfEntry); + logger.info(`${this.logPrefix()} ${className} method(s) entry: %j`, perfEntry); } public start(): void { @@ -137,6 +137,6 @@ export default class Statistics { } private logPrefix(): string { - return Utils.logPrefix(` ${this.objId} Statistics:`); + return Utils.logPrefix(` ${this.objId} | Performance statistics`); } } -- 2.34.1