X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=a81974adf3ea527cbf34fdadd4ac28dfc8d054ad;hb=e57acf6acb996f5fbc5790a2a4fc17248f8319db;hp=6b19d06186a4bfd8c4b82d40d6aaaf5afe526fd9;hpb=3ba2381e6a5415267d9146fbac658a6c187ecb2b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 6b19d061..a81974ad 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -24,7 +24,6 @@ export default abstract class OCPPRequestService { public async sendMessage(messageId: string, commandParams: any, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE, commandName: RequestCommand | IncomingRequestCommand): Promise { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; - const chargingStation = this.chargingStation; // Send a message through wsConnection return new Promise((resolve: (value?: any | PromiseLike) => void, reject: (reason?: any) => void) => { let messageToSend: string; @@ -56,7 +55,7 @@ export default abstract class OCPPRequestService { this.chargingStation.wsConnection.send(messageToSend); } else if (commandName !== RequestCommand.BOOT_NOTIFICATION) { // Buffer it - this.chargingStation.addMessageToBuffer(messageToSend); + this.chargingStation.addToMessageQueue(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 : {})); } @@ -71,8 +70,8 @@ export default abstract class OCPPRequestService { // Function that will receive the request's response async function responseCallback(payload: Record | string, requestPayload: Record): Promise { - if (chargingStation.getEnableStatistics()) { - chargingStation.statistics.addMessage(commandName, messageType); + if (self.chargingStation.getEnableStatistics()) { + self.chargingStation.statistics.addMessage(commandName, messageType); } // Send the response await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload); @@ -81,13 +80,13 @@ export default abstract class OCPPRequestService { // Function that will receive the request's rejection function rejectCallback(error: OCPPError): void { - if (chargingStation.getEnableStatistics()) { - chargingStation.statistics.addMessage(commandName, messageType); + if (self.chargingStation.getEnableStatistics()) { + self.chargingStation.statistics.addMessage(commandName, messageType); } - logger.debug(`${chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams); + logger.debug(`${self.chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams); // Build Exception // eslint-disable-next-line no-empty-function - chargingStation.requests[messageId] = [() => { }, () => { }, {}]; // Properly format the request + self.chargingStation.requests[messageId] = [() => { }, () => { }, {}]; // Send error reject(error); }