+ procedureName: ProcedureName,
+ requestPayload: RequestPayload
+ ): void {
+ this.uiServer.sendRequest(
+ this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload)
+ );
+ }
+
+ public sendResponse(messageId: string, responsePayload: ResponsePayload): void {
+ this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));
+ }
+
+ public logPrefix(modName: string, methodName: string): string {
+ return this.uiServer.logPrefix(modName, methodName);
+ }
+
+ // Validate the raw data received from the UI server
+ private requestValidation(rawData: RawData | JsonType): ProtocolRequest {
+ // logger.debug(
+ // `${this.logPrefix(
+ // moduleName,
+ // 'requestValidation'
+ // )} Data received in string format: ${rawData.toString()}`
+ // );
+
+ const data = JSON.parse(rawData.toString()) as JsonType[];
+
+ if (Array.isArray(data) === false) {
+ throw new BaseError('UI protocol request is not an array');
+ }
+
+ 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,
+ ...[...this.uiServer.chargingStations.values()],
+ } as unknown as ResponsePayload;
+ }
+
+ private async handleStartSimulator(): Promise<ResponsePayload> {
+ await Bootstrap.getInstance().start();
+ return { status: ResponseStatus.SUCCESS };