-
Notifications
You must be signed in to change notification settings - Fork 1
/
SmartChargerXML.cpp
525 lines (458 loc) · 18.8 KB
/
SmartChargerXML.cpp
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#include <QApplication>
#include <QtXml>// Library needed for processing XML documents
#include <QFile>// Library needed for processing files
#include <iostream>
#include "SmartChargerXML.h"
#include "Downloader.h"
//#define INTERMEDIATES
// -----------------------------------------------------------
// read XML file SmartCharger
// -----------------------------------------------------------
SmartChargerXML::SmartChargerXML() {}
void SmartChargerXML::ReadSmartChargerXML() {
extern QByteArray m_XMLfiledata; // globally defined in main.cpp, loaded with data by Downloader.cpp
QDomElement docElem;
QDomDocument xmldoc;
// _________________________________
// ::: Read data from byte array :::
// Set data into the QDomDocument before processing
xmldoc.setContent(m_XMLfiledata);
// _________________________
// ::: Read the root tag :::
// Extract the root markup
QDomElement root=xmldoc.documentElement();
QString RootName=root.tagName(); // Get root name// should be GetValues
std::cout << "RootName = " << RootName.toStdString().c_str() << std::endl; // Display root data
docElem=root.firstChild().toElement(); // root Element einlesen
QDomNode node = root.firstChild(); // erstes Child
QDomNode nodeRestart = node; // Merker für zweite Runde (EV)
// oberste Ebene unterhalb GetValues
// Search node SettingsVersion -----------------------------------------------------------------
while ((node.nodeName().compare("SettingsVersion") != 0) && (!node.isNull())) // überspringe alle Nodes bis SmartMeter
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// erste Ebene innerhalb GetValues
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("SettingsVersion")==0)
{
std::cout << " SettingsVersion = " << node.firstChild().toText().data().toStdString().c_str() << std::endl;
if ((node.firstChild().toText().data().toStdString() != "2.6.107") && (node.firstChild().toText().data().toStdString() != "1.6"))
{
m_messageFlag |= VERSIONFlag;
std::cout << " Caution! Wrong settings version - Parser is for '1.6 or '2.6.107' and has to be checked" << std::endl;
}
}
// Search node SmartMeter -----------------------------------------------------------------
// loopcount = 0;
while ((node.nodeName().compare("SmartMeter") != 0) && (!node.isNull())) // überspringe alle Nodes bis SmartMeter
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// erste Ebene innerhalb SmartMeter
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
QDomNode nodeRestartTop = node; // Merker für dritte Runde (StorageSystem)
node = node.firstChild();
// Search node ActualPower
// loopcount = 0;
while ((node.nodeName().compare("ActualPower") !=0 ) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("ActualPower")==0)
{
m_SmartMeterActualPower = node.firstChild().toText().data().toDouble();
std::cout << " ActualPower = " << m_SmartMeterActualPower << std::endl;
}
// Search node MeterReadings
// loopcount = 0;
while ((node.nodeName().compare("MeterReadings") !=0 ) && (!node.isNull())) // überspringe alle Nodes bis MeterReadings
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// erste Ebene innerhalb MeterReadings
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node ActualPower
// loopcount = 0;
while ((node.nodeName().compare("Consumption") !=0 ) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("Consumption")==0)
{
m_SmartMeterConsumption = node.firstChild().toText().data().toDouble();
std::cout << " Consumption = " << m_SmartMeterConsumption << std::endl;
}
// Read node Surplus
node=node.nextSibling();
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("Surplus")==0)
{
m_SmartMeterSurplus = node.firstChild().toText().data().toDouble();
std::cout << " Surplus = " << m_SmartMeterSurplus << std::endl;
}
// wieder oberste Ebene, neu aufsetzen
node = nodeRestartTop; // neu aufsetzen
// Search node EV -----------------------------------------------------------------
// loopcount = 0;
while ((node.nodeName().compare("EV") != 0) && (!node.isNull())) // überspringe alle Nodes bis EV
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
nodeRestart = node; // Merker für zweite Runde (Wallbox)
// erste Ebene innerhalb EV
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node Charging
// loopcount = 0;
while ((node.nodeName().compare("Charging") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// erste Ebene innerhalb Charging
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node ChargingMode
// loopcount = 0;
while ((node.nodeName().compare("ChargingMode") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("ChargingMode")==0)
{
m_EVChargingMode = node.firstChild().toText().data(); // moegliche Werte: OFF, QUICK, SURPLUS, MANUAL
std::cout << " ChargingMode = " << m_EVChargingMode.toStdString().c_str() << std::endl;
}
// Search node EvaluationPoints
// loopcount = 0;
while ((node.nodeName().compare("EvaluationPoints") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("EvaluationPoints")==0)
{
m_EVEvaluationPoints = node.firstChild().toText().data().toDouble();
std::cout << " EvaluationPoints = " << m_EVEvaluationPoints << std::endl;
}
// Search node Wallbox
node = nodeRestart.firstChild(); // neu aufsetzen
// loopcount = 0;
while ((node.nodeName().compare("Wallbox") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// erste Ebene innerhalb Wallbox
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node State
/*
"State" = Current state of the charging station
0 : starting
1 : not ready for charging; e.g. unplugged, X1 or "ena" not enabled, RFID not enabled, ...
2 : ready for charging; waiting for EV charging request (S2)
3 : charging
4 : error
5 : authorization rejected
*/
// loopcount = 0;
while ((node.nodeName().compare("State") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("State")==0)
{
m_EVState = node.toElement().attribute("id").toInt();
std::cout << " State = " << m_EVState << std::endl;
}
// Search node Plug
/*
"Plug" = Current condition of the loading connection
0 unplugged
1 plugged on charging station
3 plugged on charging station plug locked
5 plugged on charging station plugged on EV
7 plugged on charging station plug locked plugged on EV
"Enable sys" = Enable state for charging (contains Enable input, RFID, UDP,..)
*/
node=node.nextSibling();
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("Plug")==0)
{
m_EVPlug = node.toElement().attribute("id").toInt(); // <<<<< klappt nicht
std::cout << " Plug = " << m_EVPlug << std::endl;
}
// Search node SystemEnabled
node=node.nextSibling();
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("SystemEnabled")==0)
{
m_EVSystemEnabled = node.firstChild().toText().data().toDouble();
std::cout << " SystemEnabled = " << m_EVSystemEnabled << std::endl;
}
// Search node ActualPower
// loopcount = 0;
while ((node.nodeName().compare("ActualPower") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("ActualPower")==0)
{
m_EVActualPower = node.firstChild().toText().data().toDouble();
std::cout << " ActualPower = " << m_EVActualPower << std::endl;
}
// Search node SessionEnergy
node=node.nextSibling();
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("SessionEnergy")==0)
{
m_EVSessionEnergy = node.firstChild().toText().data().toDouble();
std::cout << " SessionEnergy = " << m_EVSessionEnergy << std::endl;
}
// Search node TotalEnergy
// loopcount = 0;
while ((node.nodeName().compare("TotalEnergy") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("TotalEnergy")==0)
{
m_EVTotalEnergy = node.firstChild().toText().data().toULong();
std::cout << " TotalEnergy = " << m_EVTotalEnergy << std::endl;
}
// wieder oberste Ebene, neu aufsetzen
node = nodeRestartTop;
// Search node StorageSystem -----------------------------------------------------------------
// loopcount = 0;
while ((node.nodeName().compare("StorageSystem") != 0) && (!node.isNull())) // überspringe alle Nodes bis StorageSystem
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
nodeRestart = node; // Merker für zweite Runde (AC)
// erste Ebene innerhalb StorageSystem
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node Battery
// loopcount = 0;
while ((node.nodeName().compare("Battery") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// erste Ebene innerhalb Battery
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node SOC
// loopcount = 0;
while ((node.nodeName().compare("SOC") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("SOC")==0)
{
m_StorageSystemSOC = node.firstChild().toText().data().toInt();
std::cout << " SOC = " << m_StorageSystemSOC << std::endl;
}
node=node.nextSibling();
// Search node Temperature
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("Temperature")==0)
{
m_StorageSystemTemperature = node.firstChild().toText().data().toDouble();
std::cout << " Temperature = " << m_StorageSystemTemperature << std::endl;
}
// wieder eine Ebene höher, neu aufsetzen
node = nodeRestart;
// Search node AC
// erste Ebene innerhalb StorageSystem
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// loopcount = 0;
while ((node.nodeName().compare("AC") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
// Search node ActualPower
// erste Ebene innerhalb AC
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node = node.firstChild();
// Search node ActualPower
// loopcount = 0;
while ((node.nodeName().compare("ActualPower") != 0) && (!node.isNull()))
{
#ifdef INTERMEDIATES
std::cout << " NodeNameLoop = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
node=node.nextSibling();
}
#ifdef INTERMEDIATES
std::cout << " NodeName = " << node.nodeName().toStdString().c_str() << std::endl;
#endif
if (node.nodeName().compare("ActualPower")==0)
{
m_StorageSystemActualPower = node.firstChild().toText().data().toDouble();
std::cout << " ActualPower = " << m_StorageSystemActualPower << std::endl;
}
}
SmartChargerXML::~SmartChargerXML()
{}
double SmartChargerXML::getSmartMeterActualPower(void)
{
return m_SmartMeterActualPower;
}
double SmartChargerXML::getSmartMeterConsumption(void)
{
return m_SmartMeterConsumption;
}
double SmartChargerXML::getSmartMeterSurplus(void)
{
return m_SmartMeterSurplus;
}
double SmartChargerXML::getEVEvaluationPoints(void)
{
return m_EVEvaluationPoints;
}
double SmartChargerXML::getEVState(void)
{
return m_EVState;
}
double SmartChargerXML::getEVPlug(void)
{
return m_EVPlug;
}
double SmartChargerXML::getEVSystemEnabled(void)
{
return m_EVSystemEnabled;
}
double SmartChargerXML::getEVActualPower(void)
{
return m_EVActualPower;
}
double SmartChargerXML::getEVSessionEnergy(void)
{
return m_EVSessionEnergy;
}
ulong SmartChargerXML::getEVTotalEnergy(void)
{
return m_EVTotalEnergy;
}
double SmartChargerXML::getStorageSystemSOC(void)
{
return m_StorageSystemSOC;
}
double SmartChargerXML::getStorageSystemTemperature(void)
{
return m_StorageSystemTemperature;
}
double SmartChargerXML::getStorageSystemActualPower(void)
{
return m_StorageSystemActualPower;
}
QString SmartChargerXML::getEVChargeMode(void)
{
return m_EVChargingMode;
}