From 757b2ecfd506d85f04ab57e13ff0cb3cf4c024fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 31 Aug 2022 23:28:15 +0200 Subject: [PATCH] Web UI: add start/stop ATG command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 12 +++--- .../ChargingStationWorkerBroadcastChannel.ts | 3 +- src/types/UIProtocol.ts | 2 +- src/types/WorkerBroadcastChannel.ts | 8 +--- .../charging-stations/CSConnector.vue | 8 ++++ src/ui/web/src/composables/UIClient.ts | 40 ++++++++++++++----- src/ui/web/src/types/UIProtocol.ts | 13 +++--- 7 files changed, 56 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 855e13db..e9ba6a77 100644 --- a/README.md +++ b/README.md @@ -452,7 +452,7 @@ Set the WebSocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. - Request: `ProcedureName`: 'startTransaction' `PDU`: { - `hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array, + `hashIds`: charging station unique identifier strings array, `connectorId`: connector id integer, `idTag`: RFID tag string } @@ -467,7 +467,7 @@ Set the WebSocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. - Request: `ProcedureName`: 'stopTransaction' `PDU`: { - `hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array, + `hashIds`: charging station unique identifier strings array, `transactionId`: transaction id integer } @@ -481,7 +481,7 @@ Set the WebSocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. - Request: `ProcedureName`: 'startChargingStation' `PDU`: { - `hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array + `hashIds`: charging station unique identifier strings array } - Response: @@ -494,7 +494,7 @@ Set the WebSocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. - Request: `ProcedureName`: 'stopChargingStation' `PDU`: { - `hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array + `hashIds`: charging station unique identifier strings array } - Response: @@ -507,7 +507,7 @@ Set the WebSocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. - Request: `ProcedureName`: 'openConnection' `PDU`: { - `hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array + `hashIds`: charging station unique identifier strings array } - Response: @@ -520,7 +520,7 @@ Set the WebSocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. - Request: `ProcedureName`: 'closeConnection' `PDU`: { - `hashId`: charging station unique identifier string (deprecated) | `hashIds`: charging station unique identifier strings array + `hashIds`: charging station unique identifier strings array } - Response: diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 159743a0..714bf0f9 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -44,8 +44,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca if ( requestPayload?.hashId === undefined && - (requestPayload?.hashIds as string[])?.includes(this.chargingStation.stationInfo.hashId) === - false + requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false ) { return; } diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 3906512d..f120f9c9 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -36,8 +36,8 @@ export enum ProcedureName { } export interface RequestPayload extends JsonObject { - hashId?: string; hashIds?: string[]; + connectorIds?: number[]; } export enum ResponseStatus { diff --git a/src/types/WorkerBroadcastChannel.ts b/src/types/WorkerBroadcastChannel.ts index 2cc18943..03be12fd 100644 --- a/src/types/WorkerBroadcastChannel.ts +++ b/src/types/WorkerBroadcastChannel.ts @@ -25,17 +25,11 @@ interface BaseBroadcastChannelRequestPayload extends Omit --> + + {{ connectorId }} {{ connector.status }} @@ -79,4 +81,10 @@ function startTransaction(): void { function stopTransaction(): void { UIClient.getInstance().stopTransaction(props.hashId, props.transactionId); } +function startAutomaticTransactionGenerator(): void { + UIClient.getInstance().startAutomaticTransactionGenerator(props.hashId, props.connectorId); +} +function stopAutomaticTransactionGenerator(): void { + UIClient.getInstance().stopAutomaticTransactionGenerator(props.hashId, props.connectorId); +} diff --git a/src/ui/web/src/composables/UIClient.ts b/src/ui/web/src/composables/UIClient.ts index 275e30e9..556e9bb7 100644 --- a/src/ui/web/src/composables/UIClient.ts +++ b/src/ui/web/src/composables/UIClient.ts @@ -1,5 +1,4 @@ -import type { JsonType } from '@/types/JsonType'; -import { ProcedureName, ResponseStatus } from '@/types/UIProtocol'; +import { ProcedureName, ResponseStatus, type RequestPayload } from '@/types/UIProtocol'; import type { ProtocolResponse, ResponsePayload } from '@/types/UIProtocol'; import Utils from './Utils'; @@ -47,22 +46,22 @@ export default class UIClient { } public async startChargingStation(hashId: string): Promise { - return this.sendRequest(ProcedureName.START_CHARGING_STATION, { hashId }); + return this.sendRequest(ProcedureName.START_CHARGING_STATION, { hashIds: [hashId] }); } public async stopChargingStation(hashId: string): Promise { - return this.sendRequest(ProcedureName.STOP_CHARGING_STATION, { hashId }); + return this.sendRequest(ProcedureName.STOP_CHARGING_STATION, { hashIds: [hashId] }); } public async openConnection(hashId: string): Promise { return this.sendRequest(ProcedureName.OPEN_CONNECTION, { - hashId, + hashIds: [hashId], }); } public async closeConnection(hashId: string): Promise { return this.sendRequest(ProcedureName.CLOSE_CONNECTION, { - hashId, + hashIds: [hashId], }); } @@ -72,7 +71,7 @@ export default class UIClient { idTag: string | undefined ): Promise { return this.sendRequest(ProcedureName.START_TRANSACTION, { - hashId, + hashIds: [hashId], connectorId, idTag, }); @@ -83,11 +82,31 @@ export default class UIClient { transactionId: number | undefined ): Promise { return this.sendRequest(ProcedureName.STOP_TRANSACTION, { - hashId, + hashIds: [hashId], transactionId, }); } + public async startAutomaticTransactionGenerator( + hashId: string, + connectorId: number + ): Promise { + return this.sendRequest(ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR, { + hashIds: [hashId], + connectorIds: [connectorId], + }); + } + + public async stopAutomaticTransactionGenerator( + hashId: string, + connectorId: number + ): Promise { + return this.sendRequest(ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR, { + hashIds: [hashId], + connectorIds: [connectorId], + }); + } + private openWS(): void { this._ws = new WebSocket( `ws://${config.uiServer.host}:${config.uiServer.port}`, @@ -119,7 +138,10 @@ export default class UIClient { return this._responseHandlers.delete(id); } - private async sendRequest(command: ProcedureName, data: JsonType): Promise { + private async sendRequest( + command: ProcedureName, + data: RequestPayload + ): Promise { let uuid: string; return Utils.promiseWithTimeout( new Promise((resolve, reject) => { diff --git a/src/ui/web/src/types/UIProtocol.ts b/src/ui/web/src/types/UIProtocol.ts index 22871d68..f3a9d072 100644 --- a/src/ui/web/src/types/UIProtocol.ts +++ b/src/ui/web/src/types/UIProtocol.ts @@ -21,19 +21,22 @@ export type ProtocolRequestHandler = ( ) => ResponsePayload | Promise; export enum ProcedureName { + START_SIMULATOR = 'startSimulator', + STOP_SIMULATOR = 'stopSimulator', LIST_CHARGING_STATIONS = 'listChargingStations', START_CHARGING_STATION = 'startChargingStation', STOP_CHARGING_STATION = 'stopChargingStation', - START_TRANSACTION = 'startTransaction', - STOP_TRANSACTION = 'stopTransaction', - START_SIMULATOR = 'startSimulator', - STOP_SIMULATOR = 'stopSimulator', OPEN_CONNECTION = 'openConnection', CLOSE_CONNECTION = 'closeConnection', + START_TRANSACTION = 'startTransaction', + STOP_TRANSACTION = 'stopTransaction', + START_AUTOMATIC_TRANSACTION_GENERATOR = 'startAutomaticTransactionGenerator', + STOP_AUTOMATIC_TRANSACTION_GENERATOR = 'stopAutomaticTransactionGenerator', } export interface RequestPayload extends JsonObject { - hashId?: string; hashIds?: string[]; + connectorId?: number; + connectorIds?: number[]; } export enum ResponseStatus { -- 2.34.1