+ this.requestHandler.bind(this);
+ this.sendResult.bind(this);
+ this.sendError.bind(this);
+ }
+
+ public static getInstance<T extends OCPPRequestService>(
+ this: new (chargingStation: ChargingStation, ocppResponseService: OCPPResponseService) => T,
+ chargingStation: ChargingStation,
+ ocppResponseService: OCPPResponseService
+ ): T {
+ if (!OCPPRequestService.instances.has(chargingStation.hashId)) {
+ OCPPRequestService.instances.set(
+ chargingStation.hashId,
+ new this(chargingStation, ocppResponseService)
+ );
+ }
+ return OCPPRequestService.instances.get(chargingStation.hashId) as T;
+ }
+
+ public async sendResult(
+ messageId: string,
+ messagePayload: JsonType,
+ commandName: IncomingRequestCommand
+ ): Promise<ResponseType> {
+ try {
+ // Send result message
+ return await this.internalSendMessage(
+ messageId,
+ messagePayload,
+ MessageType.CALL_RESULT_MESSAGE,
+ commandName
+ );
+ } catch (error) {
+ this.handleRequestError(commandName, error as Error);
+ }
+ }
+
+ public async sendError(
+ messageId: string,
+ ocppError: OCPPError,
+ commandName: RequestCommand | IncomingRequestCommand
+ ): Promise<ResponseType> {
+ try {
+ // Send error message
+ return await this.internalSendMessage(
+ messageId,
+ ocppError,
+ MessageType.CALL_ERROR_MESSAGE,
+ commandName
+ );
+ } catch (error) {
+ this.handleRequestError(commandName, error as Error);
+ }