X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationUtils.ts;h=033fc4b36f79647746106169fe462834d241e463;hb=933e253b07b60f598e94a40cb817e334fb0f1995;hp=2a60bb41958c85048833a0b95b2b5b75370f40b4;hpb=4c3c0d59f56be4d58e906e938c00390b41e0ca7f;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 2a60bb41..033fc4b3 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -1,4 +1,5 @@ import crypto from 'node:crypto'; +import type EventEmitter from 'node:events'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -18,6 +19,7 @@ import { type ChargingSchedulePeriod, type ChargingStationInfo, type ChargingStationTemplate, + ChargingStationWorkerMessageEvents, ConnectorPhaseRotation, type ConnectorStatus, ConnectorStatusEnum, @@ -29,15 +31,7 @@ import { RecurrencyKindType, Voltage, } from '../types'; -import { - ACElectricUtils, - Configuration, - Constants, - DCElectricUtils, - Utils, - logger, -} from '../utils'; -import { WorkerProcessType } from '../worker'; +import { ACElectricUtils, Constants, DCElectricUtils, Utils, logger } from '../utils'; const moduleName = 'ChargingStationUtils'; @@ -153,7 +147,7 @@ export class ChargingStationUtils { return connectorBootStatus; } - public static checkTemplateFile( + public static checkTemplate( stationTemplate: ChargingStationTemplate, logPrefix: string, templateFile: string @@ -169,18 +163,18 @@ export class ChargingStationUtils { throw new BaseError(errorMsg); } if (Utils.isEmptyObject(stationTemplate.AutomaticTransactionGenerator)) { - stationTemplate.AutomaticTransactionGenerator = { - enable: false, - minDuration: 60, - maxDuration: 120, - minDelayBetweenTwoTransactions: 15, - maxDelayBetweenTwoTransactions: 30, - probabilityOfStart: 1, - stopAfterHours: 0.3, - stopOnConnectionFailure: true, - }; + stationTemplate.AutomaticTransactionGenerator = Constants.DEFAULT_ATG_CONFIGURATION; logger.warn( - `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default values` + `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default: %j`, + Constants.DEFAULT_ATG_CONFIGURATION + ); + } + if ( + Utils.isNullOrUndefined(stationTemplate.idTagsFile) || + Utils.isEmptyString(stationTemplate.idTagsFile) + ) { + logger.warn( + `${logPrefix} Missing id tags file in template file ${templateFile}. That can lead to issues with the Automatic Transaction Generator` ); } } @@ -351,16 +345,6 @@ export class ChargingStationUtils { } } - public static workerPoolInUse(): boolean { - return [WorkerProcessType.dynamicPool, WorkerProcessType.staticPool].includes( - Configuration.getWorker().processType - ); - } - - public static workerDynamicPoolInUse(): boolean { - return Configuration.getWorker().processType === WorkerProcessType.dynamicPool; - } - public static warnTemplateKeysDeprecation( stationTemplate: ChargingStationTemplate, logPrefix: string, @@ -550,13 +534,32 @@ export class ChargingStationUtils { return ( stationInfo.idTagsFile && path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'), + path.dirname(fileURLToPath(import.meta.url)), 'assets', path.basename(stationInfo.idTagsFile) ) ); } + public static waitForChargingStationEvents = async ( + emitter: EventEmitter, + event: ChargingStationWorkerMessageEvents, + eventsToWait: number + ): Promise => { + return new Promise((resolve) => { + let events = 0; + if (eventsToWait === 0) { + resolve(events); + } + emitter.on(event, () => { + ++events; + if (events === eventsToWait) { + resolve(events); + } + }); + }); + }; + private static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number { let configuredMaxConnectors: number; if (Utils.isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {