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 "websocket.h"
  9. #include "time_sntp.h"
  10. #include "esp_log.h"
  11. #include "../../include/defines.h"
  12. static const char* TAG = "POSTPROC";
  13. std::string ClassFlowPostProcessing::getNumbersName()
  14. {
  15. std::string ret="";
  16. for (int i = 0; i < NUMBERS.size(); ++i)
  17. {
  18. ret += NUMBERS[i]->name;
  19. if (i < NUMBERS.size()-1)
  20. ret = ret + "\t";
  21. }
  22. // ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str());
  23. return ret;
  24. }
  25. std::string ClassFlowPostProcessing::GetJSON(std::string _lineend)
  26. {
  27. std::string json="{" + _lineend;
  28. for (int i = 0; i < NUMBERS.size(); ++i)
  29. {
  30. json += "\"" + NUMBERS[i]->name + "\":" + _lineend;
  31. json += getJsonFromNumber(i, _lineend) + _lineend;
  32. if ((i+1) < NUMBERS.size())
  33. json += "," + _lineend;
  34. }
  35. json += "}";
  36. return json;
  37. }
  38. string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _lineend) {
  39. std::string json = "";
  40. json += " {" + _lineend;
  41. if (NUMBERS[i]->ReturnValue.length() > 0)
  42. json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend;
  43. else
  44. json += " \"value\": \"\"," + _lineend;
  45. json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend;
  46. json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend;
  47. json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend;
  48. if (NUMBERS[i]->ReturnRateValue.length() > 0)
  49. json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend;
  50. else
  51. json += " \"rate\": \"\"," + _lineend;
  52. json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend;
  53. json += " }" + _lineend;
  54. return json;
  55. }
  56. string ClassFlowPostProcessing::GetPreValue(std::string _number)
  57. {
  58. std::string result;
  59. int index = -1;
  60. if (_number == "")
  61. _number = "default";
  62. for (int i = 0; i < NUMBERS.size(); ++i)
  63. if (NUMBERS[i]->name == _number)
  64. index = i;
  65. if (index == -1)
  66. return std::string("");
  67. result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma);
  68. return result;
  69. }
  70. bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern)
  71. {
  72. //ESP_LOGD(TAG, "SetPrevalue: %f, %s", zw, _numbers.c_str());
  73. for (int j = 0; j < NUMBERS.size(); ++j) {
  74. //ESP_LOGD(TAG, "Number %d, %s", j, NUMBERS[j]->name.c_str());
  75. if (NUMBERS[j]->name == _numbers) {
  76. if (_newvalue >= 0) { // if new value posivive, use provided value to preset PreValue
  77. NUMBERS[j]->PreValue = _newvalue;
  78. }
  79. else { // if new value negative, use last raw value to preset PreValue
  80. char* p;
  81. double ReturnRawValueAsDouble = strtod(NUMBERS[j]->ReturnRawValue.c_str(), &p);
  82. if (ReturnRawValueAsDouble == 0) {
  83. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: "
  84. + NUMBERS[j]->ReturnRawValue);
  85. return false;
  86. }
  87. NUMBERS[j]->PreValue = ReturnRawValueAsDouble;
  88. }
  89. NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue);
  90. NUMBERS[j]->PreValueOkay = true;
  91. if (_extern)
  92. {
  93. time(&(NUMBERS[j]->lastvalue));
  94. localtime(&(NUMBERS[j]->lastvalue));
  95. }
  96. //ESP_LOGD(TAG, "Found %d! - set to %.8f", j, NUMBERS[j]->PreValue);
  97. UpdatePreValueINI = true; // Only update prevalue file if a new value is set
  98. SavePreValue();
  99. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " +
  100. std::to_string(NUMBERS[j]->PreValue));
  101. return true;
  102. }
  103. }
  104. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: Numbersname not found or not valid");
  105. return false; // No new value was set (e.g. wrong numbersname, no numbers at all)
  106. }
  107. bool ClassFlowPostProcessing::LoadPreValue(void)
  108. {
  109. std::vector<string> splitted;
  110. FILE* pFile;
  111. char zw[1024];
  112. string zwtime, zwvalue, name;
  113. bool _done = false;
  114. UpdatePreValueINI = false; // Conversion to the new format
  115. pFile = fopen(FilePreValue.c_str(), "r");
  116. if (pFile == NULL)
  117. return false;
  118. fgets(zw, 1024, pFile);
  119. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
  120. zwtime = trim(std::string(zw));
  121. if (zwtime.length() == 0)
  122. return false;
  123. splitted = HelperZerlegeZeile(zwtime, "\t");
  124. if (splitted.size() > 1) // Conversion to the new format
  125. {
  126. while ((splitted.size() > 1) && !_done)
  127. {
  128. name = trim(splitted[0]);
  129. zwtime = trim(splitted[1]);
  130. zwvalue = trim(splitted[2]);
  131. for (int j = 0; j < NUMBERS.size(); ++j)
  132. {
  133. if (NUMBERS[j]->name == name)
  134. {
  135. NUMBERS[j]->PreValue = stod(zwvalue.c_str());
  136. 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).
  137. time_t tStart;
  138. int yy, month, dd, hh, mm, ss;
  139. struct tm whenStart;
  140. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  141. whenStart.tm_year = yy - 1900;
  142. whenStart.tm_mon = month - 1;
  143. whenStart.tm_mday = dd;
  144. whenStart.tm_hour = hh;
  145. whenStart.tm_min = mm;
  146. whenStart.tm_sec = ss;
  147. whenStart.tm_isdst = -1;
  148. NUMBERS[j]->lastvalue = mktime(&whenStart);
  149. time(&tStart);
  150. localtime(&tStart);
  151. double difference = difftime(tStart, NUMBERS[j]->lastvalue);
  152. difference /= 60;
  153. if (difference > PreValueAgeStartup)
  154. NUMBERS[j]->PreValueOkay = false;
  155. else
  156. NUMBERS[j]->PreValueOkay = true;
  157. }
  158. }
  159. if (!fgets(zw, 1024, pFile))
  160. _done = true;
  161. else
  162. {
  163. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
  164. splitted = HelperZerlegeZeile(trim(std::string(zw)), "\t");
  165. if (splitted.size() > 1)
  166. {
  167. name = trim(splitted[0]);
  168. zwtime = trim(splitted[1]);
  169. zwvalue = trim(splitted[2]);
  170. }
  171. }
  172. }
  173. fclose(pFile);
  174. }
  175. else // Old Format
  176. {
  177. fgets(zw, 1024, pFile);
  178. fclose(pFile);
  179. ESP_LOGD(TAG, "%s", zw);
  180. zwvalue = trim(std::string(zw));
  181. NUMBERS[0]->PreValue = stod(zwvalue.c_str());
  182. time_t tStart;
  183. int yy, month, dd, hh, mm, ss;
  184. struct tm whenStart;
  185. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  186. whenStart.tm_year = yy - 1900;
  187. whenStart.tm_mon = month - 1;
  188. whenStart.tm_mday = dd;
  189. whenStart.tm_hour = hh;
  190. whenStart.tm_min = mm;
  191. whenStart.tm_sec = ss;
  192. whenStart.tm_isdst = -1;
  193. 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);
  194. NUMBERS[0]->lastvalue = mktime(&whenStart);
  195. time(&tStart);
  196. localtime(&tStart);
  197. double difference = difftime(tStart, NUMBERS[0]->lastvalue);
  198. difference /= 60;
  199. if (difference > PreValueAgeStartup)
  200. return false;
  201. NUMBERS[0]->Value = NUMBERS[0]->PreValue;
  202. NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
  203. if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
  204. {
  205. NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma);
  206. }
  207. UpdatePreValueINI = true; // Conversion to the new format
  208. SavePreValue();
  209. }
  210. return true;
  211. }
  212. void ClassFlowPostProcessing::SavePreValue()
  213. {
  214. FILE* pFile;
  215. string _zw;
  216. if (!UpdatePreValueINI) // PreValues unchanged --> File does not have to be rewritten
  217. return;
  218. pFile = fopen(FilePreValue.c_str(), "w");
  219. for (int j = 0; j < NUMBERS.size(); ++j)
  220. {
  221. char buffer[80];
  222. struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue);
  223. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  224. NUMBERS[j]->timeStamp = std::string(buffer);
  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. #ifdef SERIAL_DEBUG
  710. ESP_LOGD(TAG, "Neg: value=%f, preValue=%f, preToll%f", NUMBERS[j]->Value, NUMBERS[j]->PreValue,
  711. NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))
  712. ) ;
  713. #endif
  714. // Include inaccuracy of 0.2 for isExtendedResolution.
  715. if (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution) {
  716. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  717. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
  718. } else {
  719. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
  720. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  721. NUMBERS[j]->ReturnValue = "";
  722. NUMBERS[j]->lastvalue = imagetime;
  723. schedule_websocket_message("{\"status\": \"" + NUMBERS[j]->ErrorMessageText + "\", \"number\": \"" + NUMBERS[j]->name + "\"}");
  724. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  725. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  726. WriteDataLog(j);
  727. continue;
  728. }
  729. }
  730. }
  731. #ifdef SERIAL_DEBUG
  732. ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value);
  733. #endif
  734. difference /= 60;
  735. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  736. NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct);
  737. if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
  738. {
  739. double _ratedifference;
  740. if (NUMBERS[j]->RateType == RateChange)
  741. _ratedifference = NUMBERS[j]->FlowRateAct;
  742. else
  743. _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue);
  744. if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
  745. {
  746. 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);
  747. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  748. NUMBERS[j]->ReturnValue = "";
  749. NUMBERS[j]->ReturnRateValue = "";
  750. NUMBERS[j]->lastvalue = imagetime;
  751. schedule_websocket_message("{\"status\": \"" + NUMBERS[j]->ErrorMessageText + "\", \"number\": \"" + NUMBERS[j]->name + "\"}");
  752. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  753. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  754. WriteDataLog(j);
  755. continue;
  756. }
  757. }
  758. #ifdef SERIAL_DEBUG
  759. ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value);
  760. #endif
  761. NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  762. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  763. NUMBERS[j]->PreValueOkay = true;
  764. NUMBERS[j]->lastvalue = imagetime;
  765. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  766. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  767. NUMBERS[j]->ErrorMessageText = "no error";
  768. UpdatePreValueINI = true;
  769. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  770. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  771. WriteDataLog(j);
  772. }
  773. SavePreValue();
  774. return true;
  775. }
  776. void ClassFlowPostProcessing::WriteDataLog(int _index)
  777. {
  778. if (!LogFile.GetDataLogToSD()){
  779. return;
  780. }
  781. string analog = "";
  782. string digital = "";
  783. string timezw = "";
  784. char buffer[80];
  785. struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue);
  786. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  787. timezw = std::string(buffer);
  788. if (flowAnalog)
  789. analog = flowAnalog->getReadoutRawString(_index);
  790. if (flowDigit)
  791. digital = flowDigit->getReadoutRawString(_index);
  792. LogFile.WriteToData(timezw, NUMBERS[_index]->name,
  793. NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  794. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute,
  795. NUMBERS[_index]->ErrorMessageText,
  796. digital, analog);
  797. 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());
  798. }
  799. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  800. {
  801. for (int j = 0; j < NUMBERS.size(); ++j)
  802. {
  803. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits
  804. {
  805. // ESP_LOGD(TAG, "Nurdigital");
  806. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  807. if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  808. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  809. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  810. }
  811. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  812. {
  813. // ESP_LOGD(TAG, "Nur analog");
  814. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  815. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  816. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  817. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  818. }
  819. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog
  820. {
  821. // ESP_LOGD(TAG, "Nur digital + analog");
  822. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  823. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  824. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  825. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1;
  826. }
  827. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift);
  828. }
  829. }
  830. string ClassFlowPostProcessing::getReadout(int _number)
  831. {
  832. return NUMBERS[_number]->ReturnValue;
  833. }
  834. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  835. {
  836. if (_rawValue)
  837. return NUMBERS[_number]->ReturnRawValue;
  838. if (_noerror)
  839. return NUMBERS[_number]->ReturnValue;
  840. return NUMBERS[_number]->ReturnValue;
  841. }
  842. string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
  843. {
  844. int posN, posPunkt;
  845. int pot, ziffer;
  846. float zw;
  847. posN = findDelimiterPos(input, "N");
  848. posPunkt = findDelimiterPos(input, ".");
  849. if (posPunkt == std::string::npos){
  850. posPunkt = input.length();
  851. }
  852. while (posN != std::string::npos)
  853. {
  854. if (posN < posPunkt) {
  855. pot = posPunkt - posN - 1;
  856. }
  857. else {
  858. pot = posPunkt - posN;
  859. }
  860. zw =_prevalue / pow(10, pot);
  861. ziffer = ((int) zw) % 10;
  862. input[posN] = ziffer + 48;
  863. posN = findDelimiterPos(input, "N");
  864. }
  865. return input;
  866. }
  867. float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
  868. int aktdigit, olddigit;
  869. int aktdigit_before, olddigit_before;
  870. int pot, pot_max;
  871. float zw;
  872. bool no_nulldurchgang = false;
  873. pot = _decilamshift;
  874. if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated
  875. {
  876. pot++;
  877. }
  878. #ifdef SERIAL_DEBUG
  879. ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift);
  880. #endif
  881. pot_max = ((int) log10(input)) + 1;
  882. while (pot <= pot_max)
  883. {
  884. zw = input / pow(10, pot-1);
  885. aktdigit_before = ((int) zw) % 10;
  886. zw = _preValue / pow(10, pot-1);
  887. olddigit_before = ((int) zw) % 10;
  888. zw = input / pow(10, pot);
  889. aktdigit = ((int) zw) % 10;
  890. zw = _preValue / pow(10, pot);
  891. olddigit = ((int) zw) % 10;
  892. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  893. if (no_nulldurchgang)
  894. {
  895. if (aktdigit != olddigit)
  896. {
  897. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit;
  898. }
  899. }
  900. else
  901. {
  902. if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1
  903. {
  904. input = input + ((float) (1)) * pow(10, pot); // add 1 at the point
  905. }
  906. }
  907. #ifdef SERIAL_DEBUG
  908. ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input);
  909. #endif
  910. pot++;
  911. }
  912. return input;
  913. }
  914. string ClassFlowPostProcessing::getReadoutRate(int _number)
  915. {
  916. return std::to_string(NUMBERS[_number]->FlowRateAct);
  917. }
  918. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  919. {
  920. return NUMBERS[_number]->timeStamp;
  921. }
  922. string ClassFlowPostProcessing::getReadoutError(int _number)
  923. {
  924. return NUMBERS[_number]->ErrorMessageText;
  925. }