From 4eca248cf2d300b51dc45412766a821184a00dcb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Aug 2022 17:41:37 +0200 Subject: [PATCH] =?utf8?q?UI=20protocol:=20Allow=20to=20send=20some=20rele?= =?utf8?q?vant=20commands=20to=20several=20charging=E2=80=A6=20(#152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .eslintignore | 1 + README.md | 18 +++++++++--------- .../ChargingStationWorkerBroadcastChannel.ts | 16 +++++++++++++++- src/types/UIProtocol.ts | 1 + src/types/WorkerBroadcastChannel.ts | 15 +++++++++++++-- src/ui/web/src/type/UIProtocol.ts | 1 + 6 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..69ef742b --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/src/ui/web/dist diff --git a/README.md b/README.md index f5964162..563b2e31 100644 --- a/README.md +++ b/README.md @@ -450,9 +450,9 @@ Response: Request: `ProcedureName`: 'startTransaction' `PDU`: { -`hashId`: the unique identifier of a charging station -`connectorId`: the id of the connector -`idTag`: the RFID tag +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array, +`connectorId`: connector id integer, +`idTag`: RFID tag string } Response: @@ -465,8 +465,8 @@ Response: Request: `ProcedureName`: 'stopTransaction' `PDU`: { -`hashId`: the unique identifier of a charging station -`transactionId`: the id of the transaction +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array, +`transactionId`: transaction id integer } Response: @@ -479,7 +479,7 @@ Response: Request: `ProcedureName`: 'startChargingStation' `PDU`: { -`hashId`: the unique identifier of a charging station +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array } Response: @@ -492,7 +492,7 @@ Response: Request: `ProcedureName`: 'stopChargingStation' `PDU`: { -`hashId`: the unique identifier of a charging station +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array } Response: @@ -505,7 +505,7 @@ Response: Request: `ProcedureName`: 'openConnection' `PDU`: { -`hashId`: the unique identifier of a charging station +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array } Response: @@ -518,7 +518,7 @@ Response: Request: `ProcedureName`: 'closeConnection' `PDU`: { -`hashId`: the unique identifier of a charging station +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array } Response: diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 9e88b418..9de2cfb2 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -44,9 +44,23 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest; - if (requestPayload?.hashId !== this.chargingStation.hashId) { + if ( + requestPayload?.hashId === undefined && + (requestPayload?.hashIds as string[])?.includes(this.chargingStation.hashId) === false + ) { return; } + if ( + requestPayload?.hashIds === undefined && + requestPayload?.hashId !== this.chargingStation.hashId + ) { + return; + } + if (requestPayload?.hashId !== undefined) { + logger.warn( + `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead` + ); + } let responsePayload: BroadcastChannelResponsePayload; let commandResponse: CommandResponse; diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 63bb7ca1..1939fdd5 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -35,6 +35,7 @@ export enum ProcedureName { export interface RequestPayload extends JsonObject { hashId?: string; + hashIds?: string[]; } export enum ResponseStatus { diff --git a/src/types/WorkerBroadcastChannel.ts b/src/types/WorkerBroadcastChannel.ts index 0015b717..0d6da48d 100644 --- a/src/types/WorkerBroadcastChannel.ts +++ b/src/types/WorkerBroadcastChannel.ts @@ -16,13 +16,24 @@ export enum BroadcastChannelProcedureName { CLOSE_CONNECTION = 'closeConnection', } -export interface BroadcastChannelRequestPayload extends Omit { - hashId: string; +interface BaseBroadcastChannelRequestPayload extends Omit { connectorId?: number; transactionId?: number; idTag?: string; } +interface HashIdBroadcastChannelRequestPayload extends BaseBroadcastChannelRequestPayload { + hashId: string; +} + +interface HashIdsBroadcastChannelRequestPayload extends BaseBroadcastChannelRequestPayload { + hashIds: string[]; +} + +export type BroadcastChannelRequestPayload = + | HashIdBroadcastChannelRequestPayload + | HashIdsBroadcastChannelRequestPayload; + export type BroadcastChannelResponsePayload = ResponsePayload; export type MessageEvent = { data: BroadcastChannelRequest | BroadcastChannelResponse }; diff --git a/src/ui/web/src/type/UIProtocol.ts b/src/ui/web/src/type/UIProtocol.ts index b8d40f31..23537c3e 100644 --- a/src/ui/web/src/type/UIProtocol.ts +++ b/src/ui/web/src/type/UIProtocol.ts @@ -33,6 +33,7 @@ export enum ProcedureName { } export interface RequestPayload extends JsonObject { hashId?: string; + hashIds?: string[]; } export enum ResponseStatus { -- 2.34.1