Convert sendDiagnosticsStatusNotification to OCPP message sending handler
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 8 Mar 2022 11:37:53 +0000 (12:37 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 8 Mar 2022 11:37:53 +0000 (12:37 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index a86e995efb477d53675da0a458e7d9e37ca32b84..bd9985048c3f9fdfa0679b96c677df0e8d674249 100644 (file)
@@ -829,8 +829,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
                 info.bytes / 1024
               } bytes transferred from diagnostics archive ${info.name}`
             );
-            await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
-              OCPP16DiagnosticsStatus.Uploading
+            await this.chargingStation.ocppRequestService.sendMessageHandler(
+              OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+              {
+                status: OCPP16DiagnosticsStatus.Uploading,
+              }
             );
           });
           uploadResponse = await ftpClient.uploadFrom(
@@ -838,8 +841,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
             uri.pathname + diagnosticsArchive
           );
           if (uploadResponse.code === 226) {
-            await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
-              OCPP16DiagnosticsStatus.Uploaded
+            await this.chargingStation.ocppRequestService.sendMessageHandler(
+              OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+              {
+                status: OCPP16DiagnosticsStatus.Uploaded,
+              }
             );
             if (ftpClient) {
               ftpClient.close();
@@ -862,8 +868,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
         );
       } catch (error) {
-        await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
-          OCPP16DiagnosticsStatus.UploadFailed
+        await this.chargingStation.ocppRequestService.sendMessageHandler(
+          OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+          {
+            status: OCPP16DiagnosticsStatus.UploadFailed,
+          }
         );
         if (ftpClient) {
           ftpClient.close();
@@ -880,8 +889,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           uri.protocol
         } to transfer the diagnostic logs archive`
       );
-      await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
-        OCPP16DiagnosticsStatus.UploadFailed
+      await this.chargingStation.ocppRequestService.sendMessageHandler(
+        OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+        {
+          status: OCPP16DiagnosticsStatus.UploadFailed,
+        }
       );
       return Constants.OCPP_RESPONSE_EMPTY;
     }
index 8ba3c08617427baaab8538405a78e0b4de517c0f..f184c7ab24bc8c7b21bfc553b9298f39003df7fc 100644 (file)
@@ -12,13 +12,13 @@ import {
   OCPP16RequestCommand,
   StatusNotificationRequest,
 } from '../../../types/ocpp/1.6/Requests';
-import { MeterValuesRequest, OCPP16MeterValue } from '../../../types/ocpp/1.6/MeterValues';
 import { ResponseType, SendParams } from '../../../types/ocpp/Requests';
 
 import type ChargingStation from '../../ChargingStation';
 import Constants from '../../../utils/Constants';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
 import { JsonType } from '../../../types/JsonType';
+import { MeterValuesRequest } from '../../../types/ocpp/1.6/MeterValues';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 import OCPPError from '../../../exception/OCPPError';
@@ -57,19 +57,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
     );
   }
 
-  public async sendDiagnosticsStatusNotification(
-    diagnosticsStatus: OCPP16DiagnosticsStatus
-  ): Promise<void> {
-    const payload: DiagnosticsStatusNotificationRequest = {
-      status: diagnosticsStatus,
-    };
-    await this.sendMessage(
-      Utils.generateUUID(),
-      payload,
-      OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
-    );
-  }
-
   private buildCommandPayload(
     commandName: OCPP16RequestCommand,
     commandParams?: JsonType
index 1430de0701cf5bcb356b484adc8581c812ec7725..e5047d33e2ec8d05a1a6021b6d921d5df0cded17 100644 (file)
@@ -13,7 +13,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';
@@ -323,8 +322,4 @@ export default abstract class OCPPRequestService {
     commandParams?: JsonType,
     params?: SendParams
   ): Promise<ResponseType>;
-
-  public abstract sendDiagnosticsStatusNotification(
-    diagnosticsStatus: DiagnosticsStatus
-  ): Promise<void>;
 }