forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.cpp
More file actions
309 lines (237 loc) · 8 KB
/
Copy pathModel.cpp
File metadata and controls
309 lines (237 loc) · 8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Model/Model.h>
#include <string>
#include <MicroOcpp/Model/Transactions/TransactionStore.h>
#include <MicroOcpp/Model/SmartCharging/SmartChargingService.h>
#include <MicroOcpp/Model/ConnectorBase/ConnectorsCommon.h>
#include <MicroOcpp/Model/Metering/MeteringService.h>
#include <MicroOcpp/Model/FirmwareManagement/FirmwareService.h>
#include <MicroOcpp/Model/Diagnostics/DiagnosticsService.h>
#include <MicroOcpp/Model/Heartbeat/HeartbeatService.h>
#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
#include <MicroOcpp/Model/Reservation/ReservationService.h>
#include <MicroOcpp/Model/Boot/BootService.h>
#include <MicroOcpp/Model/Reset/ResetService.h>
#include <MicroOcpp/Model/Variables/VariableService.h>
#include <MicroOcpp/Model/Transactions/TransactionService.h>
#include <MicroOcpp/Model/Certificates/CertificateService.h>
#include <MicroOcpp/Core/Configuration.h>
#include <MicroOcpp/Debug.h>
using namespace MicroOcpp;
Model::Model(ProtocolVersion version, uint16_t bootNr) : version(version), bootNr(bootNr) {
}
Model::~Model() = default;
void Model::loop() {
if (bootService) {
bootService->loop();
}
if (capabilitiesUpdated) {
updateSupportedStandardProfiles();
capabilitiesUpdated = false;
}
if (!runTasks) {
return;
}
for (auto& connector : connectors) {
connector->loop();
}
if (chargeControlCommon)
chargeControlCommon->loop();
if (smartChargingService)
smartChargingService->loop();
if (heartbeatService)
heartbeatService->loop();
if (meteringService)
meteringService->loop();
if (diagnosticsService)
diagnosticsService->loop();
if (firmwareService)
firmwareService->loop();
if (reservationService)
reservationService->loop();
if (resetService)
resetService->loop();
#if MO_ENABLE_V201
if (transactionService)
transactionService->loop();
if (resetServiceV201)
resetServiceV201->loop();
#endif
}
void Model::setTransactionStore(std::unique_ptr<TransactionStore> ts) {
transactionStore = std::move(ts);
capabilitiesUpdated = true;
}
TransactionStore *Model::getTransactionStore() {
return transactionStore.get();
}
void Model::setSmartChargingService(std::unique_ptr<SmartChargingService> scs) {
smartChargingService = std::move(scs);
capabilitiesUpdated = true;
}
SmartChargingService* Model::getSmartChargingService() const {
return smartChargingService.get();
}
void Model::setConnectorsCommon(std::unique_ptr<ConnectorsCommon> ccs) {
chargeControlCommon = std::move(ccs);
capabilitiesUpdated = true;
}
ConnectorsCommon *Model::getConnectorsCommon() {
return chargeControlCommon.get();
}
void Model::setConnectors(std::vector<std::unique_ptr<Connector>>&& connectors) {
this->connectors = std::move(connectors);
capabilitiesUpdated = true;
}
unsigned int Model::getNumConnectors() const {
return connectors.size();
}
Connector *Model::getConnector(unsigned int connectorId) {
if (connectorId >= connectors.size()) {
MO_DBG_ERR("connector with connectorId %u does not exist", connectorId);
return nullptr;
}
return connectors[connectorId].get();
}
void Model::setMeteringSerivce(std::unique_ptr<MeteringService> ms) {
meteringService = std::move(ms);
capabilitiesUpdated = true;
}
MeteringService* Model::getMeteringService() const {
return meteringService.get();
}
void Model::setFirmwareService(std::unique_ptr<FirmwareService> fws) {
firmwareService = std::move(fws);
capabilitiesUpdated = true;
}
FirmwareService *Model::getFirmwareService() const {
return firmwareService.get();
}
void Model::setDiagnosticsService(std::unique_ptr<DiagnosticsService> ds) {
diagnosticsService = std::move(ds);
capabilitiesUpdated = true;
}
DiagnosticsService *Model::getDiagnosticsService() const {
return diagnosticsService.get();
}
void Model::setHeartbeatService(std::unique_ptr<HeartbeatService> hs) {
heartbeatService = std::move(hs);
capabilitiesUpdated = true;
}
void Model::setAuthorizationService(std::unique_ptr<AuthorizationService> as) {
authorizationService = std::move(as);
capabilitiesUpdated = true;
}
AuthorizationService *Model::getAuthorizationService() {
return authorizationService.get();
}
void Model::setReservationService(std::unique_ptr<ReservationService> rs) {
reservationService = std::move(rs);
capabilitiesUpdated = true;
}
ReservationService *Model::getReservationService() {
return reservationService.get();
}
void Model::setBootService(std::unique_ptr<BootService> bs){
bootService = std::move(bs);
capabilitiesUpdated = true;
}
BootService *Model::getBootService() const {
return bootService.get();
}
void Model::setResetService(std::unique_ptr<ResetService> rs) {
this->resetService = std::move(rs);
capabilitiesUpdated = true;
}
ResetService *Model::getResetService() const {
return resetService.get();
}
void Model::setCertificateService(std::unique_ptr<CertificateService> cs) {
this->certService = std::move(cs);
capabilitiesUpdated = true;
}
CertificateService *Model::getCertificateService() const {
return certService.get();
}
#if MO_ENABLE_V201
void Model::setVariableService(std::unique_ptr<VariableService> vs) {
this->variableService = std::move(vs);
capabilitiesUpdated = true;
}
VariableService *Model::getVariableService() const {
return variableService.get();
}
void Model::setTransactionService(std::unique_ptr<TransactionService> ts) {
this->transactionService = std::move(ts);
capabilitiesUpdated = true;
}
TransactionService *Model::getTransactionService() const {
return transactionService.get();
}
void Model::setResetServiceV201(std::unique_ptr<Ocpp201::ResetService> rs) {
this->resetServiceV201 = std::move(rs);
capabilitiesUpdated = true;
}
Ocpp201::ResetService *Model::getResetServiceV201() const {
return resetServiceV201.get();
}
#endif
Clock& Model::getClock() {
return clock;
}
const ProtocolVersion& Model::getVersion() const {
return version;
}
uint16_t Model::getBootNr() {
return bootNr;
}
void Model::updateSupportedStandardProfiles() {
auto supportedFeatureProfilesString =
declareConfiguration<const char*>("SupportedFeatureProfiles", "", CONFIGURATION_VOLATILE, true);
if (!supportedFeatureProfilesString) {
MO_DBG_ERR("OOM");
return;
}
std::string buf = supportedFeatureProfilesString->getString();
if (chargeControlCommon &&
heartbeatService &&
bootService) {
if (!strstr(supportedFeatureProfilesString->getString(), "Core")) {
if (!buf.empty()) buf += ',';
buf += "Core";
}
}
if (firmwareService ||
diagnosticsService) {
if (!strstr(supportedFeatureProfilesString->getString(), "FirmwareManagement")) {
if (!buf.empty()) buf += ',';
buf += "FirmwareManagement";
}
}
if (authorizationService) {
if (!strstr(supportedFeatureProfilesString->getString(), "LocalAuthListManagement")) {
if (!buf.empty()) buf += ',';
buf += "LocalAuthListManagement";
}
}
if (reservationService) {
if (!strstr(supportedFeatureProfilesString->getString(), "Reservation")) {
if (!buf.empty()) buf += ',';
buf += "Reservation";
}
}
if (smartChargingService) {
if (!strstr(supportedFeatureProfilesString->getString(), "SmartCharging")) {
if (!buf.empty()) buf += ',';
buf += "SmartCharging";
}
}
if (!strstr(supportedFeatureProfilesString->getString(), "RemoteTrigger")) {
if (!buf.empty()) buf += ',';
buf += "RemoteTrigger";
}
supportedFeatureProfilesString->setString(buf.c_str());
MO_DBG_DEBUG("supported feature profiles: %s", buf.c_str());
}