X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=411c452217e7e166bf77a47a1bf486836054616c;hb=b539f3735ff897f0261e6b17d68bd77b6eedf48d;hp=2d9e9a63ce2c2bf4bbca8cce9673f4b80ad229ba;hpb=c7db471811bca32168cbeb4287f06db112bfcd05;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 2d9e9a63..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; @@ -223,7 +224,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 +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[] {