ClassFlowPostProcessing.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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]->ErrorMessageText = "";
  612. NUMBERS[j]->Value = -1;
  613. /* calculate time difference BEFORE we overwrite the 'lastvalue' */
  614. double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in seconds
  615. /* TODO:
  616. * We could call `NUMBERS[j]->lastvalue = imagetime;` here and remove all other such calls further down.
  617. * But we should check nothing breaks! */
  618. UpdateNachkommaDecimalShift();
  619. int previous_value = -1;
  620. if (NUMBERS[j]->analog_roi)
  621. {
  622. NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution);
  623. if (NUMBERS[j]->ReturnRawValue.length() > 0)
  624. {
  625. char zw = NUMBERS[j]->ReturnRawValue[0];
  626. if (zw >= 48 && zw <=57)
  627. previous_value = zw - 48;
  628. }
  629. }
  630. #ifdef SERIAL_DEBUG
  631. ESP_LOGD(TAG, "After analog->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  632. #endif
  633. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  634. NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue;
  635. if (NUMBERS[j]->digit_roi)
  636. {
  637. if (NUMBERS[j]->analog_roi)
  638. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue;
  639. else
  640. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits
  641. }
  642. #ifdef SERIAL_DEBUG
  643. ESP_LOGD(TAG, "After digital->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  644. #endif
  645. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  646. #ifdef SERIAL_DEBUG
  647. ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  648. #endif
  649. if (IgnoreLeadingNaN)
  650. while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N'))
  651. NUMBERS[j]->ReturnRawValue.erase(0, 1);
  652. #ifdef SERIAL_DEBUG
  653. ESP_LOGD(TAG, "After IgnoreLeadingNaN: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  654. #endif
  655. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
  656. if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos)
  657. {
  658. if (PreValueUse && NUMBERS[j]->PreValueOkay)
  659. {
  660. NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue);
  661. }
  662. else
  663. {
  664. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  665. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  666. /* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */
  667. NUMBERS[j]->lastvalue = imagetime;
  668. WriteDataLog(j);
  669. continue; // there is no number because there is still an N.
  670. }
  671. }
  672. #ifdef SERIAL_DEBUG
  673. ESP_LOGD(TAG, "After findDelimiterPos: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str());
  674. #endif
  675. // Delete leading zeros (unless there is only one 0 left)
  676. while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
  677. NUMBERS[j]->ReturnValue.erase(0, 1);
  678. #ifdef SERIAL_DEBUG
  679. ESP_LOGD(TAG, "After removeLeadingZeros: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str());
  680. #endif
  681. NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue);
  682. #ifdef SERIAL_DEBUG
  683. ESP_LOGD(TAG, "After setting the Value: Value %f and as double is %f", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue));
  684. #endif
  685. if (NUMBERS[j]->checkDigitIncreaseConsistency)
  686. {
  687. if (flowDigit)
  688. {
  689. if (flowDigit->getCNNType() != Digital)
  690. ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)");
  691. else
  692. NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
  693. }
  694. else
  695. {
  696. #ifdef SERIAL_DEBUG
  697. ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digital numbers defined!");
  698. #endif
  699. }
  700. }
  701. #ifdef SERIAL_DEBUG
  702. ESP_LOGD(TAG, "After checkDigitIncreaseConsistency: Value %f", NUMBERS[j]->Value);
  703. #endif
  704. if (!NUMBERS[j]->AllowNegativeRates)
  705. {
  706. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name);
  707. if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  708. {
  709. // more debug if extended resolution is on, see #2447
  710. if (NUMBERS[j]->isExtendedResolution) {
  711. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value)
  712. + ", preValue=" + std::to_string(NUMBERS[j]->PreValue)
  713. + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))));
  714. }
  715. // Include inaccuracy of 0.2 for isExtendedResolution.
  716. if ((NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution)
  717. // not extended resolution allows -1 on the lowest digit
  718. || (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(1/pow(10, NUMBERS[j]->Nachkomma))) && !NUMBERS[j]->isExtendedResolution)) {
  719. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  720. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
  721. }
  722. else {
  723. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
  724. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  725. NUMBERS[j]->ReturnValue = "";
  726. NUMBERS[j]->lastvalue = imagetime;
  727. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  728. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  729. WriteDataLog(j);
  730. continue;
  731. }
  732. }
  733. }
  734. #ifdef SERIAL_DEBUG
  735. ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value);
  736. #endif
  737. difference /= 60;
  738. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  739. NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct);
  740. if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
  741. {
  742. double _ratedifference;
  743. if (NUMBERS[j]->RateType == RateChange)
  744. _ratedifference = NUMBERS[j]->FlowRateAct;
  745. else
  746. _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue);
  747. if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
  748. {
  749. 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);
  750. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  751. NUMBERS[j]->ReturnValue = "";
  752. NUMBERS[j]->ReturnRateValue = "";
  753. NUMBERS[j]->lastvalue = imagetime;
  754. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  755. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  756. WriteDataLog(j);
  757. continue;
  758. }
  759. }
  760. #ifdef SERIAL_DEBUG
  761. ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value);
  762. #endif
  763. NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  764. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  765. NUMBERS[j]->PreValueOkay = true;
  766. NUMBERS[j]->lastvalue = imagetime;
  767. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  768. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  769. NUMBERS[j]->ErrorMessageText = "no error";
  770. UpdatePreValueINI = true;
  771. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  772. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  773. WriteDataLog(j);
  774. }
  775. SavePreValue();
  776. return true;
  777. }
  778. void ClassFlowPostProcessing::WriteDataLog(int _index)
  779. {
  780. if (!LogFile.GetDataLogToSD()){
  781. return;
  782. }
  783. string analog = "";
  784. string digital = "";
  785. string timezw = "";
  786. char buffer[80];
  787. struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue);
  788. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  789. timezw = std::string(buffer);
  790. if (flowAnalog)
  791. analog = flowAnalog->getReadoutRawString(_index);
  792. if (flowDigit)
  793. digital = flowDigit->getReadoutRawString(_index);
  794. LogFile.WriteToData(timezw, NUMBERS[_index]->name,
  795. NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  796. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute,
  797. NUMBERS[_index]->ErrorMessageText,
  798. digital, analog);
  799. 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());
  800. }
  801. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  802. {
  803. for (int j = 0; j < NUMBERS.size(); ++j)
  804. {
  805. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits
  806. {
  807. // ESP_LOGD(TAG, "Nurdigital");
  808. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  809. if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  810. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  811. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  812. }
  813. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  814. {
  815. // ESP_LOGD(TAG, "Nur analog");
  816. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  817. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  818. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  819. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  820. }
  821. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog
  822. {
  823. // ESP_LOGD(TAG, "Nur digital + analog");
  824. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  825. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  826. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  827. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1;
  828. }
  829. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift);
  830. }
  831. }
  832. string ClassFlowPostProcessing::getReadout(int _number)
  833. {
  834. return NUMBERS[_number]->ReturnValue;
  835. }
  836. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  837. {
  838. if (_rawValue)
  839. return NUMBERS[_number]->ReturnRawValue;
  840. if (_noerror)
  841. return NUMBERS[_number]->ReturnValue;
  842. return NUMBERS[_number]->ReturnValue;
  843. }
  844. string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
  845. {
  846. int posN, posPunkt;
  847. int pot, ziffer;
  848. float zw;
  849. posN = findDelimiterPos(input, "N");
  850. posPunkt = findDelimiterPos(input, ".");
  851. if (posPunkt == std::string::npos){
  852. posPunkt = input.length();
  853. }
  854. while (posN != std::string::npos)
  855. {
  856. if (posN < posPunkt) {
  857. pot = posPunkt - posN - 1;
  858. }
  859. else {
  860. pot = posPunkt - posN;
  861. }
  862. zw =_prevalue / pow(10, pot);
  863. ziffer = ((int) zw) % 10;
  864. input[posN] = ziffer + 48;
  865. posN = findDelimiterPos(input, "N");
  866. }
  867. return input;
  868. }
  869. float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
  870. int aktdigit, olddigit;
  871. int aktdigit_before, olddigit_before;
  872. int pot, pot_max;
  873. float zw;
  874. bool no_nulldurchgang = false;
  875. pot = _decilamshift;
  876. if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated
  877. {
  878. pot++;
  879. }
  880. #ifdef SERIAL_DEBUG
  881. ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift);
  882. #endif
  883. pot_max = ((int) log10(input)) + 1;
  884. while (pot <= pot_max)
  885. {
  886. zw = input / pow(10, pot-1);
  887. aktdigit_before = ((int) zw) % 10;
  888. zw = _preValue / pow(10, pot-1);
  889. olddigit_before = ((int) zw) % 10;
  890. zw = input / pow(10, pot);
  891. aktdigit = ((int) zw) % 10;
  892. zw = _preValue / pow(10, pot);
  893. olddigit = ((int) zw) % 10;
  894. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  895. if (no_nulldurchgang)
  896. {
  897. if (aktdigit != olddigit)
  898. {
  899. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit;
  900. }
  901. }
  902. else
  903. {
  904. if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1
  905. {
  906. input = input + ((float) (1)) * pow(10, pot); // add 1 at the point
  907. }
  908. }
  909. #ifdef SERIAL_DEBUG
  910. ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input);
  911. #endif
  912. pot++;
  913. }
  914. return input;
  915. }
  916. string ClassFlowPostProcessing::getReadoutRate(int _number)
  917. {
  918. return std::to_string(NUMBERS[_number]->FlowRateAct);
  919. }
  920. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  921. {
  922. return NUMBERS[_number]->timeStamp;
  923. }
  924. string ClassFlowPostProcessing::getReadoutError(int _number)
  925. {
  926. return NUMBERS[_number]->ErrorMessageText;
  927. }