From: Jérôme Benoit Date: Tue, 2 Feb 2021 08:10:19 +0000 (+0100) Subject: Move message buffer code to charging station. X-Git-Tag: v1.0.1-0~104^2~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3ba2381e6a5415267d9146fbac658a6c187ecb2b;p=e-mobility-charging-stations-simulator.git Move message buffer code to charging station. Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index efedd101..4f19f2d9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -319,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; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 89248822..6b19d061 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -55,19 +55,8 @@ export default abstract class OCPPRequestService { // Yes: Send Message this.chargingStation.wsConnection.send(messageToSend); } else if (commandName !== RequestCommand.BOOT_NOTIFICATION) { - let dups = false; - // Handle dups in buffer - for (const message of this.chargingStation.messageQueue) { - // Same message - if (messageToSend === message) { - dups = true; - break; - } - } - if (!dups) { - // Buffer message - this.chargingStation.messageQueue.push(messageToSend); - } + // Buffer it + this.chargingStation.addMessageToBuffer(messageToSend); // Reject it return rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `WebSocket closed for message id '${messageId}' with content '${messageToSend}', message buffered`, commandParams.details ? commandParams.details : {})); }