ClassFlowPostProcessing.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. #include "ClassFlowPostProcessing.h"
  2. #include "Helper.h"
  3. #include "ClassFlowTakeImage.h"
  4. #include "ClassLogFile.h"
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <time.h>
  8. #include "time_sntp.h"
  9. #include "esp_log.h"
  10. #include "../../include/defines.h"
  11. static const char* TAG = "POSTPROC";
  12. std::string ClassFlowPostProcessing::getNumbersName()
  13. {
  14. std::string ret="";
  15. for (int i = 0; i < NUMBERS.size(); ++i)
  16. {
  17. ret += NUMBERS[i]->name;
  18. if (i < NUMBERS.size()-1)
  19. ret = ret + "\t";
  20. }
  21. // ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str());
  22. return ret;
  23. }
  24. std::string ClassFlowPostProcessing::GetJSON(std::string _lineend)
  25. {
  26. std::string json="{" + _lineend;
  27. for (int i = 0; i < NUMBERS.size(); ++i)
  28. {
  29. json += "\"" + NUMBERS[i]->name + "\":" + _lineend;
  30. json += getJsonFromNumber(i, _lineend) + _lineend;
  31. if ((i+1) < NUMBERS.size())
  32. json += "," + _lineend;
  33. }
  34. json += "}";
  35. return json;
  36. }
  37. string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _lineend) {
  38. std::string json = "";
  39. json += " {" + _lineend;
  40. if (NUMBERS[i]->ReturnValue.length() > 0)
  41. json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend;
  42. else
  43. json += " \"value\": \"\"," + _lineend;
  44. json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend;
  45. json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend;
  46. json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend;
  47. if (NUMBERS[i]->ReturnRateValue.length() > 0)
  48. json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend;
  49. else
  50. json += " \"rate\": \"\"," + _lineend;
  51. json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend;
  52. json += " }" + _lineend;
  53. return json;
  54. }
  55. string ClassFlowPostProcessing::GetPreValue(std::string _number)
  56. {
  57. std::string result;
  58. int index = -1;
  59. if (_number == "")
  60. _number = "default";
  61. for (int i = 0; i < NUMBERS.size(); ++i)
  62. if (NUMBERS[i]->name == _number)
  63. index = i;
  64. if (index == -1)
  65. return std::string("");
  66. result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma);
  67. return result;
  68. }
  69. bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern)
  70. {
  71. //ESP_LOGD(TAG, "SetPrevalue: %f, %s", zw, _numbers.c_str());
  72. for (int j = 0; j < NUMBERS.size(); ++j) {
  73. //ESP_LOGD(TAG, "Number %d, %s", j, NUMBERS[j]->name.c_str());
  74. if (NUMBERS[j]->name == _numbers) {
  75. if (_newvalue >= 0) { // if new value posivive, use provided value to preset PreValue
  76. NUMBERS[j]->PreValue = _newvalue;
  77. }
  78. else { // if new value negative, use last raw value to preset PreValue
  79. char* p;
  80. double ReturnRawValueAsDouble = strtod(NUMBERS[j]->ReturnRawValue.c_str(), &p);
  81. if (ReturnRawValueAsDouble == 0) {
  82. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: "
  83. + NUMBERS[j]->ReturnRawValue);
  84. return false;
  85. }
  86. NUMBERS[j]->PreValue = ReturnRawValueAsDouble;
  87. }
  88. NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue);
  89. NUMBERS[j]->PreValueOkay = true;
  90. if (_extern)
  91. {
  92. time(&(NUMBERS[j]->lastvalue));
  93. localtime(&(NUMBERS[j]->lastvalue));
  94. }
  95. //ESP_LOGD(TAG, "Found %d! - set to %.8f", j, NUMBERS[j]->PreValue);
  96. UpdatePreValueINI = true; // Only update prevalue file if a new value is set
  97. SavePreValue();
  98. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " +
  99. std::to_string(NUMBERS[j]->PreValue));
  100. return true;
  101. }
  102. }
  103. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: Numbersname not found or not valid");
  104. return false; // No new value was set (e.g. wrong numbersname, no numbers at all)
  105. }
  106. bool ClassFlowPostProcessing::LoadPreValue(void)
  107. {
  108. std::vector<string> splitted;
  109. FILE* pFile;
  110. char zw[1024];
  111. string zwtime, zwvalue, name;
  112. bool _done = false;
  113. UpdatePreValueINI = false; // Conversion to the new format
  114. pFile = fopen(FilePreValue.c_str(), "r");
  115. if (pFile == NULL)
  116. return false;
  117. fgets(zw, 1024, pFile);
  118. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
  119. zwtime = trim(std::string(zw));
  120. if (zwtime.length() == 0)
  121. return false;
  122. splitted = HelperZerlegeZeile(zwtime, "\t");
  123. if (splitted.size() > 1) // Conversion to the new format
  124. {
  125. while ((splitted.size() > 1) && !_done)
  126. {
  127. name = trim(splitted[0]);
  128. zwtime = trim(splitted[1]);
  129. zwvalue = trim(splitted[2]);
  130. for (int j = 0; j < NUMBERS.size(); ++j)
  131. {
  132. if (NUMBERS[j]->name == name)
  133. {
  134. NUMBERS[j]->PreValue = stod(zwvalue.c_str());
  135. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // To be on the safe side, 1 digit more, as Exgtended Resolution may be on (will only be set during the first run).
  136. time_t tStart;
  137. int yy, month, dd, hh, mm, ss;
  138. struct tm whenStart;
  139. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  140. whenStart.tm_year = yy - 1900;
  141. whenStart.tm_mon = month - 1;
  142. whenStart.tm_mday = dd;
  143. whenStart.tm_hour = hh;
  144. whenStart.tm_min = mm;
  145. whenStart.tm_sec = ss;
  146. whenStart.tm_isdst = -1;
  147. NUMBERS[j]->lastvalue = mktime(&whenStart);
  148. time(&tStart);
  149. localtime(&tStart);
  150. double difference = difftime(tStart, NUMBERS[j]->lastvalue);
  151. difference /= 60;
  152. if (difference > PreValueAgeStartup)
  153. NUMBERS[j]->PreValueOkay = false;
  154. else
  155. NUMBERS[j]->PreValueOkay = true;
  156. }
  157. }
  158. if (!fgets(zw, 1024, pFile))
  159. _done = true;
  160. else
  161. {
  162. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
  163. splitted = HelperZerlegeZeile(trim(std::string(zw)), "\t");
  164. if (splitted.size() > 1)
  165. {
  166. name = trim(splitted[0]);
  167. zwtime = trim(splitted[1]);
  168. zwvalue = trim(splitted[2]);
  169. }
  170. }
  171. }
  172. fclose(pFile);
  173. }
  174. else // Old Format
  175. {
  176. fgets(zw, 1024, pFile);
  177. fclose(pFile);
  178. ESP_LOGD(TAG, "%s", zw);
  179. zwvalue = trim(std::string(zw));
  180. NUMBERS[0]->PreValue = stod(zwvalue.c_str());
  181. time_t tStart;
  182. int yy, month, dd, hh, mm, ss;
  183. struct tm whenStart;
  184. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  185. whenStart.tm_year = yy - 1900;
  186. whenStart.tm_mon = month - 1;
  187. whenStart.tm_mday = dd;
  188. whenStart.tm_hour = hh;
  189. whenStart.tm_min = mm;
  190. whenStart.tm_sec = ss;
  191. whenStart.tm_isdst = -1;
  192. ESP_LOGD(TAG, "TIME: %d, %d, %d, %d, %d, %d", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec);
  193. NUMBERS[0]->lastvalue = mktime(&whenStart);
  194. time(&tStart);
  195. localtime(&tStart);
  196. double difference = difftime(tStart, NUMBERS[0]->lastvalue);
  197. difference /= 60;
  198. if (difference > PreValueAgeStartup)
  199. return false;
  200. NUMBERS[0]->Value = NUMBERS[0]->PreValue;
  201. NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
  202. if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
  203. {
  204. NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma);
  205. }
  206. UpdatePreValueINI = true; // Conversion to the new format
  207. SavePreValue();
  208. }
  209. return true;
  210. }
  211. void ClassFlowPostProcessing::SavePreValue()
  212. {
  213. FILE* pFile;
  214. string _zw;
  215. if (!UpdatePreValueINI) // PreValues unchanged --> File does not have to be rewritten
  216. return;
  217. pFile = fopen(FilePreValue.c_str(), "w");
  218. for (int j = 0; j < NUMBERS.size(); ++j)
  219. {
  220. char buffer[80];
  221. struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue);
  222. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  223. NUMBERS[j]->timeStamp = std::string(buffer);
  224. NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->lastvalue;
  225. // ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  226. _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n";
  227. ESP_LOGD(TAG, "Write PreValue line: %s", _zw.c_str());
  228. if (pFile) {
  229. fputs(_zw.c_str(), pFile);
  230. }
  231. }
  232. UpdatePreValueINI = false;
  233. fclose(pFile);
  234. }
  235. ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit)
  236. {
  237. PreValueUse = false;
  238. PreValueAgeStartup = 30;
  239. ErrorMessage = false;
  240. ListFlowControll = NULL;
  241. FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
  242. ListFlowControll = lfc;
  243. flowTakeImage = NULL;
  244. UpdatePreValueINI = false;
  245. IgnoreLeadingNaN = false;
  246. flowAnalog = _analog;
  247. flowDigit = _digit;
  248. for (int i = 0; i < ListFlowControll->size(); ++i)
  249. {
  250. if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0)
  251. {
  252. flowTakeImage = (ClassFlowTakeImage*) (*ListFlowControll)[i];
  253. }
  254. }
  255. }
  256. void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, string _value)
  257. {
  258. string _digit, _decpos;
  259. int _pospunkt = _decsep.find_first_of(".");
  260. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  261. if (_pospunkt > -1)
  262. _digit = _decsep.substr(0, _pospunkt);
  263. else
  264. _digit = "default";
  265. for (int j = 0; j < NUMBERS.size(); ++j)
  266. {
  267. bool _zwdc = false;
  268. if (toUpper(_value) == "TRUE")
  269. _zwdc = true;
  270. if (_digit == "default") // Set to default first (if nothing else is set)
  271. {
  272. NUMBERS[j]->isExtendedResolution = _zwdc;
  273. }
  274. if (NUMBERS[j]->name == _digit)
  275. {
  276. NUMBERS[j]->isExtendedResolution = _zwdc;
  277. }
  278. }
  279. }
  280. void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value)
  281. {
  282. string _digit, _decpos;
  283. int _pospunkt = _decsep.find_first_of(".");
  284. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  285. if (_pospunkt > -1)
  286. _digit = _decsep.substr(0, _pospunkt);
  287. else
  288. _digit = "default";
  289. for (int j = 0; j < NUMBERS.size(); ++j)
  290. {
  291. int _zwdc = 0;
  292. // try
  293. {
  294. _zwdc = stoi(_value);
  295. }
  296. /* catch(const std::exception& e)
  297. {
  298. ESP_LOGD(TAG, "ERROR - Decimalshift is not a number: %s", _value.c_str());
  299. }
  300. */
  301. if (_digit == "default") // Set to default first (if nothing else is set)
  302. {
  303. NUMBERS[j]->DecimalShift = _zwdc;
  304. NUMBERS[j]->DecimalShiftInitial = _zwdc;
  305. }
  306. if (NUMBERS[j]->name == _digit)
  307. {
  308. NUMBERS[j]->DecimalShift = _zwdc;
  309. NUMBERS[j]->DecimalShiftInitial = _zwdc;
  310. }
  311. NUMBERS[j]->Nachkomma = NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift;
  312. }
  313. }
  314. void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value)
  315. {
  316. string _digit, _decpos;
  317. int _pospunkt = _decsep.find_first_of(".");
  318. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  319. if (_pospunkt > -1)
  320. _digit = _decsep.substr(0, _pospunkt);
  321. else
  322. _digit = "default";
  323. for (int j = 0; j < NUMBERS.size(); ++j)
  324. {
  325. float _zwdc = 9.2;
  326. {
  327. _zwdc = stof(_value);
  328. }
  329. if (_digit == "default" || NUMBERS[j]->name == _digit) // Set to default first (if nothing else is set)
  330. {
  331. NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc;
  332. }
  333. }
  334. }
  335. void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _value)
  336. {
  337. string _digit, _decpos;
  338. int _pospunkt = _decsep.find_first_of(".");
  339. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  340. if (_pospunkt > -1)
  341. _digit = _decsep.substr(0, _pospunkt);
  342. else
  343. _digit = "default";
  344. for (int j = 0; j < NUMBERS.size(); ++j)
  345. {
  346. bool _rt = false;
  347. if (toUpper(_value) == "TRUE")
  348. _rt = true;
  349. if (_digit == "default") // Set to default first (if nothing else is set)
  350. {
  351. NUMBERS[j]->AllowNegativeRates = _rt;
  352. }
  353. if (NUMBERS[j]->name == _digit)
  354. {
  355. NUMBERS[j]->AllowNegativeRates = _rt;
  356. }
  357. }
  358. }
  359. void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value)
  360. {
  361. string _digit, _decpos;
  362. int _pospunkt = _decsep.find_first_of(".");
  363. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  364. if (_pospunkt > -1)
  365. _digit = _decsep.substr(0, _pospunkt);
  366. else
  367. _digit = "default";
  368. for (int j = 0; j < NUMBERS.size(); ++j)
  369. {
  370. t_RateType _rt = AbsoluteChange;
  371. if (toUpper(_value) == "RATECHANGE")
  372. _rt = RateChange;
  373. if (_digit == "default") // Set to default first (if nothing else is set)
  374. {
  375. NUMBERS[j]->RateType = _rt;
  376. }
  377. if (NUMBERS[j]->name == _digit)
  378. {
  379. NUMBERS[j]->RateType = _rt;
  380. }
  381. }
  382. }
  383. void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value)
  384. {
  385. string _digit, _decpos;
  386. int _pospunkt = _decsep.find_first_of(".");
  387. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  388. if (_pospunkt > -1)
  389. _digit = _decsep.substr(0, _pospunkt);
  390. else
  391. _digit = "default";
  392. for (int j = 0; j < NUMBERS.size(); ++j)
  393. {
  394. float _zwdc = 1;
  395. // try
  396. {
  397. _zwdc = stof(_value);
  398. }
  399. /* catch(const std::exception& e)
  400. {
  401. ESP_LOGD(TAG, "ERROR - MaxRateValue is not a number: %s", _value.c_str());
  402. }
  403. */
  404. if (_digit == "default") // Set to default first (if nothing else is set)
  405. {
  406. NUMBERS[j]->useMaxRateValue = true;
  407. NUMBERS[j]->MaxRateValue = _zwdc;
  408. }
  409. if (NUMBERS[j]->name == _digit)
  410. {
  411. NUMBERS[j]->useMaxRateValue = true;
  412. NUMBERS[j]->MaxRateValue = _zwdc;
  413. }
  414. }
  415. }
  416. bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
  417. {
  418. std::vector<string> splitted;
  419. int _n;
  420. aktparamgraph = trim(aktparamgraph);
  421. if (aktparamgraph.size() == 0)
  422. if (!this->GetNextParagraph(pfile, aktparamgraph))
  423. return false;
  424. if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph does not fit PostProcessing
  425. return false;
  426. InitNUMBERS();
  427. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  428. {
  429. splitted = ZerlegeZeile(aktparamgraph);
  430. std::string _param = GetParameterName(splitted[0]);
  431. if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (splitted.size() > 1))
  432. {
  433. handleDecimalExtendedResolution(splitted[0], splitted[1]);
  434. }
  435. if ((toUpper(_param) == "DECIMALSHIFT") && (splitted.size() > 1))
  436. {
  437. handleDecimalSeparator(splitted[0], splitted[1]);
  438. }
  439. if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (splitted.size() > 1))
  440. {
  441. handleAnalogDigitalTransitionStart(splitted[0], splitted[1]);
  442. }
  443. if ((toUpper(_param) == "MAXRATEVALUE") && (splitted.size() > 1))
  444. {
  445. handleMaxRateValue(splitted[0], splitted[1]);
  446. }
  447. if ((toUpper(_param) == "MAXRATETYPE") && (splitted.size() > 1))
  448. {
  449. handleMaxRateType(splitted[0], splitted[1]);
  450. }
  451. if ((toUpper(_param) == "PREVALUEUSE") && (splitted.size() > 1))
  452. {
  453. if (toUpper(splitted[1]) == "TRUE")
  454. {
  455. PreValueUse = true;
  456. }
  457. }
  458. if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1))
  459. {
  460. if (toUpper(splitted[1]) == "TRUE")
  461. for (_n = 0; _n < NUMBERS.size(); ++_n)
  462. NUMBERS[_n]->checkDigitIncreaseConsistency = true;
  463. }
  464. if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1))
  465. {
  466. handleAllowNegativeRate(splitted[0], splitted[1]);
  467. /* Updated to allow individual Settings
  468. if (toUpper(splitted[1]) == "TRUE")
  469. for (_n = 0; _n < NUMBERS.size(); ++_n)
  470. NUMBERS[_n]->AllowNegativeRates = true;
  471. */
  472. }
  473. if ((toUpper(_param) == "ERRORMESSAGE") && (splitted.size() > 1))
  474. {
  475. if (toUpper(splitted[1]) == "TRUE")
  476. ErrorMessage = true;
  477. }
  478. if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1))
  479. {
  480. if (toUpper(splitted[1]) == "TRUE")
  481. IgnoreLeadingNaN = true;
  482. }
  483. if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1))
  484. {
  485. PreValueAgeStartup = std::stoi(splitted[1]);
  486. }
  487. }
  488. if (PreValueUse) {
  489. LoadPreValue();
  490. }
  491. return true;
  492. }
  493. void ClassFlowPostProcessing::InitNUMBERS()
  494. {
  495. int anzDIGIT = 0;
  496. int anzANALOG = 0;
  497. std::vector<std::string> name_numbers;
  498. if (flowDigit)
  499. {
  500. anzDIGIT = flowDigit->getNumberGENERAL();
  501. flowDigit->UpdateNameNumbers(&name_numbers);
  502. }
  503. if (flowAnalog)
  504. {
  505. anzANALOG = flowAnalog->getNumberGENERAL();
  506. flowAnalog->UpdateNameNumbers(&name_numbers);
  507. }
  508. ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG);
  509. for (int _num = 0; _num < name_numbers.size(); ++_num)
  510. {
  511. NumberPost *_number = new NumberPost;
  512. _number->name = name_numbers[_num];
  513. _number->digit_roi = NULL;
  514. if (flowDigit)
  515. _number->digit_roi = flowDigit->FindGENERAL(name_numbers[_num]);
  516. if (_number->digit_roi)
  517. _number->AnzahlDigital = _number->digit_roi->ROI.size();
  518. else
  519. _number->AnzahlDigital = 0;
  520. _number->analog_roi = NULL;
  521. if (flowAnalog)
  522. _number->analog_roi = flowAnalog->FindGENERAL(name_numbers[_num]);
  523. if (_number->analog_roi)
  524. _number->AnzahlAnalog = _number->analog_roi->ROI.size();
  525. else
  526. _number->AnzahlAnalog = 0;
  527. _number->ReturnRawValue = ""; // Raw value (with N & leading 0).
  528. _number->ReturnValue = ""; // corrected return value, possibly with error message
  529. _number->ErrorMessageText = ""; // Error message for consistency check
  530. _number->ReturnPreValue = "";
  531. _number->PreValueOkay = false;
  532. _number->AllowNegativeRates = false;
  533. _number->MaxRateValue = 0.1;
  534. _number->RateType = AbsoluteChange;
  535. _number->useMaxRateValue = false;
  536. _number->checkDigitIncreaseConsistency = false;
  537. _number->DecimalShift = 0;
  538. _number->DecimalShiftInitial = 0;
  539. _number->isExtendedResolution = false;
  540. _number->AnalogDigitalTransitionStart=9.2;
  541. _number->FlowRateAct = 0; // m3 / min
  542. _number->PreValue = 0; // last value read out well
  543. _number->Value = 0; // last value read out, incl. corrections
  544. _number->ReturnRawValue = ""; // raw value (with N & leading 0)
  545. _number->ReturnValue = ""; // corrected return value, possibly with error message
  546. _number->ErrorMessageText = ""; // Error message for consistency check
  547. _number->Nachkomma = _number->AnzahlAnalog;
  548. NUMBERS.push_back(_number);
  549. }
  550. for (int i = 0; i < NUMBERS.size(); ++i) {
  551. ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog);
  552. }
  553. }
  554. string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
  555. if (_decShift == 0){
  556. return in;
  557. }
  558. int _pos_dec_org, _pos_dec_neu;
  559. _pos_dec_org = findDelimiterPos(in, ".");
  560. if (_pos_dec_org == std::string::npos) {
  561. _pos_dec_org = in.length();
  562. }
  563. else
  564. {
  565. in = in.erase(_pos_dec_org, 1);
  566. }
  567. _pos_dec_neu = _pos_dec_org + _decShift;
  568. if (_pos_dec_neu <= 0) { // comma is before the first digit
  569. for (int i = 0; i > _pos_dec_neu; --i){
  570. in = in.insert(0, "0");
  571. }
  572. in = "0." + in;
  573. return in;
  574. }
  575. if (_pos_dec_neu > in.length()){ // Comma should be after string (123 --> 1230)
  576. for (int i = in.length(); i < _pos_dec_neu; ++i){
  577. in = in.insert(in.length(), "0");
  578. }
  579. return in;
  580. }
  581. string zw;
  582. zw = in.substr(0, _pos_dec_neu);
  583. zw = zw + ".";
  584. zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  585. return zw;
  586. }
  587. bool ClassFlowPostProcessing::doFlow(string zwtime)
  588. {
  589. string result = "";
  590. string digit = "";
  591. string analog = "";
  592. string zwvalue;
  593. string zw;
  594. time_t imagetime = 0;
  595. string rohwert;
  596. // Update decimal point, as the decimal places can also change when changing from CNNType Auto --> xyz:
  597. imagetime = flowTakeImage->getTimeImageTaken();
  598. if (imagetime == 0)
  599. time(&imagetime);
  600. struct tm* timeinfo;
  601. timeinfo = localtime(&imagetime);
  602. char strftime_buf[64];
  603. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  604. zwtime = std::string(strftime_buf);
  605. ESP_LOGD(TAG, "Quantity NUMBERS: %d", NUMBERS.size());
  606. for (int j = 0; j < NUMBERS.size(); ++j)
  607. {
  608. NUMBERS[j]->ReturnRawValue = "";
  609. NUMBERS[j]->ReturnRateValue = "";
  610. NUMBERS[j]->ReturnValue = "";
  611. NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(0.0, NUMBERS[j]->Nachkomma); // always reset change absolute
  612. NUMBERS[j]->ErrorMessageText = "";
  613. NUMBERS[j]->Value = -1;
  614. /* calculate time difference BEFORE we overwrite the 'lastvalue' */
  615. double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in seconds
  616. /* TODO:
  617. * We could call `NUMBERS[j]->lastvalue = imagetime;` here and remove all other such calls further down.
  618. * But we should check nothing breaks! */
  619. UpdateNachkommaDecimalShift();
  620. int previous_value = -1;
  621. if (NUMBERS[j]->analog_roi)
  622. {
  623. NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution);
  624. if (NUMBERS[j]->ReturnRawValue.length() > 0)
  625. {
  626. char zw = NUMBERS[j]->ReturnRawValue[0];
  627. if (zw >= 48 && zw <=57)
  628. previous_value = zw - 48;
  629. }
  630. }
  631. #ifdef SERIAL_DEBUG
  632. ESP_LOGD(TAG, "After analog->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  633. #endif
  634. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  635. NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue;
  636. if (NUMBERS[j]->digit_roi)
  637. {
  638. if (NUMBERS[j]->analog_roi)
  639. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue;
  640. else
  641. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits
  642. }
  643. #ifdef SERIAL_DEBUG
  644. ESP_LOGD(TAG, "After digital->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  645. #endif
  646. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  647. #ifdef SERIAL_DEBUG
  648. ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  649. #endif
  650. if (IgnoreLeadingNaN)
  651. while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N'))
  652. NUMBERS[j]->ReturnRawValue.erase(0, 1);
  653. #ifdef SERIAL_DEBUG
  654. ESP_LOGD(TAG, "After IgnoreLeadingNaN: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  655. #endif
  656. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
  657. if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos)
  658. {
  659. if (PreValueUse && NUMBERS[j]->PreValueOkay)
  660. {
  661. NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue);
  662. }
  663. else
  664. {
  665. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  666. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  667. /* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */
  668. NUMBERS[j]->lastvalue = imagetime;
  669. WriteDataLog(j);
  670. continue; // there is no number because there is still an N.
  671. }
  672. }
  673. #ifdef SERIAL_DEBUG
  674. ESP_LOGD(TAG, "After findDelimiterPos: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str());
  675. #endif
  676. // Delete leading zeros (unless there is only one 0 left)
  677. while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
  678. NUMBERS[j]->ReturnValue.erase(0, 1);
  679. #ifdef SERIAL_DEBUG
  680. ESP_LOGD(TAG, "After removeLeadingZeros: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str());
  681. #endif
  682. NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue);
  683. #ifdef SERIAL_DEBUG
  684. ESP_LOGD(TAG, "After setting the Value: Value %f and as double is %f", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue));
  685. #endif
  686. if (NUMBERS[j]->checkDigitIncreaseConsistency)
  687. {
  688. if (flowDigit)
  689. {
  690. if (flowDigit->getCNNType() != Digital)
  691. ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)");
  692. else
  693. NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
  694. }
  695. else
  696. {
  697. #ifdef SERIAL_DEBUG
  698. ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digital numbers defined!");
  699. #endif
  700. }
  701. }
  702. #ifdef SERIAL_DEBUG
  703. ESP_LOGD(TAG, "After checkDigitIncreaseConsistency: Value %f", NUMBERS[j]->Value);
  704. #endif
  705. if (!NUMBERS[j]->AllowNegativeRates)
  706. {
  707. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name);
  708. if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  709. {
  710. // more debug if extended resolution is on, see #2447
  711. if (NUMBERS[j]->isExtendedResolution) {
  712. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value)
  713. + ", preValue=" + std::to_string(NUMBERS[j]->PreValue)
  714. + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))));
  715. }
  716. // Include inaccuracy of 0.2 for isExtendedResolution.
  717. if ((NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution)
  718. // not extended resolution allows -1 on the lowest digit
  719. || (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(1/pow(10, NUMBERS[j]->Nachkomma))) && !NUMBERS[j]->isExtendedResolution)) {
  720. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  721. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
  722. }
  723. else {
  724. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
  725. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  726. NUMBERS[j]->ReturnValue = "";
  727. NUMBERS[j]->lastvalue = imagetime;
  728. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  729. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  730. WriteDataLog(j);
  731. continue;
  732. }
  733. }
  734. }
  735. #ifdef SERIAL_DEBUG
  736. ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value);
  737. #endif
  738. difference /= 60;
  739. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  740. NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct);
  741. if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
  742. {
  743. double _ratedifference;
  744. if (NUMBERS[j]->RateType == RateChange)
  745. _ratedifference = NUMBERS[j]->FlowRateAct;
  746. else
  747. _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue);
  748. if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
  749. {
  750. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + RundeOutput(_ratedifference, NUMBERS[j]->Nachkomma);
  751. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  752. NUMBERS[j]->ReturnValue = "";
  753. NUMBERS[j]->ReturnRateValue = "";
  754. NUMBERS[j]->lastvalue = imagetime;
  755. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  756. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  757. WriteDataLog(j);
  758. continue;
  759. }
  760. }
  761. #ifdef SERIAL_DEBUG
  762. ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value);
  763. #endif
  764. NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  765. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  766. NUMBERS[j]->PreValueOkay = true;
  767. NUMBERS[j]->lastvalue = imagetime;
  768. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  769. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  770. NUMBERS[j]->ErrorMessageText = "no error";
  771. UpdatePreValueINI = true;
  772. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  773. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  774. WriteDataLog(j);
  775. }
  776. SavePreValue();
  777. return true;
  778. }
  779. void ClassFlowPostProcessing::WriteDataLog(int _index)
  780. {
  781. if (!LogFile.GetDataLogToSD()){
  782. return;
  783. }
  784. string analog = "";
  785. string digital = "";
  786. string timezw = "";
  787. char buffer[80];
  788. struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue);
  789. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  790. timezw = std::string(buffer);
  791. if (flowAnalog)
  792. analog = flowAnalog->getReadoutRawString(_index);
  793. if (flowDigit)
  794. digital = flowDigit->getReadoutRawString(_index);
  795. LogFile.WriteToData(timezw, NUMBERS[_index]->name,
  796. NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  797. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute,
  798. NUMBERS[_index]->ErrorMessageText,
  799. digital, analog);
  800. ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digital.c_str(), analog.c_str());
  801. }
  802. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  803. {
  804. for (int j = 0; j < NUMBERS.size(); ++j)
  805. {
  806. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits
  807. {
  808. // ESP_LOGD(TAG, "Nurdigital");
  809. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  810. if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  811. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  812. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  813. }
  814. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  815. {
  816. // ESP_LOGD(TAG, "Nur analog");
  817. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  818. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  819. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  820. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  821. }
  822. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog
  823. {
  824. // ESP_LOGD(TAG, "Nur digital + analog");
  825. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  826. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  827. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  828. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1;
  829. }
  830. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift);
  831. }
  832. }
  833. string ClassFlowPostProcessing::getReadout(int _number)
  834. {
  835. return NUMBERS[_number]->ReturnValue;
  836. }
  837. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  838. {
  839. if (_rawValue)
  840. return NUMBERS[_number]->ReturnRawValue;
  841. if (_noerror)
  842. return NUMBERS[_number]->ReturnValue;
  843. return NUMBERS[_number]->ReturnValue;
  844. }
  845. string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
  846. {
  847. int posN, posPunkt;
  848. int pot, ziffer;
  849. float zw;
  850. posN = findDelimiterPos(input, "N");
  851. posPunkt = findDelimiterPos(input, ".");
  852. if (posPunkt == std::string::npos){
  853. posPunkt = input.length();
  854. }
  855. while (posN != std::string::npos)
  856. {
  857. if (posN < posPunkt) {
  858. pot = posPunkt - posN - 1;
  859. }
  860. else {
  861. pot = posPunkt - posN;
  862. }
  863. zw =_prevalue / pow(10, pot);
  864. ziffer = ((int) zw) % 10;
  865. input[posN] = ziffer + 48;
  866. posN = findDelimiterPos(input, "N");
  867. }
  868. return input;
  869. }
  870. float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
  871. int aktdigit, olddigit;
  872. int aktdigit_before, olddigit_before;
  873. int pot, pot_max;
  874. float zw;
  875. bool no_nulldurchgang = false;
  876. pot = _decilamshift;
  877. if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated
  878. {
  879. pot++;
  880. }
  881. #ifdef SERIAL_DEBUG
  882. ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift);
  883. #endif
  884. pot_max = ((int) log10(input)) + 1;
  885. while (pot <= pot_max)
  886. {
  887. zw = input / pow(10, pot-1);
  888. aktdigit_before = ((int) zw) % 10;
  889. zw = _preValue / pow(10, pot-1);
  890. olddigit_before = ((int) zw) % 10;
  891. zw = input / pow(10, pot);
  892. aktdigit = ((int) zw) % 10;
  893. zw = _preValue / pow(10, pot);
  894. olddigit = ((int) zw) % 10;
  895. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  896. if (no_nulldurchgang)
  897. {
  898. if (aktdigit != olddigit)
  899. {
  900. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit;
  901. }
  902. }
  903. else
  904. {
  905. if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1
  906. {
  907. input = input + ((float) (1)) * pow(10, pot); // add 1 at the point
  908. }
  909. }
  910. #ifdef SERIAL_DEBUG
  911. ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input);
  912. #endif
  913. pot++;
  914. }
  915. return input;
  916. }
  917. string ClassFlowPostProcessing::getReadoutRate(int _number)
  918. {
  919. return std::to_string(NUMBERS[_number]->FlowRateAct);
  920. }
  921. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  922. {
  923. return NUMBERS[_number]->timeStamp;
  924. }
  925. string ClassFlowPostProcessing::getReadoutError(int _number)
  926. {
  927. return NUMBERS[_number]->ErrorMessageText;
  928. }