28286d3be62c03b702a5488043b5e4984acc4138
[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 const ProcedureNameToBroadCastChannelProcedureNameMap: Omit<
12 Record<ProcedureName, BroadcastChannelProcedureName>,
13 'startSimulator' | 'stopSimulator' | 'listChargingStations'
14 > = {
15 [ProcedureName.START_CHARGING_STATION]: BroadcastChannelProcedureName.START_CHARGING_STATION,
16 [ProcedureName.STOP_CHARGING_STATION]: BroadcastChannelProcedureName.STOP_CHARGING_STATION,
17 [ProcedureName.CLOSE_CONNECTION]: BroadcastChannelProcedureName.CLOSE_CONNECTION,
18 [ProcedureName.OPEN_CONNECTION]: BroadcastChannelProcedureName.OPEN_CONNECTION,
19 [ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR]:
20 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
21 [ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR]:
22 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
23 [ProcedureName.START_TRANSACTION]: BroadcastChannelProcedureName.START_TRANSACTION,
24 [ProcedureName.STOP_TRANSACTION]: BroadcastChannelProcedureName.STOP_TRANSACTION,
25 [ProcedureName.AUTHORIZE]: BroadcastChannelProcedureName.AUTHORIZE,
26 [ProcedureName.STATUS_NOTIFICATION]: BroadcastChannelProcedureName.STATUS_NOTIFICATION,
27 [ProcedureName.HEARTBEAT]: BroadcastChannelProcedureName.HEARTBEAT,
28 };
29
30 export default class UIService001 extends AbstractUIService {
31 constructor(uiServer: AbstractUIServer) {
32 super(uiServer, ProtocolVersion['0.0.1']);
33 this.requestHandlers.set(
34 ProcedureName.START_CHARGING_STATION,
35 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
36 );
37 this.requestHandlers.set(
38 ProcedureName.STOP_CHARGING_STATION,
39 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
40 );
41 this.requestHandlers.set(
42 ProcedureName.OPEN_CONNECTION,
43 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
44 );
45 this.requestHandlers.set(
46 ProcedureName.CLOSE_CONNECTION,
47 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
48 );
49 this.requestHandlers.set(
50 ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
51 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
52 );
53 this.requestHandlers.set(
54 ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
55 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
56 );
57 this.requestHandlers.set(
58 ProcedureName.START_TRANSACTION,
59 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
60 );
61 this.requestHandlers.set(
62 ProcedureName.STOP_TRANSACTION,
63 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
64 );
65 this.requestHandlers.set(
66 ProcedureName.AUTHORIZE,
67 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
68 );
69 this.requestHandlers.set(
70 ProcedureName.STATUS_NOTIFICATION,
71 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
72 );
73 this.requestHandlers.set(
74 ProcedureName.HEARTBEAT,
75 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
76 );
77 }
78
79 private handleProtocolRequest(
80 uuid: string,
81 procedureName: ProcedureName,
82 payload: RequestPayload
83 ): void {
84 this.sendBroadcastChannelRequest(
85 uuid,
86 ProcedureNameToBroadCastChannelProcedureNameMap[
87 procedureName
88 ] as BroadcastChannelProcedureName,
89 payload
90 );
91 }
92 }