UI Protocol: Build response with the global excecution status on each
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIService001.ts
1 import {
2 ProcedureName,
3 ProtocolRequestHandler,
4 ProtocolVersion,
5 RequestPayload,
6 } from '../../../types/UIProtocol';
7 import { BroadcastChannelProcedureName } from '../../../types/WorkerBroadcastChannel';
8 import type { AbstractUIServer } from '../AbstractUIServer';
9 import AbstractUIService from './AbstractUIService';
10
11 export default class UIService001 extends AbstractUIService {
12 constructor(uiServer: AbstractUIServer) {
13 super(uiServer, ProtocolVersion['0.0.1']);
14 this.requestHandlers.set(
15 ProcedureName.START_CHARGING_STATION,
16 this.handleStartChargingStation.bind(this) as ProtocolRequestHandler
17 );
18 this.requestHandlers.set(
19 ProcedureName.STOP_CHARGING_STATION,
20 this.handleStopChargingStation.bind(this) as ProtocolRequestHandler
21 );
22 this.requestHandlers.set(
23 ProcedureName.OPEN_CONNECTION,
24 this.handleOpenConnection.bind(this) as ProtocolRequestHandler
25 );
26 this.requestHandlers.set(
27 ProcedureName.CLOSE_CONNECTION,
28 this.handleCloseConnection.bind(this) as ProtocolRequestHandler
29 );
30 this.requestHandlers.set(
31 ProcedureName.START_TRANSACTION,
32 this.handleStartTransaction.bind(this) as ProtocolRequestHandler
33 );
34 this.requestHandlers.set(
35 ProcedureName.STOP_TRANSACTION,
36 this.handleStopTransaction.bind(this) as ProtocolRequestHandler
37 );
38 this.requestHandlers.set(
39 ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
40 this.handleStartAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler
41 );
42 this.requestHandlers.set(
43 ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
44 this.handleStopAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler
45 );
46 }
47
48 private handleStartChargingStation(uuid: string, payload: RequestPayload): void {
49 this.sendBroadcastChannelRequest(
50 uuid,
51 BroadcastChannelProcedureName.START_CHARGING_STATION,
52 payload
53 );
54 }
55
56 private handleStopChargingStation(uuid: string, payload: RequestPayload): void {
57 this.sendBroadcastChannelRequest(
58 uuid,
59 BroadcastChannelProcedureName.STOP_CHARGING_STATION,
60 payload
61 );
62 }
63
64 private handleOpenConnection(uuid: string, payload: RequestPayload): void {
65 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.OPEN_CONNECTION, payload);
66 }
67
68 private handleCloseConnection(uuid: string, payload: RequestPayload): void {
69 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.CLOSE_CONNECTION, payload);
70 }
71
72 private handleStartTransaction(uuid: string, payload: RequestPayload): void {
73 this.sendBroadcastChannelRequest(
74 uuid,
75 BroadcastChannelProcedureName.START_TRANSACTION,
76 payload
77 );
78 }
79
80 private handleStopTransaction(uuid: string, payload: RequestPayload): void {
81 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.STOP_TRANSACTION, payload);
82 }
83
84 private handleStartAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
85 this.sendBroadcastChannelRequest(
86 uuid,
87 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
88 payload
89 );
90 }
91
92 private handleStopAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
93 this.sendBroadcastChannelRequest(
94 uuid,
95 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
96 payload
97 );
98 }
99 }