Cleanups: log msg refinements, ...
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 1 Feb 2021 08:13:24 +0000 (09:13 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 1 Feb 2021 08:13:24 +0000 (09:13 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts
src/utils/Configuration.ts
src/utils/Constants.ts

index 90dff98bd09dfc9b69ade8466ed04d4158670426..763533ed82e12269cb56183708bf0ae7720ab6a0 100644 (file)
@@ -74,7 +74,7 @@ export default class AutomaticTransactionGenerator {
       if (!this.chargingStation?.ocppRequestService) {
         logger.info(`${this.logPrefix(connectorId)} Transaction loop waiting for charging station service to be initialized`);
         do {
-          await Utils.sleep(500);
+          await Utils.sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
         } while (!this.chargingStation?.ocppRequestService);
       }
       const wait = Utils.getRandomInt(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransactions,
index a63a28e4b875e0d0c97bc05f6b3c2152891dcc13..38bd3c0621b1c16b243e597a7d87a7f82ea2ecee 100644 (file)
@@ -25,7 +25,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       } catch (error) {
         // Log
         logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error);
-        // Send back response to inform backend
+        // Send back an error response to inform backend
         await this.chargingStation.ocppRequestService.sendError(messageId, error, commandName);
         throw error;
       }
@@ -160,7 +160,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
 
   private handleRequestSetChargingProfile(commandPayload: SetChargingProfileRequest): SetChargingProfileResponse {
     if (!this.chargingStation.getConnector(commandPayload.connectorId)) {
-      logger.error(`${this.chargingStation.logPrefix()} Trying to set a charging profile to a non existing connector Id ${commandPayload.connectorId}`);
+      logger.error(`${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
       return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
     }
     if (commandPayload.csChargingProfiles.chargingProfilePurpose === ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE && commandPayload.connectorId !== 0) {
@@ -170,18 +170,18 @@ 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);
+    logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
     return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
   }
 
   private handleRequestClearChargingProfile(commandPayload: ClearChargingProfileRequest): ClearChargingProfileResponse {
     if (!this.chargingStation.getConnector(commandPayload.connectorId)) {
-      logger.error(`${this.chargingStation.logPrefix()} Trying to clear a charging profile to a non existing connector Id ${commandPayload.connectorId}`);
+      logger.error(`${this.chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
       return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
     }
     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);
+      logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
       return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
     }
     if (!commandPayload.connectorId) {
@@ -204,7 +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);
+              logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
               clearedCP = true;
             }
           });
@@ -260,7 +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);
+            logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) 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;
           }
@@ -276,7 +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);
+        logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) 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 075ddaa478cb152c4104c7a2d9c93fac864acecb..6d1f7ccfd06ee85df55e8d2fccfeb5f33c18c9c7 100644 (file)
@@ -117,6 +117,7 @@ export default class Configuration {
   }
 
   private static getConfigurationFileWatcher(): fs.FSWatcher {
+    // eslint-disable-next-line @typescript-eslint/no-misused-promises
     return fs.watch(Configuration.configurationFilePath).on('change', async (e): Promise<void> => {
       // Nullify to force configuration file reading
       Configuration.configuration = null;
index c3de59e70271a8654cf0457c63d900bdb713cc32..31a673281c8b9a43a2d37b405b611ce0a2c04588 100644 (file)
@@ -27,6 +27,7 @@ export default class Constants {
 
   static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms
   static readonly CHARGING_STATION_ATG_WAIT_TIME = 2000; // Ms
+  static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms
 
   static readonly TRANSACTION_DEFAULT_TAGID = '00000000';