X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=411c452217e7e166bf77a47a1bf486836054616c;hb=f4754f5b40d2bc5e18a0bd0bc7e12e6500060a2d;hp=a19ad3b4948c827223bb4472714e1b1aa4bf407b;hpb=7162326761291e5683f7a6e08b7845ea37e35a07;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index a19ad3b4..411c4522 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'; @@ -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,6 +320,31 @@ export default class ChargingStation { } } + public addToMessageQueue(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 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; @@ -465,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()})`); @@ -578,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[] {