X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=4f19f2d9581c810fbb1a25a7e2609d32381a08a3;hb=3ba2381e6a5415267d9146fbac658a6c187ecb2b;hp=bc7f63f9e43e0a6f8524abab29eb32bb8ed424aa;hpb=c0560973d259dbce64a24d10bab46246596fa1d5;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index bc7f63f9..4f19f2d9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1,4 +1,4 @@ -import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/RequestResponses'; +import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses'; import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration'; import ChargingStationTemplate, { PowerOutType, VoltageOut } from '../types/ChargingStationTemplate'; import Connectors, { Connector } from '../types/Connectors'; @@ -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({ @@ -317,6 +319,22 @@ export default class ChargingStation { } } + public addMessageToBuffer(message: string): void { + let dups = false; + // Handle dups in buffer + for (const bufferedMessage of this.messageQueue) { + // Same message + if (message === bufferedMessage) { + dups = true; + break; + } + } + if (!dups) { + // Buffer message + this.messageQueue.push(message); + } + } + private getChargingStationId(stationTemplate: ChargingStationTemplate): string { // In case of multiple instances: add instance index to charging station id let instanceIndex = process.env.CF_INSTANCE_INDEX ? process.env.CF_INSTANCE_INDEX : 0; @@ -458,9 +476,9 @@ export default class ChargingStation { await Utils.sleep(this.bootNotificationResponse?.interval ? this.bootNotificationResponse.interval * 1000 : Constants.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL); } } while (!this.isRegistered() && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1)); - } - if (this.isRegistered()) { + } else if (this.isRegistered()) { await this.startMessageSequence(); + this.hasStopped && (this.hasStopped = false); if (this.hasSocketRestarted && this.isWebSocketOpen()) { if (!Utils.isEmptyArray(this.messageQueue)) { this.messageQueue.forEach((message, index) => { @@ -703,7 +721,7 @@ export default class ChargingStation { this.automaticTransactionGeneration = new AutomaticTransactionGenerator(this); } if (this.automaticTransactionGeneration.timeToStop) { - this.automaticTransactionGeneration.start(); + await this.automaticTransactionGeneration.start(); } } if (this.getEnableStatistics()) { @@ -823,7 +841,8 @@ export default class ChargingStation { } private startStationTemplateFileMonitoring(): void { - fs.watch(this.stationTemplateFile).on('change', (e) => { + // 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'); // Initialize @@ -831,7 +850,7 @@ export default class ChargingStation { // Stop the ATG if (!this.stationInfo.AutomaticTransactionGenerator.enable && this.automaticTransactionGeneration) { - this.automaticTransactionGeneration.stop().catch(() => { }); + await this.automaticTransactionGeneration.stop(); } // Start the ATG if (this.stationInfo.AutomaticTransactionGenerator.enable) { @@ -839,7 +858,7 @@ export default class ChargingStation { this.automaticTransactionGeneration = new AutomaticTransactionGenerator(this); } if (this.automaticTransactionGeneration.timeToStop) { - this.automaticTransactionGeneration.start(); + await this.automaticTransactionGeneration.start(); } } // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed