+ public static getInstance<T extends OCPPRequestService>(this: new (chargingStation: ChargingStation, ocppResponseService: OCPPResponseService) => T, chargingStation: ChargingStation, ocppResponseService: OCPPResponseService): T {
+ if (!OCPPRequestService.instances.has(chargingStation.id)) {
+ OCPPRequestService.instances.set(chargingStation.id, new this(chargingStation, ocppResponseService));
+ }
+ return OCPPRequestService.instances.get(chargingStation.id) 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: 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);
+ }
+ }
+
+ protected async sendMessage(messageId: string, messagePayload: JsonType, commandName: RequestCommand, params: SendParams = {
+ skipBufferingOnError: false,
+ triggerMessage: false
+ }): Promise<ResponseType> {
+ try {
+ return await this.internalSendMessage(messageId, messagePayload, MessageType.CALL_MESSAGE, commandName, params);
+ } catch (error) {
+ this.handleRequestError(commandName, error as Error, { throwError: false });
+ }
+ }
+
+ private async internalSendMessage(messageId: string, messagePayload: JsonType | OCPPError, messageType: MessageType, commandName?: RequestCommand | IncomingRequestCommand,