Add helper to get connector id for a transaction id
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index fc465b8c3e8ac784d025f44e7fa1cd146bc2995d..c4dc0cbf396fafc986ccf921712d125c6da7582b 100644 (file)
@@ -1,20 +1,10 @@
 import {
-  AuthorizeResponse,
-  StartTransactionResponse,
-  StopTransactionReason,
-  StopTransactionResponse,
-} from '../../types/ocpp/Transaction';
-import {
-  DiagnosticsStatus,
   IncomingRequestCommand,
   RequestCommand,
   ResponseType,
   SendParams,
 } from '../../types/ocpp/Requests';
 
-import { BootNotificationResponse } from '../../types/ocpp/Responses';
-import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode';
-import { ChargePointStatus } from '../../types/ocpp/ChargePointStatus';
 import type ChargingStation from '../ChargingStation';
 import Constants from '../../utils/Constants';
 import { EmptyObject } from '../../types/EmptyObject';
@@ -22,7 +12,6 @@ import { ErrorType } from '../../types/ocpp/ErrorType';
 import { HandleErrorParams } from '../../types/Error';
 import { JsonType } from '../../types/JsonType';
 import { MessageType } from '../../types/ocpp/MessageType';
-import { MeterValue } from '../../types/ocpp/MeterValues';
 import OCPPError from '../../exception/OCPPError';
 import type OCPPResponseService from './OCPPResponseService';
 import PerformanceStatistics from '../../performance/PerformanceStatistics';
@@ -44,6 +33,7 @@ export default abstract class OCPPRequestService {
   ) {
     this.chargingStation = chargingStation;
     this.ocppResponseService = ocppResponseService;
+    this.sendMessageHandler.bind(this);
   }
 
   public static getInstance<T extends OCPPRequestService>(
@@ -220,7 +210,6 @@ export default abstract class OCPPRequestService {
               resolve(payload);
             } catch (error) {
               reject(error);
-              throw error;
             } finally {
               self.chargingStation.requests.delete(messageId);
             }
@@ -326,58 +315,9 @@ export default abstract class OCPPRequestService {
     }
   }
 
-  public abstract sendHeartbeat(params?: SendParams): Promise<void>;
-  public abstract sendBootNotification(
-    chargePointModel: string,
-    chargePointVendor: string,
-    chargeBoxSerialNumber?: string,
-    firmwareVersion?: string,
-    chargePointSerialNumber?: string,
-    iccid?: string,
-    imsi?: string,
-    meterSerialNumber?: string,
-    meterType?: string,
+  public abstract sendMessageHandler(
+    commandName: RequestCommand,
+    commandParams?: JsonType,
     params?: SendParams
-  ): Promise<BootNotificationResponse>;
-
-  public abstract sendStatusNotification(
-    connectorId: number,
-    status: ChargePointStatus,
-    errorCode?: ChargePointErrorCode
-  ): Promise<void>;
-
-  public abstract sendAuthorize(connectorId: number, idTag?: string): Promise<AuthorizeResponse>;
-  public abstract sendStartTransaction(
-    connectorId: number,
-    idTag?: string
-  ): Promise<StartTransactionResponse>;
-
-  public abstract sendStopTransaction(
-    transactionId: number,
-    meterStop: number,
-    idTag?: string,
-    reason?: StopTransactionReason
-  ): Promise<StopTransactionResponse>;
-
-  public abstract sendMeterValues(
-    connectorId: number,
-    transactionId: number,
-    interval: number
-  ): Promise<void>;
-
-  public abstract sendTransactionBeginMeterValues(
-    connectorId: number,
-    transactionId: number,
-    beginMeterValue: MeterValue
-  ): Promise<void>;
-
-  public abstract sendTransactionEndMeterValues(
-    connectorId: number,
-    transactionId: number,
-    endMeterValue: MeterValue
-  ): Promise<void>;
-
-  public abstract sendDiagnosticsStatusNotification(
-    diagnosticsStatus: DiagnosticsStatus
-  ): Promise<void>;
+  ): Promise<ResponseType>;
 }