Add debug log for CPs.
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 1 Feb 2021 01:29:32 +0000 (02:29 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 1 Feb 2021 01:29:32 +0000 (02:29 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts
src/utils/Configuration.ts

index 929927541d502d7670ce57000c1eb76e821d39dc..90dff98bd09dfc9b69ade8466ed04d4158670426 100644 (file)
@@ -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<void> => {
         await this.stop();
       }, this.chargingStation.stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600 * 1000);
index c532eea01dc72b2a008862a61d98164ebfdbda43..a19ad3b4948c827223bb4472714e1b1aa4bf407b 100644 (file)
@@ -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<void> => {
         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<void> => {
         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<void> => {
       try {
         logger.debug(this.logPrefix() + ' Template file ' + this.stationTemplateFile + ' have changed, reload');
index f94f410b948a6ef335ca61cdf01f89adec82c084..a63a28e4b875e0d0c97bc05f6b3c2152891dcc13 100644 (file)
@@ -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<void> => {
       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;
       }
index d71af225afec4539344c45da6a3af47604a51219..075ddaa478cb152c4104c7a2d9c93fac864acecb 100644 (file)
@@ -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<void> => {
       // Nullify to force configuration file reading
       Configuration.configuration = null;
       await Bootstrap.getInstance().restart();