UI protocol: add OCPP heartbeat command support
[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 this.requestHandlers.set(
47 ProcedureName.STATUS_NOTIFICATION,
48 this.handleStatusNotification.bind(this) as ProtocolRequestHandler
49 );
50 this.requestHandlers.set(
51 ProcedureName.HEARTBEAT,
52 this.handleHeartbeat.bind(this) as ProtocolRequestHandler
53 );
54 }
55
56 private handleStartChargingStation(uuid: string, payload: RequestPayload): void {
57 this.sendBroadcastChannelRequest(
58 uuid,
59 BroadcastChannelProcedureName.START_CHARGING_STATION,
60 payload
61 );
62 }
63
64 private handleStopChargingStation(uuid: string, payload: RequestPayload): void {
65 this.sendBroadcastChannelRequest(
66 uuid,
67 BroadcastChannelProcedureName.STOP_CHARGING_STATION,
68 payload
69 );
70 }
71
72 private handleOpenConnection(uuid: string, payload: RequestPayload): void {
73 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.OPEN_CONNECTION, payload);
74 }
75
76 private handleCloseConnection(uuid: string, payload: RequestPayload): void {
77 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.CLOSE_CONNECTION, payload);
78 }
79
80 private handleStartTransaction(uuid: string, payload: RequestPayload): void {
81 this.sendBroadcastChannelRequest(
82 uuid,
83 BroadcastChannelProcedureName.START_TRANSACTION,
84 payload
85 );
86 }
87
88 private handleStopTransaction(uuid: string, payload: RequestPayload): void {
89 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.STOP_TRANSACTION, payload);
90 }
91
92 private handleStartAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
93 this.sendBroadcastChannelRequest(
94 uuid,
95 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
96 payload
97 );
98 }
99
100 private handleStopAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
101 this.sendBroadcastChannelRequest(
102 uuid,
103 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
104 payload
105 );
106 }
107
108 private handleStatusNotification(uuid: string, payload: RequestPayload): void {
109 this.sendBroadcastChannelRequest(
110 uuid,
111 BroadcastChannelProcedureName.STATUS_NOTIFICATION,
112 payload
113 );
114 }
115
116 private handleHeartbeat(uuid: string, payload: RequestPayload): void {
117 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.HEARTBEAT, payload);
118 }
119 }