From 8bfbc743623554d980978f90da658d7beb2e8d05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 9 Sep 2022 23:47:04 +0200 Subject: [PATCH] UI Protocol: add boot notification command support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 38 ++--------- .../ChargingStationWorkerBroadcastChannel.ts | 68 +++++++++++++------ .../UIServiceWorkerBroadcastChannel.ts | 2 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 18 +---- .../ui-services/AbstractUIService.ts | 1 + .../ui-server/ui-services/UIService001.ts | 4 ++ src/types/UIProtocol.ts | 1 + src/types/WorkerBroadcastChannel.ts | 1 + 8 files changed, 66 insertions(+), 67 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d7b67e6a..bbb5c6f2 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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(); diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 4f671966..31afa58e 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -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) { diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index 76de2cdf..5139b678 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -1,4 +1,4 @@ -import { ResponsePayload, ResponseStatus } from '../types/UIProtocol'; +import { type ResponsePayload, ResponseStatus } from '../types/UIProtocol'; import type { BroadcastChannelResponse, BroadcastChannelResponsePayload, diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index ce2f1d2b..f951fc77 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1116,23 +1116,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer .requestHandler( 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 */ diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 5e9e4899..64053c42 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -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, diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index a43d96c7..b02bac82 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -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 diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 8195f7be..174ae7dd 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -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', diff --git a/src/types/WorkerBroadcastChannel.ts b/src/types/WorkerBroadcastChannel.ts index 8b0d643e..1756e496 100644 --- a/src/types/WorkerBroadcastChannel.ts +++ b/src/types/WorkerBroadcastChannel.ts @@ -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', -- 2.34.1