From d9149cf1ea5f8e9469ecb4b2cb100a38577200dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Aug 2022 15:55:33 +0200 Subject: [PATCH 1/4] UI protocol: Allow to send some relevant commands to several charging stations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ChargingStationWorkerBroadcastChannel.ts | 7 ++++++- src/types/UIProtocol.ts | 2 +- src/types/WorkerBroadcastChannel.ts | 2 +- src/ui/web/src/type/UIProtocol.ts | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 9e88b41893..99a8e483c8 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -44,7 +44,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest; - if (requestPayload?.hashId !== this.chargingStation.hashId) { + if ( + (Array.isArray(requestPayload?.hashId) === true && + requestPayload?.hashId.includes(this.chargingStation.hashId)) || + (Array.isArray(requestPayload?.hashId) === false && + requestPayload?.hashId === this.chargingStation.hashId) + ) { return; } diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 63bb7ca1a5..51fa6e4b76 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -34,7 +34,7 @@ export enum ProcedureName { } export interface RequestPayload extends JsonObject { - hashId?: string; + hashId?: string | string[]; } export enum ResponseStatus { diff --git a/src/types/WorkerBroadcastChannel.ts b/src/types/WorkerBroadcastChannel.ts index 0015b717e7..a898dbfb71 100644 --- a/src/types/WorkerBroadcastChannel.ts +++ b/src/types/WorkerBroadcastChannel.ts @@ -17,7 +17,7 @@ export enum BroadcastChannelProcedureName { } export interface BroadcastChannelRequestPayload extends Omit { - hashId: string; + hashId: string | string[]; connectorId?: number; transactionId?: number; idTag?: string; diff --git a/src/ui/web/src/type/UIProtocol.ts b/src/ui/web/src/type/UIProtocol.ts index b8d40f31a1..34cdce3ced 100644 --- a/src/ui/web/src/type/UIProtocol.ts +++ b/src/ui/web/src/type/UIProtocol.ts @@ -32,7 +32,7 @@ export enum ProcedureName { CLOSE_CONNECTION = 'closeConnection', } export interface RequestPayload extends JsonObject { - hashId?: string; + hashId?: string | string[]; } export enum ResponseStatus { From f855f5a36a400b63e6d2890279de55ad96646165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Aug 2022 16:49:23 +0200 Subject: [PATCH 2/4] Define two different payload attributes for multiple and single charging station(s) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare the deprecation of the former. Signed-off-by: Jérôme Benoit --- .eslintignore | 1 + README.md | 18 +++++++++--------- .../ChargingStationWorkerBroadcastChannel.ts | 6 ++---- src/types/UIProtocol.ts | 3 ++- src/types/WorkerBroadcastChannel.ts | 15 +++++++++++++-- src/ui/web/src/type/UIProtocol.ts | 3 ++- 6 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..69ef742b96 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/src/ui/web/dist diff --git a/README.md b/README.md index f59641624e..4659bf7006 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 | `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 | `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 | `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 | `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 | `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 | `hashIds`: charging station unique identifier strings array } Response: diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 99a8e483c8..d0da705651 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -45,10 +45,8 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest; if ( - (Array.isArray(requestPayload?.hashId) === true && - requestPayload?.hashId.includes(this.chargingStation.hashId)) || - (Array.isArray(requestPayload?.hashId) === false && - requestPayload?.hashId === this.chargingStation.hashId) + (requestPayload?.hashIds as string[])?.includes(this.chargingStation.hashId) === false || + requestPayload?.hashId !== this.chargingStation.hashId ) { return; } diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 51fa6e4b76..1939fdd580 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -34,7 +34,8 @@ export enum ProcedureName { } export interface RequestPayload extends JsonObject { - hashId?: string | string[]; + hashId?: string; + hashIds?: string[]; } export enum ResponseStatus { diff --git a/src/types/WorkerBroadcastChannel.ts b/src/types/WorkerBroadcastChannel.ts index a898dbfb71..0d6da48d88 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 | 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 34cdce3ced..23537c3ea0 100644 --- a/src/ui/web/src/type/UIProtocol.ts +++ b/src/ui/web/src/type/UIProtocol.ts @@ -32,7 +32,8 @@ export enum ProcedureName { CLOSE_CONNECTION = 'closeConnection', } export interface RequestPayload extends JsonObject { - hashId?: string | string[]; + hashId?: string; + hashIds?: string[]; } export enum ResponseStatus { From f141fa74e20b34d1a780058e207fe8827484e79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Aug 2022 17:25:49 +0200 Subject: [PATCH 3/4] Fix condition at broadcast channel message handling (XOR between hashId and hashIds) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ChargingStationWorkerBroadcastChannel.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index d0da705651..0b32732e9a 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -45,7 +45,13 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest; if ( - (requestPayload?.hashIds as string[])?.includes(this.chargingStation.hashId) === false || + requestPayload?.hashId === undefined && + (requestPayload?.hashIds as string[])?.includes(this.chargingStation.hashId) === false + ) { + return; + } + if ( + requestPayload?.hashIds === undefined && requestPayload?.hashId !== this.chargingStation.hashId ) { return; From 48395d29890020c502069f374eedf3d5d8e92cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Aug 2022 17:37:39 +0200 Subject: [PATCH 4/4] Warn about deprecated field in UI protocol payloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 12 ++++++------ .../ChargingStationWorkerBroadcastChannel.ts | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4659bf7006..563b2e31b9 100644 --- a/README.md +++ b/README.md @@ -450,7 +450,7 @@ Response: Request: `ProcedureName`: 'startTransaction' `PDU`: { -`hashId`: charging station unique identifier string | `hashIds`: charging station unique identifier strings array, +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array, `connectorId`: connector id integer, `idTag`: RFID tag string } @@ -465,7 +465,7 @@ Response: Request: `ProcedureName`: 'stopTransaction' `PDU`: { -`hashId`: charging station unique identifier string | `hashIds`: charging station unique identifier strings array, +`hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array, `transactionId`: transaction id integer } @@ -479,7 +479,7 @@ Response: Request: `ProcedureName`: 'startChargingStation' `PDU`: { -`hashId`: charging station unique identifier string | `hashIds`: charging station unique identifier strings array +`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`: charging station unique identifier string | `hashIds`: charging station unique identifier strings array +`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`: charging station unique identifier string | `hashIds`: charging station unique identifier strings array +`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`: charging station unique identifier string | `hashIds`: charging station unique identifier strings array +`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 0b32732e9a..9de2cfb278 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -56,6 +56,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca ) { 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;