UI protocol: add OCPP heartbeat command support
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIService001.ts
CommitLineData
33cea517 1import {
32de5a57 2 ProcedureName,
33cea517
JB
3 ProtocolRequestHandler,
4 ProtocolVersion,
89b7a234 5 RequestPayload,
33cea517 6} from '../../../types/UIProtocol';
0d2cec76 7import { BroadcastChannelProcedureName } from '../../../types/WorkerBroadcastChannel';
6c1761d4 8import type { AbstractUIServer } from '../AbstractUIServer';
4198ad5c 9import AbstractUIService from './AbstractUIService';
4198ad5c 10
f16356b9 11export default class UIService001 extends AbstractUIService {
fe94fce0 12 constructor(uiServer: AbstractUIServer) {
33cea517 13 super(uiServer, ProtocolVersion['0.0.1']);
02a6943a 14 this.requestHandlers.set(
89b7a234
JB
15 ProcedureName.START_CHARGING_STATION,
16 this.handleStartChargingStation.bind(this) as ProtocolRequestHandler
17 );
02a6943a 18 this.requestHandlers.set(
89b7a234
JB
19 ProcedureName.STOP_CHARGING_STATION,
20 this.handleStopChargingStation.bind(this) as ProtocolRequestHandler
21 );
db2336d9
JB
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 );
4f69be04
JB
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 );
a9ed42b2
JB
46 this.requestHandlers.set(
47 ProcedureName.STATUS_NOTIFICATION,
48 this.handleStatusNotification.bind(this) as ProtocolRequestHandler
49 );
10db00b2
JB
50 this.requestHandlers.set(
51 ProcedureName.HEARTBEAT,
52 this.handleHeartbeat.bind(this) as ProtocolRequestHandler
53 );
89b7a234
JB
54 }
55
4f69be04 56 private handleStartChargingStation(uuid: string, payload: RequestPayload): void {
0d2cec76 57 this.sendBroadcastChannelRequest(
4e3ff94d 58 uuid,
4f69be04 59 BroadcastChannelProcedureName.START_CHARGING_STATION,
0d2cec76
JB
60 payload
61 );
89b7a234
JB
62 }
63
4f69be04 64 private handleStopChargingStation(uuid: string, payload: RequestPayload): void {
0d2cec76 65 this.sendBroadcastChannelRequest(
4e3ff94d 66 uuid,
4f69be04 67 BroadcastChannelProcedureName.STOP_CHARGING_STATION,
0d2cec76
JB
68 payload
69 );
4198ad5c
JB
70 }
71
4f69be04 72 private handleOpenConnection(uuid: string, payload: RequestPayload): void {
0d2cec76 73 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.OPEN_CONNECTION, payload);
32de5a57
LM
74 }
75
4f69be04 76 private handleCloseConnection(uuid: string, payload: RequestPayload): void {
0d2cec76 77 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.CLOSE_CONNECTION, payload);
32de5a57 78 }
db2336d9 79
4f69be04 80 private handleStartTransaction(uuid: string, payload: RequestPayload): void {
0d2cec76 81 this.sendBroadcastChannelRequest(
db2336d9 82 uuid,
4f69be04 83 BroadcastChannelProcedureName.START_TRANSACTION,
0d2cec76
JB
84 payload
85 );
db2336d9
JB
86 }
87
4f69be04 88 private handleStopTransaction(uuid: string, payload: RequestPayload): void {
0d2cec76 89 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.STOP_TRANSACTION, payload);
4f69be04
JB
90 }
91
92 private handleStartAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
0d2cec76 93 this.sendBroadcastChannelRequest(
4f69be04
JB
94 uuid,
95 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
0d2cec76
JB
96 payload
97 );
4f69be04
JB
98 }
99
100 private handleStopAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
0d2cec76 101 this.sendBroadcastChannelRequest(
4f69be04
JB
102 uuid,
103 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
0d2cec76
JB
104 payload
105 );
db2336d9 106 }
a9ed42b2
JB
107
108 private handleStatusNotification(uuid: string, payload: RequestPayload): void {
109 this.sendBroadcastChannelRequest(
110 uuid,
111 BroadcastChannelProcedureName.STATUS_NOTIFICATION,
112 payload
113 );
114 }
10db00b2
JB
115
116 private handleHeartbeat(uuid: string, payload: RequestPayload): void {
117 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.HEARTBEAT, payload);
118 }
4198ad5c 119}