From 7162326761291e5683f7a6e08b7845ea37e35a07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 1 Feb 2021 02:29:32 +0100 Subject: [PATCH] Add debug log for CPs. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/AutomaticTransactionGenerator.ts | 1 + src/charging-station/ChargingStation.ts | 7 +++++-- .../ocpp/1.6/OCCP16IncomingRequestService.ts | 10 ++++++++-- src/utils/Configuration.ts | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 92992754..90dff98b 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -27,6 +27,7 @@ export default class AutomaticTransactionGenerator { this.timeToStop = false; if (this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours && this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours > 0) { + // eslint-disable-next-line @typescript-eslint/no-misused-promises setTimeout(async (): Promise => { await this.stop(); }, this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600 * 1000); diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c532eea0..a19ad3b4 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -174,7 +174,8 @@ export default class ChargingStation { public startHeartbeat(): void { if (this.getHeartbeatInterval() && this.getHeartbeatInterval() > 0 && !this.heartbeatSetInterval) { - this.heartbeatSetInterval = setInterval(async () => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + this.heartbeatSetInterval = setInterval(async (): Promise => { await this.ocppRequestService.sendHeartbeat(); }, this.getHeartbeatInterval()); logger.info(this.logPrefix() + ' Heartbeat started every ' + Utils.milliSecondsToHHMMSS(this.getHeartbeatInterval())); @@ -209,7 +210,8 @@ export default class ChargingStation { return; } if (interval > 0) { - this.getConnector(connectorId).transactionSetInterval = setInterval(async () => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + this.getConnector(connectorId).transactionSetInterval = setInterval(async (): Promise => { if (this.getEnableStatistics()) { const sendMeterValues = performance.timerify(this.ocppRequestService.sendMeterValues); this.performanceObserver.observe({ @@ -824,6 +826,7 @@ export default class ChargingStation { } private startStationTemplateFileMonitoring(): void { + // eslint-disable-next-line @typescript-eslint/no-misused-promises fs.watch(this.stationTemplateFile).on('change', async (e): Promise => { try { logger.debug(this.logPrefix() + ' Template file ' + this.stationTemplateFile + ' have changed, reload'); diff --git a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts index f94f410b..a63a28e4 100644 --- a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts @@ -40,10 +40,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer // Simulate charging station restart private handleRequestReset(commandPayload: ResetRequest): DefaultResponse { - setImmediate(async () => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + setImmediate(async (): Promise => { await this.chargingStation.stop(commandPayload.type + 'Reset' as OCPP16StopTransactionReason); await Utils.sleep(this.chargingStation.stationInfo.resetTime); - await this.chargingStation.start(); + this.chargingStation.start(); }); logger.info(`${this.chargingStation.logPrefix()} ${commandPayload.type} reset command received, simulating it. The station will be back online in ${Utils.milliSecondsToHHMMSS(this.chargingStation.stationInfo.resetTime)}`); return Constants.OCPP_RESPONSE_ACCEPTED; @@ -169,6 +170,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED; } this.chargingStation.setChargingProfile(commandPayload.connectorId, commandPayload.csChargingProfiles); + logger.debug(`${this.chargingStation.logPrefix()} Charging profile set, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles); return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED; } @@ -179,6 +181,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } if (commandPayload.connectorId && !Utils.isEmptyArray(this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles)) { this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles = []; + logger.debug(`${this.chargingStation.logPrefix()} Charging profiles cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles); return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED; } if (!commandPayload.connectorId) { @@ -201,6 +204,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } if (clearCurrentCP) { this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles[index] = {} as OCPP16ChargingProfile; + logger.debug(`${this.chargingStation.logPrefix()} Charging profiles cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles); clearedCP = true; } }); @@ -256,6 +260,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer this.chargingStation.getConnector(transactionConnectorID).status = OCPP16ChargePointStatus.PREPARING; if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) { this.chargingStation.setChargingProfile(transactionConnectorID, commandPayload.chargingProfile); + logger.debug(`${this.chargingStation.logPrefix()} Charging profile set at start transaction, dump their stack: %j`, this.chargingStation.getConnector(transactionConnectorID).chargingProfiles); } else if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) { return Constants.OCPP_RESPONSE_REJECTED; } @@ -271,6 +276,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer this.chargingStation.getConnector(transactionConnectorID).status = OCPP16ChargePointStatus.PREPARING; if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) { this.chargingStation.setChargingProfile(transactionConnectorID, commandPayload.chargingProfile); + logger.debug(`${this.chargingStation.logPrefix()} Charging profile set at start transaction, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles); } else if (commandPayload.chargingProfile && commandPayload.chargingProfile.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) { return Constants.OCPP_RESPONSE_REJECTED; } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index d71af225..075ddaa4 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -117,7 +117,7 @@ export default class Configuration { } private static getConfigurationFileWatcher(): fs.FSWatcher { - return fs.watch(Configuration.configurationFilePath).on('change', async (e) => { + return fs.watch(Configuration.configurationFilePath).on('change', async (e): Promise => { // Nullify to force configuration file reading Configuration.configuration = null; await Bootstrap.getInstance().restart(); -- 2.34.1