-
Notifications
You must be signed in to change notification settings - Fork 1
/
WechselrichterJSON.cpp
207 lines (172 loc) · 7.3 KB
/
WechselrichterJSON.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
#include "WechselrichterJSON.h"
#include "Downloader.h"
WechselrichterJSON::WechselrichterJSON() {}
void WechselrichterJSON::ReadWechselrichterJSON() {
extern QString m_JSONfiledata; // globally defined in main.cpp, loaded with data by Downloader.cpp
// qDebug() << "m_JSONfiledata: " << m_JSONfiledata;
// ich mach es zu Fuss...
int position = 0;
int positionColon = 0;
int positionComma = 0;
if(!m_JSONfiledata.isEmpty())
{
// WR Garage
if ((position = m_JSONfiledata.indexOf("SUNSPEC1")) != -1) // "SUNSPEC1" gefunden
{
position = m_JSONfiledata.indexOf("\"Export", position);
positionColon = m_JSONfiledata.indexOf(":", position);
// if converters deliver 0 (zero), there is no "comma "," after "Export:", it's a "}"
positionComma = std::min(m_JSONfiledata.indexOf(",", positionColon), m_JSONfiledata.indexOf("}", positionColon));
QString exportGarage = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
qDebug() << "exportGarage: " << exportGarage;
m_PVGarageErtrag = exportGarage.toDouble();
m_PVGesamtErtrag = m_PVGarageErtrag;
if((position = m_JSONfiledata.indexOf("\"Power", position)) != -1)
{
positionColon = m_JSONfiledata.indexOf(":", position);
positionComma = m_JSONfiledata.indexOf(",", positionColon);
QString power = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
double dPower = power.toDouble();
qDebug() << "Power1: " << dPower;
m_PVGarageActualPower = dPower;
}
}
else
{
qDebug() << "Wechselrichter Garage ist ausgefallen";
m_messageFlag |= WRFlag;
}
// WR DachS
if ((position = m_JSONfiledata.indexOf("SUNSPEC2")) != -1) // "SUNSPEC2" gefunden
{
position = m_JSONfiledata.indexOf("\"Export", position);
positionColon = m_JSONfiledata.indexOf(":", position);
// if converters deliver 0 (zero), there is no "comma "," after "Export:", it's a "}"
positionComma = std::min(m_JSONfiledata.indexOf(",", positionColon), m_JSONfiledata.indexOf("}", positionColon));
QString exportDachS = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
qDebug() << "exportDachS: " << exportDachS;
m_PVDachSErtrag = exportDachS.toDouble();
m_PVGesamtErtrag += exportDachS.toDouble();
if((position = m_JSONfiledata.indexOf("\"Power", position)) != -1)
{
positionColon = m_JSONfiledata.indexOf(":", position);
positionComma = m_JSONfiledata.indexOf(",", positionColon);
QString power = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
double dPower = power.toDouble();
qDebug() << "Power2: " << dPower;
m_PVDachSActualPower = dPower;
}
}
else
{
qDebug() << "Wechselrichter DachS ist ausgefallen";
m_messageFlag |= WRFlag;
}
// WR Gaube
if ((position = m_JSONfiledata.indexOf("SUNSPEC3")) != -1) // "SUNSPEC3" gefunden
{
position = m_JSONfiledata.indexOf("\"Export", position);
positionColon = m_JSONfiledata.indexOf(":", position);
// if converters deliver 0 (zero), there is no "comma "," after "Export:", it's a "}"
if (m_JSONfiledata.indexOf(",", positionColon) != -1)
{
positionComma = std::min(m_JSONfiledata.indexOf(",", positionColon), m_JSONfiledata.indexOf("}", positionColon));
}
else
{
positionComma = m_JSONfiledata.indexOf("}", positionColon);
}
QString exportGaube = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
qDebug() << "exportGaube: " << exportGaube;
m_PVGaubeErtrag = exportGaube.toDouble();
m_PVGesamtErtrag += m_PVGaubeErtrag;
if((position = m_JSONfiledata.indexOf("\"Power", position)) != -1)
{
positionColon = m_JSONfiledata.indexOf(":", position);
positionComma = m_JSONfiledata.indexOf(",", positionColon);
QString power = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
double dPower = power.toDouble();
qDebug() << "Power3: " << dPower;
m_PVGaubeActualPower = dPower;
}
}
else
{
qDebug() << "Wechselrichter Gaube ist ausgefallen";
m_messageFlag |= WRFlag;
}
#ifdef WRDACHN
// WR DachN
if ((position = m_JSONfiledata.indexOf("SUNSPEC4")) != -1) // "SUNSPEC4" gefunden
{
position = m_JSONfiledata.indexOf("\"Export", position);
positionColon = m_JSONfiledata.indexOf(":", position);
// if converters deliver 0 (zero), there is no "comma "," after "Export:", it's a "}"
if (m_JSONfiledata.indexOf(",", positionColon) != -1)
{
positionComma = std::min(m_JSONfiledata.indexOf(",", positionColon), m_JSONfiledata.indexOf("}", positionColon));
}
else
{
positionComma = m_JSONfiledata.indexOf("}", positionColon);
}
QString exportDachN = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
qDebug() << "exportDachN: " << exportDachN;
m_PVDachNErtrag = exportDachN.toDouble();
m_PVGesamtErtrag += m_PVDachNErtrag;
if((position = m_JSONfiledata.indexOf("\"Power", position)) != -1)
{
positionColon = m_JSONfiledata.indexOf(":", position);
positionComma = m_JSONfiledata.indexOf(",", positionColon);
QString power = m_JSONfiledata.mid(positionColon + 1, positionComma - positionColon - 1);
double dPower = power.toDouble();
qDebug() << "Power4: " << dPower;
m_PVDachNActualPower = dPower;
}
}
else
{
qDebug() << "Wechselrichter DachN ist ausgefallen";
m_messageFlag |= WRFlag;
}
#endif
// m_messageFlag |= WRFlag; // Test für Debug!!
}
}
WechselrichterJSON::~WechselrichterJSON() {}
double WechselrichterJSON::getPVDachSActualPower(void)
{
return m_PVDachSActualPower;
};
double WechselrichterJSON::getPVDachNActualPower(void)
{
return m_PVDachNActualPower;
};
double WechselrichterJSON::getPVGaubeActualPower(void)
{
return m_PVGaubeActualPower;
};
double WechselrichterJSON::getPVGarageActualPower(void)
{
return m_PVGarageActualPower;
};
double WechselrichterJSON::getPVGesamtErtrag(void)
{
return m_PVGesamtErtrag;
};
double WechselrichterJSON::getPVDachNErtrag(void)
{
return m_PVDachNErtrag;
};
double WechselrichterJSON::getPVDachSErtrag(void)
{
return m_PVDachSErtrag;
};
double WechselrichterJSON::getPVGaubeErtrag(void)
{
return m_PVGaubeErtrag;
};
double WechselrichterJSON::getPVGarageErtrag(void)
{
return m_PVGarageErtrag;
};