Convert sendBootNotification to OCPP message sending handler
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Mar 2022 21:22:30 +0000 (22:22 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 7 Mar 2022 21:22:30 +0000 (22:22 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index a71d56d9d56f373e149ba29ebb0106e9e29b83d4..9297b3e838ada19afbe86760aca65e050a3942e0 100644 (file)
@@ -937,12 +937,16 @@ export default class ChargingStation {
       // Send BootNotification
       let registrationRetryCount = 0;
       do {
-        this.bootNotificationResponse = await this.ocppRequestService.sendBootNotification(
-          this.bootNotificationRequest.chargePointModel,
-          this.bootNotificationRequest.chargePointVendor,
-          this.bootNotificationRequest.chargeBoxSerialNumber,
-          this.bootNotificationRequest.firmwareVersion
-        );
+        this.bootNotificationResponse = (await this.ocppRequestService.sendMessageHandler(
+          RequestCommand.BOOT_NOTIFICATION,
+          {
+            chargePointModel: this.bootNotificationRequest.chargePointModel,
+            chargePointVendor: this.bootNotificationRequest.chargePointVendor,
+            chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
+            firmwareVersion: this.bootNotificationRequest.firmwareVersion,
+          },
+          { skipBufferingOnError: true }
+        )) as BootNotificationResponse;
         if (!this.isInAcceptedState()) {
           this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
           await Utils.sleep(
@@ -1237,11 +1241,15 @@ export default class ChargingStation {
 
   private async startMessageSequence(): Promise<void> {
     if (this.stationInfo.autoRegister) {
-      await this.ocppRequestService.sendBootNotification(
-        this.bootNotificationRequest.chargePointModel,
-        this.bootNotificationRequest.chargePointVendor,
-        this.bootNotificationRequest.chargeBoxSerialNumber,
-        this.bootNotificationRequest.firmwareVersion
+      await this.ocppRequestService.sendMessageHandler(
+        RequestCommand.BOOT_NOTIFICATION,
+        {
+          chargePointModel: this.bootNotificationRequest.chargePointModel,
+          chargePointVendor: this.bootNotificationRequest.chargePointVendor,
+          chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
+          firmwareVersion: this.bootNotificationRequest.firmwareVersion,
+        },
+        { skipBufferingOnError: true }
       );
     }
     // Start WebSocket ping
index f8ca8de69745192c0baefea62b68ba38ba804507..a7dae0c5b95eeed06843dad5f71afcdda0721f6b 100644 (file)
@@ -811,17 +811,26 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         case MessageTrigger.BootNotification:
           setTimeout(() => {
             this.chargingStation.ocppRequestService
-              .sendBootNotification(
-                this.chargingStation.getBootNotificationRequest().chargePointModel,
-                this.chargingStation.getBootNotificationRequest().chargePointVendor,
-                this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber,
-                this.chargingStation.getBootNotificationRequest().firmwareVersion,
-                this.chargingStation.getBootNotificationRequest().chargePointSerialNumber,
-                this.chargingStation.getBootNotificationRequest().iccid,
-                this.chargingStation.getBootNotificationRequest().imsi,
-                this.chargingStation.getBootNotificationRequest().meterSerialNumber,
-                this.chargingStation.getBootNotificationRequest().meterType,
-                { triggerMessage: true }
+              .sendMessageHandler(
+                OCPP16RequestCommand.BOOT_NOTIFICATION,
+                {
+                  chargePointModel:
+                    this.chargingStation.getBootNotificationRequest().chargePointModel,
+                  chargePointVendor:
+                    this.chargingStation.getBootNotificationRequest().chargePointVendor,
+                  chargeBoxSerialNumber:
+                    this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber,
+                  firmwareVersion:
+                    this.chargingStation.getBootNotificationRequest().firmwareVersion,
+                  chargePointSerialNumber:
+                    this.chargingStation.getBootNotificationRequest().chargePointSerialNumber,
+                  iccid: this.chargingStation.getBootNotificationRequest().iccid,
+                  imsi: this.chargingStation.getBootNotificationRequest().imsi,
+                  meterSerialNumber:
+                    this.chargingStation.getBootNotificationRequest().meterSerialNumber,
+                  meterType: this.chargingStation.getBootNotificationRequest().meterType,
+                },
+                { skipBufferingOnError: true, triggerMessage: true }
               )
               .catch(() => {
                 /* This is intentional */
index 27ba76ec10f626e9f1154c40a56c2b7560e9a4b0..e7fa7751eb88f39e2e0533c5a6b5a8427932ca3d 100644 (file)
@@ -23,7 +23,6 @@ import type ChargingStation from '../../ChargingStation';
 import Constants from '../../../utils/Constants';
 import { ErrorType } from '../../../types/ocpp/ErrorType';
 import { JsonType } from '../../../types/JsonType';
-import { OCPP16BootNotificationResponse } from '../../../types/ocpp/1.6/Responses';
 import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
 import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
 import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
@@ -64,37 +63,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
     );
   }
 
-  public async sendBootNotification(
-    chargePointModel: string,
-    chargePointVendor: string,
-    chargeBoxSerialNumber?: string,
-    firmwareVersion?: string,
-    chargePointSerialNumber?: string,
-    iccid?: string,
-    imsi?: string,
-    meterSerialNumber?: string,
-    meterType?: string,
-    params?: SendParams
-  ): Promise<OCPP16BootNotificationResponse> {
-    const payload: OCPP16BootNotificationRequest = {
-      chargePointModel,
-      chargePointVendor,
-      ...(!Utils.isUndefined(chargeBoxSerialNumber) && { chargeBoxSerialNumber }),
-      ...(!Utils.isUndefined(chargePointSerialNumber) && { chargePointSerialNumber }),
-      ...(!Utils.isUndefined(firmwareVersion) && { firmwareVersion }),
-      ...(!Utils.isUndefined(iccid) && { iccid }),
-      ...(!Utils.isUndefined(imsi) && { imsi }),
-      ...(!Utils.isUndefined(meterSerialNumber) && { meterSerialNumber }),
-      ...(!Utils.isUndefined(meterType) && { meterType }),
-    };
-    return (await this.sendMessage(
-      Utils.generateUUID(),
-      payload,
-      OCPP16RequestCommand.BOOT_NOTIFICATION,
-      { ...params, skipBufferingOnError: true }
-    )) as OCPP16BootNotificationResponse;
-  }
-
   public async sendStatusNotification(
     connectorId: number,
     status: OCPP16ChargePointStatus,
index 90af961e0851c997cac548539f26aa61339ce095..73fc4bf15a6de2935974f15bc3994a64752bcaa7 100644 (file)
@@ -333,19 +333,6 @@ export default abstract class OCPPRequestService {
     params?: SendParams
   ): Promise<ResponseType>;
 
-  public abstract sendBootNotification(
-    chargePointModel: string,
-    chargePointVendor: string,
-    chargeBoxSerialNumber?: string,
-    firmwareVersion?: string,
-    chargePointSerialNumber?: string,
-    iccid?: string,
-    imsi?: string,
-    meterSerialNumber?: string,
-    meterType?: string,
-    params?: SendParams
-  ): Promise<BootNotificationResponse>;
-
   public abstract sendStatusNotification(
     connectorId: number,
     status: ChargePointStatus,