log raw socket messages
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index 4ab79d9d2bdb400cbbad9dca3f2befb7d93505b5..9dd0e7bf9c8fdd5744d824846d190ced6e6d5247 100644 (file)
@@ -16,6 +16,7 @@ import OCPPError from '../../exception/OCPPError';
 import type OCPPResponseService from './OCPPResponseService';
 import PerformanceStatistics from '../../performance/PerformanceStatistics';
 import Utils from '../../utils/Utils';
+import chalk from 'chalk';
 import logger from '../../utils/Logger';
 
 export default abstract class OCPPRequestService {
@@ -34,6 +35,8 @@ export default abstract class OCPPRequestService {
     this.chargingStation = chargingStation;
     this.ocppResponseService = ocppResponseService;
     this.sendMessageHandler.bind(this);
+    this.sendResult.bind(this);
+    this.sendError.bind(this);
   }
 
   public static getInstance<T extends OCPPRequestService>(
@@ -149,6 +152,7 @@ export default abstract class OCPPRequestService {
           if (this.chargingStation.isWebSocketConnectionOpened()) {
             // Yes: Send Message
             const beginId = PerformanceStatistics.beginMeasure(commandName);
+            console.log(chalk`{blue >> Sending message = ${messageToSend}}`);
             // FIXME: Handle sending error
             this.chargingStation.wsConnection.send(messageToSend);
             PerformanceStatistics.endMeasure(commandName, beginId);
@@ -315,9 +319,9 @@ export default abstract class OCPPRequestService {
     }
   }
 
-  public abstract sendMessageHandler(
+  public abstract sendMessageHandler<Response extends JsonType>(
     commandName: RequestCommand,
     commandParams?: JsonType,
     params?: SendParams
-  ): Promise<ResponseType>;
+  ): Promise<Response>;
 }