X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=0c39613beefea49afdb1a3701457daba98fa12ee;hb=77f00f84dff47dc35d2fca1afb3ca574dd3954b5;hp=4f19f2d9581c810fbb1a25a7e2609d32381a08a3;hpb=3ba2381e6a5415267d9146fbac658a6c187ecb2b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 4f19f2d9..0c39613b 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -223,7 +223,7 @@ export default class ChargingStation { } }, interval); } else { - logger.error(`${this.logPrefix()} Charging station ${StandardParametersKey.MeterValueSampleInterval} configuration set to ${Utils.milliSecondsToHHMMSS(interval)}, not sending MeterValues`); + logger.error(`${this.logPrefix()} Charging station ${StandardParametersKey.MeterValueSampleInterval} configuration set to ${interval ? Utils.milliSecondsToHHMMSS(interval) : interval}, not sending MeterValues`); } } @@ -319,7 +319,7 @@ export default class ChargingStation { } } - public addMessageToBuffer(message: string): void { + public addToMessageQueue(message: string): void { let dups = false; // Handle dups in buffer for (const bufferedMessage of this.messageQueue) { @@ -335,6 +335,15 @@ export default class ChargingStation { } } + private flushMessageQueue() { + if (!Utils.isEmptyArray(this.messageQueue)) { + this.messageQueue.forEach((message, index) => { + this.messageQueue.splice(index, 1); + this.wsConnection.send(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; @@ -476,16 +485,12 @@ 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)); - } else if (this.isRegistered()) { + } + 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) => { - this.messageQueue.splice(index, 1); - this.wsConnection.send(message); - }); - } + this.flushMessageQueue(); } } else { logger.error(`${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`);