X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FChargingStation.ts;h=411c452217e7e166bf77a47a1bf486836054616c;hb=b539f3735ff897f0261e6b17d68bd77b6eedf48d;hp=f60fc79ecdd5d98f4f6d5ccb4399a6f9897af45c;hpb=eb87fe879ce448deb447b8fdd453dac8eb33b8e1;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index f60fc79e..411c4522 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -29,6 +29,7 @@ import { WebSocketCloseEventStatusCode } from '../types/WebSocket'; import crypto from 'crypto'; import fs from 'fs'; import logger from '../utils/Logger'; +import path from 'path'; export default class ChargingStation { public stationTemplateFile: string; @@ -319,7 +320,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 +336,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; @@ -481,12 +491,7 @@ export default class ChargingStation { 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()})`); @@ -594,7 +599,7 @@ export default class ChargingStation { } private getAuthorizationFile(): string { - return this.stationInfo.authorizationFile && this.stationInfo.authorizationFile; + return this.stationInfo.authorizationFile && path.join(path.resolve(__dirname, '../'), 'assets', path.basename(this.stationInfo.authorizationFile)); } private getAuthorizedTags(): string[] {