UI Protocol: add boot notification command support
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Sep 2022 21:47:04 +0000 (23:47 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Sep 2022 21:47:04 +0000 (23:47 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/charging-station/ui-server/ui-services/UIService001.ts
src/types/UIProtocol.ts
src/types/WorkerBroadcastChannel.ts

index d7b67e6a04b73aa960abc5767dec9338ea0038ee..bbb5c6f290a39503092b9537e27b9a2ac8535123 100644 (file)
@@ -1341,22 +1341,9 @@ export default class ChargingStation {
           this.bootNotificationResponse = await this.ocppRequestService.requestHandler<
             BootNotificationRequest,
             BootNotificationResponse
-          >(
-            this,
-            RequestCommand.BOOT_NOTIFICATION,
-            {
-              chargePointModel: this.bootNotificationRequest.chargePointModel,
-              chargePointVendor: this.bootNotificationRequest.chargePointVendor,
-              chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
-              firmwareVersion: this.bootNotificationRequest.firmwareVersion,
-              chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
-              iccid: this.bootNotificationRequest.iccid,
-              imsi: this.bootNotificationRequest.imsi,
-              meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
-              meterType: this.bootNotificationRequest.meterType,
-            },
-            { skipBufferingOnError: true }
-          );
+          >(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, {
+            skipBufferingOnError: true,
+          });
           if (!this.isRegistered()) {
             this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
             await Utils.sleep(
@@ -1756,22 +1743,9 @@ export default class ChargingStation {
       await this.ocppRequestService.requestHandler<
         BootNotificationRequest,
         BootNotificationResponse
-      >(
-        this,
-        RequestCommand.BOOT_NOTIFICATION,
-        {
-          chargePointModel: this.bootNotificationRequest.chargePointModel,
-          chargePointVendor: this.bootNotificationRequest.chargePointVendor,
-          chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
-          firmwareVersion: this.bootNotificationRequest.firmwareVersion,
-          chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
-          iccid: this.bootNotificationRequest.iccid,
-          imsi: this.bootNotificationRequest.imsi,
-          meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
-          meterType: this.bootNotificationRequest.meterType,
-        },
-        { skipBufferingOnError: true }
-      );
+      >(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, {
+        skipBufferingOnError: true,
+      });
     }
     // Start WebSocket ping
     this.startWebSocketPing();
index 4f6719667075cfa094ca0ef9608fef05dc9a220a..31afa58ecf2aeb6893dde3a13363c633997ad6ac 100644 (file)
@@ -2,31 +2,34 @@ import BaseError from '../exception/BaseError';
 import type OCPPError from '../exception/OCPPError';
 import { StandardParametersKey } from '../types/ocpp/Configuration';
 import {
-  HeartbeatRequest,
-  MeterValuesRequest,
+  type BootNotificationRequest,
+  type HeartbeatRequest,
+  type MeterValuesRequest,
   RequestCommand,
   type StatusNotificationRequest,
 } from '../types/ocpp/Requests';
-import type {
-  HeartbeatResponse,
-  MeterValuesResponse,
-  StatusNotificationResponse,
+import {
+  type BootNotificationResponse,
+  type HeartbeatResponse,
+  type MeterValuesResponse,
+  RegistrationStatus,
+  type StatusNotificationResponse,
 } from '../types/ocpp/Responses';
 import {
   AuthorizationStatus,
-  AuthorizeRequest,
-  AuthorizeResponse,
-  StartTransactionRequest,
-  StartTransactionResponse,
-  StopTransactionRequest,
-  StopTransactionResponse,
+  type AuthorizeRequest,
+  type AuthorizeResponse,
+  type StartTransactionRequest,
+  type StartTransactionResponse,
+  type StopTransactionRequest,
+  type StopTransactionResponse,
 } from '../types/ocpp/Transaction';
 import {
   BroadcastChannelProcedureName,
-  BroadcastChannelRequest,
-  BroadcastChannelRequestPayload,
-  BroadcastChannelResponsePayload,
-  MessageEvent,
+  type BroadcastChannelRequest,
+  type BroadcastChannelRequestPayload,
+  type BroadcastChannelResponsePayload,
+  type MessageEvent,
 } from '../types/WorkerBroadcastChannel';
 import { ResponseStatus } from '../ui/web/src/types/UIProtocol';
 import Constants from '../utils/Constants';
@@ -43,6 +46,7 @@ type CommandResponse =
   | StartTransactionResponse
   | StopTransactionResponse
   | AuthorizeResponse
+  | BootNotificationResponse
   | StatusNotificationResponse
   | HeartbeatResponse
   | MeterValuesResponse;
@@ -96,13 +100,13 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
             StopTransactionRequest,
             StartTransactionResponse
           >(this.chargingStation, RequestCommand.STOP_TRANSACTION, {
-            ...requestPayload,
             meterStop:
               requestPayload.meterStop ??
               this.chargingStation.getEnergyActiveImportRegisterByTransactionId(
                 requestPayload.transactionId,
                 true
               ),
+            ...requestPayload,
           }),
       ],
       [
@@ -113,6 +117,27 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
             AuthorizeResponse
           >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload),
       ],
+      [
+        BroadcastChannelProcedureName.BOOT_NOTIFICATION,
+        async (requestPayload?: BroadcastChannelRequestPayload) => {
+          this.chargingStation.bootNotificationResponse =
+            await this.chargingStation.ocppRequestService.requestHandler<
+              BootNotificationRequest,
+              BootNotificationResponse
+            >(
+              this.chargingStation,
+              RequestCommand.BOOT_NOTIFICATION,
+              {
+                ...this.chargingStation.bootNotificationRequest,
+                ...requestPayload,
+              },
+              {
+                skipBufferingOnError: true,
+              }
+            );
+          return this.chargingStation.bootNotificationResponse;
+        },
+      ],
       [
         BroadcastChannelProcedureName.STATUS_NOTIFICATION,
         async (requestPayload?: BroadcastChannelRequestPayload) =>
@@ -141,8 +166,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
             MeterValuesRequest,
             MeterValuesResponse
           >(this.chargingStation, RequestCommand.METER_VALUES, {
-            ...requestPayload,
-            meterValue: requestPayload.meterValue ?? [
+            meterValue: [
               OCPP16ServiceUtils.buildMeterValue(
                 this.chargingStation,
                 requestPayload.connectorId,
@@ -152,6 +176,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
                   : Constants.DEFAULT_METER_VALUES_INTERVAL
               ),
             ],
+            ...requestPayload,
           });
         },
       ],
@@ -288,6 +313,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           return ResponseStatus.SUCCESS;
         }
         return ResponseStatus.FAILURE;
+      case BroadcastChannelProcedureName.BOOT_NOTIFICATION:
+        if (commandResponse?.status === RegistrationStatus.ACCEPTED) {
+          return ResponseStatus.SUCCESS;
+        }
+        return ResponseStatus.FAILURE;
       case BroadcastChannelProcedureName.STATUS_NOTIFICATION:
       case BroadcastChannelProcedureName.METER_VALUES:
         if (Utils.isEmptyObject(commandResponse) === true) {
index 76de2cdfea6fc617e6a2b10e4a3de54b10404c6e..5139b678c2d47ea168c495a3afbf264f7a62d517 100644 (file)
@@ -1,4 +1,4 @@
-import { ResponsePayload, ResponseStatus } from '../types/UIProtocol';
+import { type ResponsePayload, ResponseStatus } from '../types/UIProtocol';
 import type {
   BroadcastChannelResponse,
   BroadcastChannelResponsePayload,
index ce2f1d2b3ec1b12b1469504ed77f1e54c1e1d8b4..f951fc77145cceda22e15f77b0f873da8a901e12 100644 (file)
@@ -1116,23 +1116,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               .requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
                 chargingStation,
                 OCPP16RequestCommand.BOOT_NOTIFICATION,
-                {
-                  chargePointModel: chargingStation.bootNotificationRequest.chargePointModel,
-                  chargePointVendor: chargingStation.bootNotificationRequest.chargePointVendor,
-                  chargeBoxSerialNumber:
-                    chargingStation.bootNotificationRequest.chargeBoxSerialNumber,
-                  firmwareVersion: chargingStation.bootNotificationRequest.firmwareVersion,
-                  chargePointSerialNumber:
-                    chargingStation.bootNotificationRequest.chargePointSerialNumber,
-                  iccid: chargingStation.bootNotificationRequest.iccid,
-                  imsi: chargingStation.bootNotificationRequest.imsi,
-                  meterSerialNumber: chargingStation.bootNotificationRequest.meterSerialNumber,
-                  meterType: chargingStation.bootNotificationRequest.meterType,
-                },
+                chargingStation.bootNotificationRequest,
                 { skipBufferingOnError: true, triggerMessage: true }
               )
-              .then((value) => {
-                chargingStation.bootNotificationResponse = value;
+              .then((response) => {
+                chargingStation.bootNotificationResponse = response;
               })
               .catch(() => {
                 /* This is intentional */
index 5e9e4899d66e59d1934631abb2b2071797f7d14e..64053c4200c439729828b3112d218c8db8adf703 100644 (file)
@@ -37,6 +37,7 @@ export default abstract class AbstractUIService {
     [ProcedureName.START_TRANSACTION]: BroadcastChannelProcedureName.START_TRANSACTION,
     [ProcedureName.STOP_TRANSACTION]: BroadcastChannelProcedureName.STOP_TRANSACTION,
     [ProcedureName.AUTHORIZE]: BroadcastChannelProcedureName.AUTHORIZE,
+    [ProcedureName.BOOT_NOTIFICATION]: BroadcastChannelProcedureName.BOOT_NOTIFICATION,
     [ProcedureName.STATUS_NOTIFICATION]: BroadcastChannelProcedureName.STATUS_NOTIFICATION,
     [ProcedureName.HEARTBEAT]: BroadcastChannelProcedureName.HEARTBEAT,
     [ProcedureName.METER_VALUES]: BroadcastChannelProcedureName.METER_VALUES,
index a43d96c7ab2ad0211115bbaaabffa7d529d14932..b02bac82cbb029e654e35e69769c45080a4a0fd2 100644 (file)
@@ -45,6 +45,10 @@ export default class UIService001 extends AbstractUIService {
       ProcedureName.AUTHORIZE,
       this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
     );
+    this.requestHandlers.set(
+      ProcedureName.BOOT_NOTIFICATION,
+      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
+    );
     this.requestHandlers.set(
       ProcedureName.STATUS_NOTIFICATION,
       this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
index 8195f7be7086722dbf386aa587abb3f4e30939d5..174ae7dd0cbccf00cab4f49c7fdced2098f9ab5b 100644 (file)
@@ -40,6 +40,7 @@ export enum ProcedureName {
   START_TRANSACTION = 'startTransaction',
   STOP_TRANSACTION = 'stopTransaction',
   AUTHORIZE = 'authorize',
+  BOOT_NOTIFICATION = 'bootNotification',
   STATUS_NOTIFICATION = 'statusNotification',
   HEARTBEAT = 'heartbeat',
   METER_VALUES = 'meterValues',
index 8b0d643ee3f8300f9db91f50f8ce6769547e5fb9..1756e496a3be5f3edc1604b5e7293de0244893db 100644 (file)
@@ -17,6 +17,7 @@ export enum BroadcastChannelProcedureName {
   START_TRANSACTION = 'startTransaction',
   STOP_TRANSACTION = 'stopTransaction',
   AUTHORIZE = 'authorize',
+  BOOT_NOTIFICATION = 'bootNotification',
   STATUS_NOTIFICATION = 'statusNotification',
   HEARTBEAT = 'heartbeat',
   METER_VALUES = 'meterValues',