55 */
66
77#include " AmsData.h"
8+ #include < algorithm>
89
910AmsData::AmsData () {}
1011
@@ -17,7 +18,6 @@ void AmsData::apply(AmsData& other) {
1718 uint32_t power = (activeImportPower + other.getActiveImportPower ()) / 2 ;
1819 float add = power * (((float ) ms) / 3600000.0 );
1920 activeImportCounter += add / 1000.0 ;
20- // Serial.printf("%dW, %dms, %.6fkWh added\n", other.getActiveImportPower(), ms, add);
2121 }
2222
2323 if (other.getListType () > 1 ) {
@@ -112,7 +112,7 @@ void AmsData::apply(AmsData& other) {
112112 this ->activeExportPower = other.getActiveExportPower ();
113113}
114114
115- void AmsData::apply (OBIS_code_t obis, double value) {
115+ void AmsData::apply (OBIS_code_t obis, double value, uint64_t millis64 ) {
116116 if (obis.sensor == 0 && obis.gr == 0 && obis.tariff == 0 ) {
117117 meterType = value;
118118 }
@@ -127,138 +127,137 @@ void AmsData::apply(OBIS_code_t obis, double value) {
127127 }
128128 }
129129 if (obis.tariff != 0 ) {
130- Serial.println (" Tariff not implemented" );
131130 return ;
132131 }
133132 if (obis.gr == 7 ) { // Instant values
134133 switch (obis.sensor ) {
135134 case 1 :
136135 activeImportPower = value;
137- listType = max (listType, (uint8_t ) 2 );
136+ listType = std:: max (listType, (uint8_t ) 2 );
138137 break ;
139138 case 2 :
140139 activeExportPower = value;
141- listType = max (listType, (uint8_t ) 2 );
140+ listType = std:: max (listType, (uint8_t ) 2 );
142141 break ;
143142 case 3 :
144143 reactiveImportPower = value;
145- listType = max (listType, (uint8_t ) 2 );
144+ listType = std:: max (listType, (uint8_t ) 2 );
146145 break ;
147146 case 4 :
148147 reactiveExportPower = value;
149- listType = max (listType, (uint8_t ) 2 );
148+ listType = std:: max (listType, (uint8_t ) 2 );
150149 break ;
151150 case 13 :
152151 powerFactor = value;
153- listType = max (listType, (uint8_t ) 4 );
152+ listType = std:: max (listType, (uint8_t ) 4 );
154153 break ;
155154 case 21 :
156155 l1activeImportPower = value;
157- listType = max (listType, (uint8_t ) 4 );
156+ listType = std:: max (listType, (uint8_t ) 4 );
158157 break ;
159158 case 22 :
160159 l1activeExportPower = value;
161- listType = max (listType, (uint8_t ) 4 );
160+ listType = std:: max (listType, (uint8_t ) 4 );
162161 break ;
163162 case 31 :
164163 l1current = value;
165- listType = max (listType, (uint8_t ) 2 );
164+ listType = std:: max (listType, (uint8_t ) 2 );
166165 break ;
167166 case 32 :
168167 l1voltage = value;
169- listType = max (listType, (uint8_t ) 2 );
168+ listType = std:: max (listType, (uint8_t ) 2 );
170169 break ;
171170 case 33 :
172171 l1PowerFactor = value;
173- listType = max (listType, (uint8_t ) 4 );
172+ listType = std:: max (listType, (uint8_t ) 4 );
174173 break ;
175174 case 41 :
176175 l2activeImportPower = value;
177- listType = max (listType, (uint8_t ) 4 );
176+ listType = std:: max (listType, (uint8_t ) 4 );
178177 break ;
179178 case 42 :
180179 l2activeExportPower = value;
181- listType = max (listType, (uint8_t ) 4 );
180+ listType = std:: max (listType, (uint8_t ) 4 );
182181 break ;
183182 case 51 :
184183 l2current = value;
185- listType = max (listType, (uint8_t ) 2 );
184+ listType = std:: max (listType, (uint8_t ) 2 );
186185 break ;
187186 case 52 :
188187 l2voltage = value;
189- listType = max (listType, (uint8_t ) 2 );
188+ listType = std:: max (listType, (uint8_t ) 2 );
190189 break ;
191190 case 53 :
192191 l2PowerFactor = value;
193- listType = max (listType, (uint8_t ) 4 );
192+ listType = std:: max (listType, (uint8_t ) 4 );
194193 break ;
195194 case 61 :
196195 l3activeImportPower = value;
197- listType = max (listType, (uint8_t ) 4 );
196+ listType = std:: max (listType, (uint8_t ) 4 );
198197 break ;
199198 case 62 :
200199 l3activeExportPower = value;
201- listType = max (listType, (uint8_t ) 4 );
200+ listType = std:: max (listType, (uint8_t ) 4 );
202201 break ;
203202 case 71 :
204203 l3current = value;
205- listType = max (listType, (uint8_t ) 2 );
204+ listType = std:: max (listType, (uint8_t ) 2 );
206205 break ;
207206 case 72 :
208207 l3voltage = value;
209- listType = max (listType, (uint8_t ) 2 );
208+ listType = std:: max (listType, (uint8_t ) 2 );
210209 break ;
211210 case 73 :
212211 l3PowerFactor = value;
213- listType = max (listType, (uint8_t ) 4 );
212+ listType = std:: max (listType, (uint8_t ) 4 );
214213 break ;
215214 }
216215 } else if (obis.gr == 8 ) { // Accumulated values
217216 switch (obis.sensor ) {
218217 case 1 :
219218 activeImportCounter = value;
220- listType = max (listType, (uint8_t ) 3 );
219+ listType = std:: max (listType, (uint8_t ) 3 );
221220 break ;
222221 case 2 :
223222 activeExportCounter = value;
224- listType = max (listType, (uint8_t ) 3 );
223+ listType = std:: max (listType, (uint8_t ) 3 );
225224 break ;
226225 case 3 :
227226 reactiveImportCounter = value;
228- listType = max (listType, (uint8_t ) 3 );
227+ listType = std:: max (listType, (uint8_t ) 3 );
229228 break ;
230229 case 4 :
231230 reactiveExportCounter = value;
232- listType = max (listType, (uint8_t ) 3 );
231+ listType = std:: max (listType, (uint8_t ) 3 );
233232 break ;
234233 case 21 :
235234 l1activeImportCounter = value;
236- listType = max (listType, (uint8_t ) 4 );
235+ listType = std:: max (listType, (uint8_t ) 4 );
237236 break ;
238237 case 22 :
239238 l1activeExportCounter = value;
240- listType = max (listType, (uint8_t ) 4 );
239+ listType = std:: max (listType, (uint8_t ) 4 );
241240 break ;
242241 case 41 :
243242 l2activeImportCounter = value;
244- listType = max (listType, (uint8_t ) 4 );
243+ listType = std:: max (listType, (uint8_t ) 4 );
245244 break ;
246245 case 42 :
247246 l2activeExportCounter = value;
248- listType = max (listType, (uint8_t ) 4 );
247+ listType = std:: max (listType, (uint8_t ) 4 );
249248 break ;
250249 case 61 :
251250 l3activeImportCounter = value;
252- listType = max (listType, (uint8_t ) 4 );
251+ listType = std:: max (listType, (uint8_t ) 4 );
253252 break ;
254253 case 62 :
255254 l3activeExportCounter = value;
256- listType = max (listType, (uint8_t ) 4 );
255+ listType = std:: max (listType, (uint8_t ) 4 );
257256 break ;
258257 }
259258 }
260259 if (listType > 0 )
261- lastUpdateMillis = millis () ;
260+ lastUpdateMillis = millis64 ;
262261
263262 threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0 ;
264263 if (!threePhase)
0 commit comments