X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=70742ea8cb472e304df44beb7d95964bdc597fba;hb=dd119a6bc8a78464c82e4d11d88e0fdbbae10537;hp=a81974adf3ea527cbf34fdadd4ac28dfc8d054ad;hpb=77f00f84dff47dc35d2fca1afb3ca574dd3954b5;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index a81974ad..70742ea8 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,5 +1,5 @@ import { AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction'; -import { IncomingRequestCommand, Request, RequestCommand } from '../../types/ocpp/Requests'; +import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests'; import { BootNotificationResponse } from '../../types/ocpp/Responses'; import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode'; @@ -21,7 +21,7 @@ export default abstract class OCPPRequestService { this.ocppResponseService = ocppResponseService; } - public async sendMessage(messageId: string, commandParams: any, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE, commandName: RequestCommand | IncomingRequestCommand): Promise { + public async sendMessage(messageId: string, commandParams: any, messageType: MessageType, commandName: RequestCommand | IncomingRequestCommand): Promise { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; // Send a message through wsConnection @@ -32,7 +32,7 @@ export default abstract class OCPPRequestService { // Request case MessageType.CALL_MESSAGE: // Build request - this.chargingStation.requests[messageId] = [responseCallback, rejectCallback, commandParams] as Request; + this.chargingStation.requests[messageId] = [responseCallback, rejectCallback, commandParams as Record]; messageToSend = JSON.stringify([messageType, messageId, commandName, commandParams]); break; // Response @@ -49,7 +49,7 @@ export default abstract class OCPPRequestService { // Check if wsConnection opened and charging station registered if (this.chargingStation.isWebSocketOpen() && (this.chargingStation.isRegistered() || commandName === RequestCommand.BOOT_NOTIFICATION)) { if (this.chargingStation.getEnableStatistics()) { - this.chargingStation.statistics.addMessage(commandName, messageType); + this.chargingStation.performanceStatistics.addMessage(commandName, messageType); } // Yes: Send Message this.chargingStation.wsConnection.send(messageToSend); @@ -68,20 +68,29 @@ export default abstract class OCPPRequestService { setTimeout(() => rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `Timeout for message id '${messageId}' with content '${messageToSend}'`, commandParams.details ? commandParams.details : {})), Constants.OCPP_ERROR_TIMEOUT); } - // Function that will receive the request's response + /** + * Function that will receive the request's response + * + * @param {Record | string} payload + * @param {Record} requestPayload + */ async function responseCallback(payload: Record | string, requestPayload: Record): Promise { if (self.chargingStation.getEnableStatistics()) { - self.chargingStation.statistics.addMessage(commandName, messageType); + self.chargingStation.performanceStatistics.addMessage(commandName, MessageType.CALL_RESULT_MESSAGE); } // Send the response await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload); resolve(payload); } - // Function that will receive the request's rejection + /** + * Function that will receive the request's rejection + * + * @param {OCPPError} error + */ function rejectCallback(error: OCPPError): void { if (self.chargingStation.getEnableStatistics()) { - self.chargingStation.statistics.addMessage(commandName, messageType); + self.chargingStation.performanceStatistics.addMessage(commandName, MessageType.CALL_ERROR_MESSAGE); } logger.debug(`${self.chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams); // Build Exception