+ return JSON.stringify([messageId, procedureName, requestPayload] as ProtocolRequest);
+ }
+
+ private buildProtocolResponse(messageId: string, responsePayload: ResponsePayload): string {
+ return JSON.stringify([messageId, responsePayload] as ProtocolResponse);
+ }
+
+ // Validate the raw data received from the WebSocket
+ // TODO: should probably be moved to the ws verify clients callback
+ private requestValidation(rawData: RawData): ProtocolRequest {
+ // 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) {
+ throw new BaseError('UI protocol request is not iterable');
+ }
+
+ if (data.length !== 3) {
+ throw new BaseError('UI protocol request is malformed');
+ }
+
+ return data as ProtocolRequest;
+ }
+
+ private handleListChargingStations(): ResponsePayload {
+ // TODO: remove cast to unknown
+ return {
+ status: ResponseStatus.SUCCESS,
+ ...Array.from(this.uiServer.chargingStations.values()),
+ } as unknown as ResponsePayload;
+ }
+
+ private async handleStartSimulator(): Promise<ResponsePayload> {
+ await Bootstrap.getInstance().start();
+ return { status: ResponseStatus.SUCCESS };