From: Jérôme Benoit Date: Mon, 1 Feb 2021 08:13:24 +0000 (+0100) Subject: Cleanups: log msg refinements, ... X-Git-Tag: v1.0.1-0~105^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a4cc42ea02111459495c70c60554f5ffa8e9722a;p=e-mobility-charging-stations-simulator.git Cleanups: log msg refinements, ... Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 90dff98b..763533ed 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -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, diff --git a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts index a63a28e4..38bd3c06 100644 --- a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts @@ -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; } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 075ddaa4..6d1f7ccf 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -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 => { // Nullify to force configuration file reading Configuration.configuration = null; diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index c3de59e7..31a67328 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -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';