X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=a50500dc24047f7a7eb3276a03d725cedf69fb44;hb=d5575b174bef0e79d2a600ae24be2789d6cf3451;hp=e00e954c9bfebe5be9e6dd7c6200182559248d90;hpb=e8a92d57004dcddba34fa4a510226b56e11a8cdb;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index e00e954c..a50500dc 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,7 +1,7 @@ import Ajv, { type JSONSchemaType } from 'ajv'; import ajvFormats from 'ajv-formats'; -import { type OCPPResponseService, OCPPServiceUtils } from './internal'; +import { OCPPConstants, type OCPPResponseService, OCPPServiceUtils } from './internal'; import type { ChargingStation } from '../../charging-station'; import { OCPPError } from '../../exception'; import { PerformanceStatistics } from '../../performance'; @@ -42,14 +42,63 @@ export abstract class OCPPRequestService { }); ajvFormats(this.ajv); this.ocppResponseService = ocppResponseService; - this.requestHandler.bind(this); - this.sendMessage.bind(this); - this.sendResponse.bind(this); - this.sendError.bind(this); - this.internalSendMessage.bind(this); - this.buildMessageToSend.bind(this); - this.validateRequestPayload.bind(this); - this.validateIncomingRequestResponsePayload.bind(this); + this.requestHandler = this.requestHandler.bind(this) as < + ReqType extends JsonType, + ResType extends JsonType + >( + chargingStation: ChargingStation, + commandName: RequestCommand, + commandParams?: JsonType, + params?: RequestParams + ) => Promise; + this.sendMessage = this.sendMessage.bind(this) as ( + chargingStation: ChargingStation, + messageId: string, + messagePayload: JsonType, + commandName: RequestCommand, + params?: RequestParams + ) => Promise; + this.sendResponse = this.sendResponse.bind(this) as ( + chargingStation: ChargingStation, + messageId: string, + messagePayload: JsonType, + commandName: IncomingRequestCommand + ) => Promise; + this.sendError = this.sendError.bind(this) as ( + chargingStation: ChargingStation, + messageId: string, + ocppError: OCPPError, + commandName: RequestCommand | IncomingRequestCommand + ) => Promise; + this.internalSendMessage = this.internalSendMessage.bind(this) as ( + chargingStation: ChargingStation, + messageId: string, + messagePayload: JsonType | OCPPError, + messageType: MessageType, + commandName: RequestCommand | IncomingRequestCommand, + params?: RequestParams + ) => Promise; + this.buildMessageToSend = this.buildMessageToSend.bind(this) as ( + chargingStation: ChargingStation, + messageId: string, + messagePayload: JsonType | OCPPError, + messageType: MessageType, + commandName: RequestCommand | IncomingRequestCommand, + responseCallback: ResponseCallback, + errorCallback: ErrorCallback + ) => string; + this.validateRequestPayload = this.validateRequestPayload.bind(this) as ( + chargingStation: ChargingStation, + commandName: RequestCommand | IncomingRequestCommand, + payload: T + ) => boolean; + this.validateIncomingRequestResponsePayload = this.validateIncomingRequestResponsePayload.bind( + this + ) as ( + chargingStation: ChargingStation, + commandName: RequestCommand | IncomingRequestCommand, + payload: T + ) => boolean; } public static getInstance( @@ -353,7 +402,7 @@ export abstract class OCPPRequestService { return resolve(messagePayload); } }), - Constants.OCPP_WEBSOCKET_TIMEOUT, + OCPPConstants.OCPP_WEBSOCKET_TIMEOUT, new OCPPError( ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}'`,