To start the program, run: `npm start`.
-To start the program with a UI controller, run: `npm run start:server`.
-Then, start/stop the simulator by going to `https://<hostname:port>` in a browser. Localhost port will default to 8080. For Cloud Foundry, the port is assigned based on the `process.env.PORT` environment variable.
+## Start Web UI
## Configuration files syntax
## UI protocol
-Protocol to control the simulator via a Websocket protocol
+Protocol to control the simulator via a Websocket
-### Version 0.0.1
-
-Set the HTTP header Sec-Websocket-Protocol to `ui0.0.1`
+### Protocol
-#### Protocol
+PDU stands for Protocol Data Unit
Request:
[`uuid`, `ProcedureName`, `PDU`]
`uuid`: String uniquely representing this request
`ProcedureName`: The procedure to run on the simulator
-`PDU (for Protocol Data Unit)`: The parameters (if any) for said procedure
+`PDU`: The parameters (if any) for said procedure
Response:
[`uuid`, `PDU`]
`uuid`: String uniquely linking the response to the request
`PDU`: Response data to requested procedure
+### Version 0.0.1
+
+Set the HTTP header _Sec-Websocket-Protocol_ to `ui0.0.1`
+
#### Procedures
##### List Charging stations
Request:
-`ProcedureName`: 'listChargingStation'
+`ProcedureName`: 'listChargingStations'
`PDU`: {}
Response:
`PDU`: {
`status`,
-An array of ChargingStationData as described in `ChargingStationWorker.ts` file
+`Indexed ChargingStationData as described in ChargingStationWorker.ts file`
}
##### Start Transaction
Request:
`ProcedureName`: 'startTransaction'
`PDU`: {
-`hashId`: the unique identifier of a chargingStation
+`hashId`: the unique identifier of a charging station
`connectorId`: the id of the connector (start at 1)
`idTag`: An allowed badge authetification ID
}
Response:
`PDU`: {
-`status`,
-**null**
+`status`
}
##### Stop Transaction
Request:
`ProcedureName`: 'stopTransaction'
`PDU`: {
-`hashId`: the unique identifier of a chargingStation
+`hashId`: the unique identifier of a charging station
`transactionId`: the id of the transaction
}
Response:
`PDU`: {
-`status`,
-**null**
+`status`
}
## Support, Feedback, Contributing
import ChargingStation from './ChargingStation';
import WorkerBroadcastChannel from './WorkerBroadcastChannel';
+const moduleName = 'ChargingStationWorkerBroadcastChannel';
+
type MessageEvent = { data: unknown };
export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel {
import { BroadcastChannel } from 'worker_threads';
+import { BroadcastChannelRequest } from '../types/WorkerBroadcastChannel';
+
export default class WorkerBroadcastChannel extends BroadcastChannel {
constructor() {
super('worker');
}
+
+ public sendRequest(request: BroadcastChannelRequest): void {
+ this.postMessage(request);
+ }
}
}
// Call the message handler to build the response payload
- responsePayload = await this.messageHandlers.get(command)(requestPayload);
+ responsePayload = await this.messageHandlers.get(command)(messageId, requestPayload);
} catch (error) {
// Log
logger.error(
// Validate the raw data received from the WebSocket
// TODO: should probably be moved to the ws verify clients callback
private dataValidation(rawData: RawData): ProtocolRequest {
- logger.debug(
- `${this.uiServer.logPrefix(
- moduleName,
- 'dataValidation'
- )} Raw data received: ${rawData.toString()}`
- );
+ // logger.debug(
+ // `${this.uiServer.logPrefix(
+ // moduleName,
+ // 'dataValidation'
+ // )} Raw data received: ${rawData.toString()}`
+ // );
+
const data = JSON.parse(rawData.toString()) as JsonType[];
if (Utils.isIterable(data) === false) {
ResponsePayload,
ResponseStatus,
} from '../../../types/UIProtocol';
-import { BroadcastChannelProcedureName } from '../../../types/WorkerBroadcastChannel';
-import Utils from '../../../utils/Utils';
+import {
+ BroadcastChannelProcedureName,
+ BroadcastChannelRequestPayload,
+} from '../../../types/WorkerBroadcastChannel';
import { AbstractUIServer } from '../AbstractUIServer';
import AbstractUIService from './AbstractUIService';
);
}
- private handleStartTransaction(payload: RequestPayload): ResponsePayload {
- this.workerBroadcastChannel.postMessage([
- Utils.generateUUID(),
+ private handleStartTransaction(uuid: string, payload: RequestPayload): ResponsePayload {
+ this.workerBroadcastChannel.sendRequest([
+ uuid,
BroadcastChannelProcedureName.START_TRANSACTION,
- payload,
+ payload as BroadcastChannelRequestPayload,
]);
return { status: ResponseStatus.SUCCESS };
}
- private handleStopTransaction(payload: RequestPayload): ResponsePayload {
- this.workerBroadcastChannel.postMessage([
- Utils.generateUUID(),
+ private handleStopTransaction(uuid: string, payload: RequestPayload): ResponsePayload {
+ this.workerBroadcastChannel.sendRequest([
+ uuid,
BroadcastChannelProcedureName.STOP_TRANSACTION,
- payload,
+ payload as BroadcastChannelRequestPayload,
]);
return { status: ResponseStatus.SUCCESS };
}
- private handleStartChargingStation(payload: RequestPayload): ResponsePayload {
- this.workerBroadcastChannel.postMessage([
- Utils.generateUUID(),
+ private handleStartChargingStation(uuid: string, payload: RequestPayload): ResponsePayload {
+ this.workerBroadcastChannel.sendRequest([
+ uuid,
BroadcastChannelProcedureName.START_CHARGING_STATION,
- payload,
+ payload as BroadcastChannelRequestPayload,
]);
return { status: ResponseStatus.SUCCESS };
}
- private handleStopChargingStation(payload: RequestPayload): ResponsePayload {
- this.workerBroadcastChannel.postMessage([
- Utils.generateUUID(),
+ private handleStopChargingStation(uuid: string, payload: RequestPayload): ResponsePayload {
+ this.workerBroadcastChannel.sendRequest([
+ uuid,
BroadcastChannelProcedureName.STOP_CHARGING_STATION,
- payload,
+ payload as BroadcastChannelRequestPayload,
]);
return { status: ResponseStatus.SUCCESS };
}
export type ProtocolResponse = [string, ResponsePayload];
export type ProtocolRequestHandler = (
- payload: RequestPayload
+ uuid?: string,
+ payload?: RequestPayload
) => ResponsePayload | Promise<ResponsePayload>;
export enum ProcedureName {
import { JsonObject } from './JsonType';
+import { RequestPayload, ResponsePayload } from './UIProtocol';
-export type BroadcastChannelRequest = [string, BroadcastChannelProcedureName, RequestPayload];
-export type BroadcastChannelResponse = [string, ResponsePayload];
+export type BroadcastChannelRequest = [
+ string,
+ BroadcastChannelProcedureName,
+ BroadcastChannelRequestPayload
+];
+export type BroadcastChannelResponse = [string, BroadcastChannelResponsePayload];
export enum BroadcastChannelProcedureName {
START_CHARGING_STATION = 'startChargingStation',
STOP_TRANSACTION = 'stopTransaction',
}
-interface BasePayload extends JsonObject {
+interface BroadcastChannelBasePayload extends JsonObject {
hashId: string;
}
-export interface RequestPayload extends BasePayload {
+export interface BroadcastChannelRequestPayload
+ extends BroadcastChannelBasePayload,
+ Omit<RequestPayload, 'hashId'> {
connectorId?: number;
transactionId?: number;
idTag?: string;
}
-export type ResponsePayload = BasePayload;
+export type BroadcastChannelResponsePayload = ResponsePayload;
-import { JsonObject, JsonType } from './JsonType';
+import { JsonObject } from './JsonType';
export enum Protocol {
UI = 'ui',
'0.0.1' = '0.0.1',
}
+export type ProtocolRequest = [string, ProcedureName, RequestPayload];
+export type ProtocolResponse = [string, ResponsePayload];
+
+export type ProtocolRequestHandler = (
+ payload: RequestPayload
+) => ResponsePayload | Promise<ResponsePayload>;
+
export enum ProcedureName {
LIST_CHARGING_STATIONS = 'listChargingStations',
+ START_CHARGING_STATION = 'startChargingStation',
+ STOP_CHARGING_STATION = 'stopChargingStation',
START_TRANSACTION = 'startTransaction',
STOP_TRANSACTION = 'stopTransaction',
START_SIMULATOR = 'startSimulator',
STOP_SIMULATOR = 'stopSimulator',
}
+export interface RequestPayload extends JsonObject {
+ hashId?: string;
+}
export enum ResponseStatus {
SUCCESS = 'success',
export interface ResponsePayload extends JsonObject {
status: ResponseStatus;
}
-
-export type ProtocolRequest = [string, ProcedureName, JsonType];
-export type ProtocolResponse = [string, ResponsePayload];
-
-export type ProtocolRequestHandler = (
- payload: JsonType
-) => void | Promise<void> | ResponsePayload | Promise<ResponsePayload>;