ClassFlowPostProcessing.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. #include "defines.h"
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <time.h>
  5. #include <esp_log.h>
  6. #include "ClassFlowPostProcessing.h"
  7. #include "MainFlowControl.h"
  8. #include "ClassFlowTakeImage.h"
  9. #include "ClassLogFile.h"
  10. #include "Helper.h"
  11. #include "time_sntp.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. {
  21. ret = ret + "\t";
  22. }
  23. }
  24. return ret;
  25. }
  26. std::string ClassFlowPostProcessing::GetJSON(std::string _lineend)
  27. {
  28. std::string json = "{" + _lineend;
  29. for (int i = 0; i < NUMBERS.size(); ++i)
  30. {
  31. json += "\"" + NUMBERS[i]->name + "\":" + _lineend;
  32. json += getJsonFromNumber(i, _lineend) + _lineend;
  33. if ((i + 1) < NUMBERS.size())
  34. {
  35. json += "," + _lineend;
  36. }
  37. }
  38. json += "}";
  39. return json;
  40. }
  41. std::string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _lineend)
  42. {
  43. std::string json = "";
  44. json += " {" + _lineend;
  45. if (NUMBERS[i]->ReturnValue.length() > 0)
  46. {
  47. json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend;
  48. }
  49. else
  50. {
  51. json += " \"value\": \"\"," + _lineend;
  52. }
  53. json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend;
  54. json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend;
  55. json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend;
  56. if (NUMBERS[i]->ReturnRateValue.length() > 0)
  57. {
  58. json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend;
  59. }
  60. else
  61. {
  62. json += " \"rate\": \"\"," + _lineend;
  63. }
  64. if (NUMBERS[i]->ReturnChangeAbsolute.length() > 0)
  65. {
  66. json += " \"absrate\": \"" + NUMBERS[i]->ReturnChangeAbsolute + "\"," + _lineend;
  67. }
  68. else
  69. {
  70. json += " \"absrate\": \"\"," + _lineend;
  71. }
  72. json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend;
  73. json += " }" + _lineend;
  74. return json;
  75. }
  76. std::string ClassFlowPostProcessing::GetPreValue(std::string _number)
  77. {
  78. std::string result;
  79. int index = -1;
  80. if (_number == "")
  81. {
  82. _number = "default";
  83. }
  84. for (int i = 0; i < NUMBERS.size(); ++i)
  85. {
  86. if (NUMBERS[i]->name == _number)
  87. {
  88. index = i;
  89. }
  90. }
  91. if (index == -1)
  92. {
  93. return std::string("");
  94. }
  95. result = round_output(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma);
  96. return result;
  97. }
  98. bool ClassFlowPostProcessing::SetPreValue(double _newvalue, std::string _numbers, bool _extern)
  99. {
  100. for (int j = 0; j < NUMBERS.size(); ++j)
  101. {
  102. if (NUMBERS[j]->name == _numbers)
  103. {
  104. if (_newvalue >= 0)
  105. {
  106. // if new value posivive, use provided value to preset PreValue
  107. NUMBERS[j]->PreValue = _newvalue;
  108. }
  109. else
  110. {
  111. // if new value negative, use last raw value to preset PreValue
  112. char *p;
  113. double ReturnRawValueAsDouble = strtod(NUMBERS[j]->ReturnRawValue.c_str(), &p);
  114. if (ReturnRawValueAsDouble == 0)
  115. {
  116. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: " + NUMBERS[j]->ReturnRawValue);
  117. return false;
  118. }
  119. NUMBERS[j]->PreValue = ReturnRawValueAsDouble;
  120. }
  121. NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue);
  122. NUMBERS[j]->PreValueValid = true;
  123. if (_extern)
  124. {
  125. time(&(NUMBERS[j]->timeStampLastPreValue));
  126. localtime(&(NUMBERS[j]->timeStampLastPreValue));
  127. }
  128. UpdatePreValueINI = true; // Only update prevalue file if a new value is set
  129. SavePreValue();
  130. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " + std::to_string(NUMBERS[j]->PreValue));
  131. return true;
  132. }
  133. }
  134. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: Numbersname not found or not valid");
  135. return false; // No new value was set (e.g. wrong numbersname, no numbers at all)
  136. }
  137. bool ClassFlowPostProcessing::LoadPreValue(void)
  138. {
  139. UpdatePreValueINI = false; // Conversion to the new format
  140. FILE *pFile = fopen(FilePreValue.c_str(), "r");
  141. if (pFile == NULL)
  142. {
  143. return false;
  144. }
  145. // Makes sure that an empty file is treated as such.
  146. char temp_char[1024];
  147. temp_char[0] = '\0';
  148. fgets(temp_char, 1024, pFile);
  149. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", temp_char);
  150. std::string temp_time = trim_string_left_right(std::string(temp_char));
  151. if (temp_time.length() == 0)
  152. {
  153. return false;
  154. }
  155. std::string temp_value, temp_name;
  156. bool _done = false;
  157. std::vector<std::string> splitted = split_line(temp_time, "\t");
  158. // Conversion to the new format
  159. if (splitted.size() > 1)
  160. {
  161. while ((splitted.size() > 1) && !_done)
  162. {
  163. temp_name = trim_string_left_right(splitted[0]);
  164. temp_time = trim_string_left_right(splitted[1]);
  165. temp_value = trim_string_left_right(splitted[2]);
  166. for (int j = 0; j < NUMBERS.size(); ++j)
  167. {
  168. if (NUMBERS[j]->name == temp_name)
  169. {
  170. NUMBERS[j]->PreValue = stod(temp_value.c_str());
  171. NUMBERS[j]->ReturnPreValue = round_output(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).
  172. time_t tStart;
  173. int yy, month, dd, hh, mm, ss;
  174. struct tm whenStart;
  175. sscanf(temp_time.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  176. whenStart.tm_year = yy - 1900;
  177. whenStart.tm_mon = month - 1;
  178. whenStart.tm_mday = dd;
  179. whenStart.tm_hour = hh;
  180. whenStart.tm_min = mm;
  181. whenStart.tm_sec = ss;
  182. whenStart.tm_isdst = -1;
  183. NUMBERS[j]->timeStampLastPreValue = mktime(&whenStart);
  184. time(&tStart);
  185. localtime(&tStart);
  186. double difference = difftime(tStart, NUMBERS[j]->timeStampLastPreValue);
  187. difference /= 60;
  188. if (difference > PreValueAgeStartup)
  189. {
  190. NUMBERS[j]->PreValueValid = false;
  191. }
  192. else
  193. {
  194. NUMBERS[j]->PreValueValid = true;
  195. }
  196. }
  197. }
  198. if (!fgets(temp_char, 1024, pFile))
  199. {
  200. _done = true;
  201. }
  202. else
  203. {
  204. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", temp_char);
  205. splitted = split_line(trim_string_left_right(std::string(temp_char)), "\t");
  206. if (splitted.size() > 1)
  207. {
  208. temp_name = trim_string_left_right(splitted[0]);
  209. temp_time = trim_string_left_right(splitted[1]);
  210. temp_value = trim_string_left_right(splitted[2]);
  211. }
  212. }
  213. }
  214. fclose(pFile);
  215. }
  216. else
  217. {
  218. // Old Format
  219. fgets(temp_char, 1024, pFile);
  220. fclose(pFile);
  221. ESP_LOGD(TAG, "%s", temp_char);
  222. temp_value = trim_string_left_right(std::string(temp_char));
  223. NUMBERS[0]->PreValue = stod(temp_value.c_str());
  224. time_t tStart;
  225. int yy, month, dd, hh, mm, ss;
  226. struct tm whenStart;
  227. sscanf(temp_time.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  228. whenStart.tm_year = yy - 1900;
  229. whenStart.tm_mon = month - 1;
  230. whenStart.tm_mday = dd;
  231. whenStart.tm_hour = hh;
  232. whenStart.tm_min = mm;
  233. whenStart.tm_sec = ss;
  234. whenStart.tm_isdst = -1;
  235. 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);
  236. NUMBERS[0]->timeStampLastPreValue = mktime(&whenStart);
  237. time(&tStart);
  238. localtime(&tStart);
  239. double difference = difftime(tStart, NUMBERS[0]->timeStampLastPreValue);
  240. difference /= 60;
  241. if (difference > PreValueAgeStartup)
  242. {
  243. return false;
  244. }
  245. NUMBERS[0]->Value = NUMBERS[0]->PreValue;
  246. NUMBERS[0]->ReturnValue = std::to_string(NUMBERS[0]->Value);
  247. if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
  248. {
  249. NUMBERS[0]->ReturnValue = round_output(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma);
  250. }
  251. UpdatePreValueINI = true; // Conversion to the new format
  252. SavePreValue();
  253. }
  254. return true;
  255. }
  256. void ClassFlowPostProcessing::SavePreValue()
  257. {
  258. // PreValues unchanged --> File does not have to be rewritten
  259. if (!UpdatePreValueINI)
  260. {
  261. return;
  262. }
  263. FILE *pFile = fopen(FilePreValue.c_str(), "w");
  264. for (int j = 0; j < NUMBERS.size(); ++j)
  265. {
  266. char buffer[80];
  267. struct tm *timeinfo = localtime(&NUMBERS[j]->timeStampLastPreValue);
  268. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  269. NUMBERS[j]->timeStamp = std::string(buffer);
  270. NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->timeStampLastPreValue;
  271. // ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  272. std::string temp_string = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n";
  273. ESP_LOGD(TAG, "Write PreValue line: %s", temp_string.c_str());
  274. if (pFile)
  275. {
  276. fputs(temp_string.c_str(), pFile);
  277. }
  278. }
  279. UpdatePreValueINI = false;
  280. fclose(pFile);
  281. }
  282. ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow *> *lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit)
  283. {
  284. PreValueUse = false;
  285. PreValueAgeStartup = 30;
  286. ListFlowControll = NULL;
  287. FilePreValue = format_filename("/sdcard/config/prevalue.ini");
  288. ListFlowControll = lfc;
  289. flowTakeImage = NULL;
  290. UpdatePreValueINI = false;
  291. flowAnalog = _analog;
  292. flowDigit = _digit;
  293. for (int i = 0; i < ListFlowControll->size(); ++i)
  294. {
  295. if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0)
  296. {
  297. flowTakeImage = (ClassFlowTakeImage *)(*ListFlowControll)[i];
  298. }
  299. }
  300. }
  301. void ClassFlowPostProcessing::handleExtendedResolution(std::string _decsep, std::string _value)
  302. {
  303. std::string _digit;
  304. int _pospunkt = _decsep.find_first_of(".");
  305. if (_pospunkt > -1)
  306. {
  307. _digit = _decsep.substr(0, _pospunkt);
  308. }
  309. else
  310. {
  311. _digit = "default";
  312. }
  313. for (int j = 0; j < NUMBERS.size(); ++j)
  314. {
  315. bool temp_value = alphanumeric_to_boolean(_value);
  316. // Set to default first (if nothing else is set)
  317. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  318. {
  319. NUMBERS[j]->ExtendedResolution = temp_value;
  320. }
  321. }
  322. }
  323. void ClassFlowPostProcessing::handleDecimalShift(std::string _decsep, std::string _value)
  324. {
  325. std::string _digit;
  326. int _pospunkt = _decsep.find_first_of(".");
  327. if (_pospunkt > -1)
  328. {
  329. _digit = _decsep.substr(0, _pospunkt);
  330. }
  331. else
  332. {
  333. _digit = "default";
  334. }
  335. for (int j = 0; j < NUMBERS.size(); ++j)
  336. {
  337. int temp_value = 0;
  338. if (is_string_numeric(_value))
  339. {
  340. temp_value = std::stoi(_value);
  341. }
  342. // Set to default first (if nothing else is set)
  343. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  344. {
  345. NUMBERS[j]->DecimalShift = temp_value;
  346. NUMBERS[j]->DecimalShiftInitial = temp_value;
  347. }
  348. NUMBERS[j]->Nachkomma = NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift;
  349. }
  350. }
  351. void ClassFlowPostProcessing::handleAnalogToDigitTransitionStart(std::string _decsep, std::string _value)
  352. {
  353. std::string _digit;
  354. int _pospunkt = _decsep.find_first_of(".");
  355. if (_pospunkt > -1)
  356. {
  357. _digit = _decsep.substr(0, _pospunkt);
  358. }
  359. else
  360. {
  361. _digit = "default";
  362. }
  363. for (int j = 0; j < NUMBERS.size(); ++j)
  364. {
  365. float temp_value = 9.2;
  366. if (is_string_numeric(_value))
  367. {
  368. temp_value = std::stof(_value);
  369. }
  370. // Set to default first (if nothing else is set)
  371. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  372. {
  373. NUMBERS[j]->AnalogToDigitTransitionStart = temp_value;
  374. }
  375. }
  376. }
  377. void ClassFlowPostProcessing::handleSkipErrorMessage(std::string _decsep, std::string _value)
  378. {
  379. std::string _digit;
  380. int _pospunkt = _decsep.find_first_of(".");
  381. if (_pospunkt > -1)
  382. {
  383. _digit = _decsep.substr(0, _pospunkt);
  384. }
  385. else
  386. {
  387. _digit = "default";
  388. }
  389. for (int j = 0; j < NUMBERS.size(); ++j)
  390. {
  391. bool temp_value = alphanumeric_to_boolean(_value);
  392. // Set to default first (if nothing else is set)
  393. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  394. {
  395. NUMBERS[j]->SkipErrorMessage = temp_value;
  396. }
  397. }
  398. }
  399. void ClassFlowPostProcessing::handleAllowNegativeRate(std::string _decsep, std::string _value)
  400. {
  401. std::string _digit;
  402. int _pospunkt = _decsep.find_first_of(".");
  403. if (_pospunkt > -1)
  404. {
  405. _digit = _decsep.substr(0, _pospunkt);
  406. }
  407. else
  408. {
  409. _digit = "default";
  410. }
  411. for (int j = 0; j < NUMBERS.size(); ++j)
  412. {
  413. bool temp_value = alphanumeric_to_boolean(_value);
  414. // Set to default first (if nothing else is set)
  415. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  416. {
  417. NUMBERS[j]->AllowNegativeRates = temp_value;
  418. }
  419. }
  420. }
  421. void ClassFlowPostProcessing::handleIgnoreLeadingNaN(std::string _decsep, std::string _value)
  422. {
  423. std::string _digit;
  424. int _pospunkt = _decsep.find_first_of(".");
  425. if (_pospunkt > -1)
  426. {
  427. _digit = _decsep.substr(0, _pospunkt);
  428. }
  429. else
  430. {
  431. _digit = "default";
  432. }
  433. for (int j = 0; j < NUMBERS.size(); ++j)
  434. {
  435. bool temp_value = alphanumeric_to_boolean(_value);
  436. // Set to default first (if nothing else is set)
  437. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  438. {
  439. NUMBERS[j]->IgnoreLeadingNaN = temp_value;
  440. }
  441. }
  442. }
  443. void ClassFlowPostProcessing::handleMaxFlowRate(std::string _decsep, std::string _value)
  444. {
  445. std::string _digit;
  446. int _pospunkt = _decsep.find_first_of(".");
  447. if (_pospunkt > -1)
  448. {
  449. _digit = _decsep.substr(0, _pospunkt);
  450. }
  451. else
  452. {
  453. _digit = "default";
  454. }
  455. for (int j = 0; j < NUMBERS.size(); ++j)
  456. {
  457. float temp_value = 4.0;
  458. if (is_string_numeric(_value))
  459. {
  460. temp_value = std::stof(_value);
  461. }
  462. // Set to default first (if nothing else is set)
  463. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  464. {
  465. NUMBERS[j]->useMaxFlowRate = true;
  466. NUMBERS[j]->MaxFlowRate = temp_value;
  467. }
  468. }
  469. }
  470. void ClassFlowPostProcessing::handleMaxRateType(std::string _decsep, std::string _value)
  471. {
  472. std::string _digit, _decpos;
  473. int _pospunkt = _decsep.find_first_of(".");
  474. if (_pospunkt > -1)
  475. {
  476. _digit = _decsep.substr(0, _pospunkt);
  477. }
  478. else
  479. {
  480. _digit = "default";
  481. }
  482. for (int j = 0; j < NUMBERS.size(); ++j)
  483. {
  484. t_RateType temp_value = AbsoluteChange;
  485. if (to_upper(_value) == "RATECHANGE")
  486. {
  487. temp_value = RateChange;
  488. }
  489. // Set to default first (if nothing else is set)
  490. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  491. {
  492. NUMBERS[j]->MaxRateType = temp_value;
  493. }
  494. }
  495. }
  496. void ClassFlowPostProcessing::handleMaxRateValue(std::string _decsep, std::string _value)
  497. {
  498. std::string _digit;
  499. int _pospunkt = _decsep.find_first_of(".");
  500. if (_pospunkt > -1)
  501. {
  502. _digit = _decsep.substr(0, _pospunkt);
  503. }
  504. else
  505. {
  506. _digit = "default";
  507. }
  508. for (int j = 0; j < NUMBERS.size(); ++j)
  509. {
  510. float temp_value = 1;
  511. if (is_string_numeric(_value))
  512. {
  513. temp_value = std::stof(_value);
  514. }
  515. // Set to default first (if nothing else is set)
  516. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  517. {
  518. NUMBERS[j]->useMaxRateValue = true;
  519. NUMBERS[j]->MaxRateValue = temp_value;
  520. }
  521. }
  522. }
  523. void ClassFlowPostProcessing::handleChangeRateThreshold(std::string _decsep, std::string _value)
  524. {
  525. std::string _digit;
  526. int _pospunkt = _decsep.find_first_of(".");
  527. if (_pospunkt > -1)
  528. {
  529. _digit = _decsep.substr(0, _pospunkt);
  530. }
  531. else
  532. {
  533. _digit = "default";
  534. }
  535. for (int j = 0; j < NUMBERS.size(); ++j)
  536. {
  537. int temp_value = 2;
  538. if (is_string_numeric(_value))
  539. {
  540. temp_value = std::stof(_value);
  541. }
  542. // Set to default first (if nothing else is set)
  543. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  544. {
  545. NUMBERS[j]->ChangeRateThreshold = temp_value;
  546. }
  547. }
  548. }
  549. bool ClassFlowPostProcessing::ReadParameter(FILE *pFile, std::string &aktparamgraph)
  550. {
  551. aktparamgraph = trim_string_left_right(aktparamgraph);
  552. if (aktparamgraph.size() == 0)
  553. {
  554. if (!GetNextParagraph(pFile, aktparamgraph))
  555. {
  556. return false;
  557. }
  558. }
  559. // Paragraph does not fit PostProcessing
  560. if ((to_upper(aktparamgraph).compare("[POSTPROCESSING]") != 0) && (to_upper(aktparamgraph).compare(";[POSTPROCESSING]") != 0))
  561. {
  562. return false;
  563. }
  564. InitNUMBERS();
  565. std::vector<std::string> splitted;
  566. while (getNextLine(pFile, &aktparamgraph) && !isNewParagraph(aktparamgraph))
  567. {
  568. splitted = split_line(aktparamgraph);
  569. if (splitted.size() > 1)
  570. {
  571. std::string _param = to_upper(GetParameterName(splitted[0]));
  572. if (_param == "PREVALUEUSE")
  573. {
  574. PreValueUse = alphanumeric_to_boolean(splitted[1]);
  575. }
  576. else if (_param == "PREVALUEAGESTARTUP")
  577. {
  578. if (is_string_numeric(splitted[1]))
  579. {
  580. PreValueAgeStartup = std::stoi(splitted[1]);
  581. }
  582. }
  583. else if (_param == "SKIPERRORMESSAGE")
  584. {
  585. handleSkipErrorMessage(splitted[0], splitted[1]);
  586. }
  587. else if (_param == "ALLOWNEGATIVERATES")
  588. {
  589. handleAllowNegativeRate(splitted[0], splitted[1]);
  590. }
  591. else if (_param == "DECIMALSHIFT")
  592. {
  593. handleDecimalShift(splitted[0], splitted[1]);
  594. }
  595. else if (_param == "ANALOGTODIGITTRANSITIONSTART")
  596. {
  597. handleAnalogToDigitTransitionStart(splitted[0], splitted[1]);
  598. }
  599. else if (_param == "MAXFLOWRATE")
  600. {
  601. handleMaxFlowRate(splitted[0], splitted[1]);
  602. }
  603. else if (_param == "MAXRATEVALUE")
  604. {
  605. handleMaxRateValue(splitted[0], splitted[1]);
  606. }
  607. else if (_param == "MAXRATETYPE")
  608. {
  609. handleMaxRateType(splitted[0], splitted[1]);
  610. }
  611. else if (_param == "CHANGERATETHRESHOLD")
  612. {
  613. handleChangeRateThreshold(splitted[0], splitted[1]);
  614. }
  615. else if (_param == "EXTENDEDRESOLUTION")
  616. {
  617. handleExtendedResolution(splitted[0], splitted[1]);
  618. }
  619. else if (_param == "IGNORELEADINGNAN")
  620. {
  621. handleIgnoreLeadingNaN(splitted[0], splitted[1]);
  622. }
  623. }
  624. }
  625. if (PreValueUse)
  626. {
  627. return LoadPreValue();
  628. }
  629. return true;
  630. }
  631. void ClassFlowPostProcessing::InitNUMBERS()
  632. {
  633. std::vector<std::string> name_numbers;
  634. if (flowDigit)
  635. {
  636. int anzDIGIT = flowDigit->getNumberGENERAL();
  637. flowDigit->UpdateNameNumbers(&name_numbers);
  638. ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d", name_numbers.size(), anzDIGIT);
  639. }
  640. if (flowAnalog)
  641. {
  642. int anzANALOG = flowAnalog->getNumberGENERAL();
  643. flowAnalog->UpdateNameNumbers(&name_numbers);
  644. ESP_LOGD(TAG, "Anzahl NUMBERS: %d - ANALOG: %d", name_numbers.size(), anzANALOG);
  645. }
  646. for (int _num = 0; _num < name_numbers.size(); ++_num)
  647. {
  648. NumberPost *_number = new NumberPost;
  649. _number->name = name_numbers[_num];
  650. _number->digit_roi = NULL;
  651. if (flowDigit)
  652. {
  653. _number->digit_roi = flowDigit->FindGENERAL(name_numbers[_num]);
  654. }
  655. if (_number->digit_roi)
  656. {
  657. _number->AnzahlDigit = _number->digit_roi->ROI.size();
  658. }
  659. else
  660. {
  661. _number->AnzahlDigit = 0;
  662. }
  663. _number->analog_roi = NULL;
  664. if (flowAnalog)
  665. {
  666. _number->analog_roi = flowAnalog->FindGENERAL(name_numbers[_num]);
  667. }
  668. if (_number->analog_roi)
  669. {
  670. _number->AnzahlAnalog = _number->analog_roi->ROI.size();
  671. }
  672. else
  673. {
  674. _number->AnzahlAnalog = 0;
  675. }
  676. _number->PreValue = 0.0f; // last value read out well
  677. _number->ReturnPreValue = "";
  678. _number->PreValueValid = false;
  679. _number->ErrorMessage = false;
  680. _number->ErrorMessageText = ""; // Error message for consistency check
  681. _number->SkipErrorMessage = false;
  682. _number->AllowNegativeRates = false;
  683. _number->DecimalShift = 0;
  684. _number->DecimalShiftInitial = 0;
  685. _number->AnalogToDigitTransitionStart = 9.2f;
  686. _number->MaxFlowRate = 4.0f;
  687. _number->useMaxFlowRate = false;
  688. _number->MaxRateValue = 0.1f;
  689. _number->MaxRateType = AbsoluteChange;
  690. _number->useMaxRateValue = false;
  691. _number->ChangeRateThreshold = 2;
  692. _number->ExtendedResolution = false;
  693. _number->IgnoreLeadingNaN = false;
  694. _number->Value = 0.0f; // last value read out, incl. corrections
  695. _number->ReturnValue = ""; // corrected return value, possibly with error message
  696. _number->ReturnRawValue = ""; // raw value (with N & leading 0)
  697. _number->FlowRateAct = 0.0f; // m3 / min
  698. _number->Nachkomma = _number->AnzahlAnalog;
  699. NUMBERS.push_back(_number);
  700. }
  701. for (int i = 0; i < NUMBERS.size(); ++i)
  702. {
  703. ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigit, NUMBERS[i]->AnzahlAnalog);
  704. }
  705. }
  706. std::string ClassFlowPostProcessing::ShiftDecimal(std::string in, int _decShift)
  707. {
  708. if (_decShift == 0)
  709. {
  710. return in;
  711. }
  712. int _pos_dec_org = find_delimiter_pos(in, ".");
  713. if (_pos_dec_org == std::string::npos)
  714. {
  715. _pos_dec_org = in.length();
  716. }
  717. else
  718. {
  719. in = in.erase(_pos_dec_org, 1);
  720. }
  721. int _pos_dec_neu = _pos_dec_org + _decShift;
  722. // comma is before the first digit
  723. if (_pos_dec_neu <= 0)
  724. {
  725. for (int i = 0; i > _pos_dec_neu; --i)
  726. {
  727. in = in.insert(0, "0");
  728. }
  729. in = "0." + in;
  730. return in;
  731. }
  732. // Comma should be after string (123 --> 1230)
  733. if (_pos_dec_neu > in.length())
  734. {
  735. for (int i = in.length(); i < _pos_dec_neu; ++i)
  736. {
  737. in = in.insert(in.length(), "0");
  738. }
  739. return in;
  740. }
  741. std::string temp_string = in.substr(0, _pos_dec_neu);
  742. temp_string = temp_string + ".";
  743. temp_string = temp_string + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  744. return temp_string;
  745. }
  746. bool ClassFlowPostProcessing::doFlow(std::string temp_time)
  747. {
  748. time_t imagetime = flowTakeImage->getTimeImageTaken();
  749. if (imagetime == 0)
  750. {
  751. time(&imagetime);
  752. }
  753. struct tm *timeinfo = localtime(&imagetime);
  754. char strftime_buf[64];
  755. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  756. temp_time = std::string(strftime_buf);
  757. for (int j = 0; j < NUMBERS.size(); ++j)
  758. {
  759. NUMBERS[j]->ErrorMessage = false;
  760. NUMBERS[j]->ErrorMessageText = "";
  761. NUMBERS[j]->Value = -1;
  762. if (NUMBERS[j]->SkipErrorMessage)
  763. {
  764. NUMBERS[j]->ReturnValue = std::to_string(NUMBERS[j]->PreValue);
  765. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnValue;
  766. }
  767. else
  768. {
  769. NUMBERS[j]->ReturnValue = "";
  770. NUMBERS[j]->ReturnRawValue = "";
  771. }
  772. NUMBERS[j]->FlowRateAct = 0.0f;
  773. NUMBERS[j]->ReturnRateValue = round_output(0.0f, NUMBERS[j]->Nachkomma);
  774. NUMBERS[j]->ReturnChangeAbsolute = NUMBERS[j]->ReturnRateValue;
  775. // calculate time difference
  776. double LastValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastValue) / 60; // in minutes
  777. double LastPreValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastPreValue) / 60; // in minutes
  778. if (!flowctrl.AlignmentOk)
  779. {
  780. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  781. NUMBERS[j]->timeStampLastValue = imagetime;
  782. NUMBERS[j]->ErrorMessage = true;
  783. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Alignment failed - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
  784. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  785. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
  786. WriteDataLog(j);
  787. continue;
  788. }
  789. UpdateNachkommaDecimalShift();
  790. int previous_value = -1;
  791. if (NUMBERS[j]->analog_roi)
  792. {
  793. NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->ExtendedResolution);
  794. if (NUMBERS[j]->ReturnRawValue.length() > 0)
  795. {
  796. char temp_char = NUMBERS[j]->ReturnRawValue[0];
  797. if (temp_char >= 48 && temp_char <= 57)
  798. {
  799. previous_value = temp_char - 48;
  800. }
  801. }
  802. }
  803. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  804. {
  805. NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue;
  806. }
  807. if (NUMBERS[j]->digit_roi)
  808. {
  809. if (NUMBERS[j]->analog_roi)
  810. {
  811. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogToDigitTransitionStart) + NUMBERS[j]->ReturnRawValue;
  812. }
  813. else
  814. {
  815. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->ExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits
  816. }
  817. }
  818. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  819. if (NUMBERS[j]->IgnoreLeadingNaN)
  820. {
  821. while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N'))
  822. {
  823. NUMBERS[j]->ReturnRawValue.erase(0, 1);
  824. }
  825. }
  826. std::string TempValue = NUMBERS[j]->ReturnRawValue;
  827. if (find_delimiter_pos(TempValue, "N") != std::string::npos)
  828. {
  829. if (PreValueUse && NUMBERS[j]->PreValueValid)
  830. {
  831. TempValue = ErsetzteN(TempValue, NUMBERS[j]->PreValue);
  832. }
  833. else
  834. {
  835. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  836. NUMBERS[j]->timeStampLastValue = imagetime;
  837. NUMBERS[j]->ErrorMessage = true;
  838. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "PreValue not valid - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
  839. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  840. LogFile.WriteToFile(ESP_LOG_INFO, TAG, temp_string);
  841. WriteDataLog(j);
  842. continue; // there is no number because there is still an N.
  843. }
  844. }
  845. // Delete leading zeros (unless there is only one 0 left)
  846. while ((TempValue.length() > 1) && (TempValue[0] == '0'))
  847. {
  848. TempValue.erase(0, 1);
  849. }
  850. NUMBERS[j]->Value = std::stod(TempValue);
  851. NUMBERS[j]->ReturnChangeAbsolute = round_output(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  852. NUMBERS[j]->FlowRateAct = std::stod(round_output(((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / LastPreValueTimeDifference), NUMBERS[j]->Nachkomma));
  853. if (NUMBERS[j]->MaxRateType == RateChange)
  854. {
  855. NUMBERS[j]->ReturnRateValue = std::to_string(NUMBERS[j]->FlowRateAct);
  856. }
  857. else
  858. {
  859. // Difference per round, as a safeguard in case a reading error(Neg. Rate - Read: or Rate too high - Read:) occurs in the meantime
  860. NUMBERS[j]->ReturnRateValue = round_output((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / ((int)(round(LastPreValueTimeDifference / LastValueTimeDifference))), NUMBERS[j]->Nachkomma);
  861. }
  862. if (PreValueUse && NUMBERS[j]->PreValueValid)
  863. {
  864. if ((NUMBERS[j]->Nachkomma > 0) && (NUMBERS[j]->ChangeRateThreshold > 0))
  865. {
  866. double _difference1 = (NUMBERS[j]->PreValue - (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma)));
  867. double _difference2 = (NUMBERS[j]->PreValue + (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma)));
  868. if ((NUMBERS[j]->Value >= _difference1) && (NUMBERS[j]->Value <= _difference2))
  869. {
  870. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  871. }
  872. }
  873. if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  874. {
  875. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name);
  876. if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  877. {
  878. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  879. NUMBERS[j]->timeStampLastValue = imagetime;
  880. NUMBERS[j]->ErrorMessage = true;
  881. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
  882. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  883. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
  884. WriteDataLog(j);
  885. continue;
  886. }
  887. }
  888. if ((NUMBERS[j]->useMaxRateValue) && (NUMBERS[j]->Value != NUMBERS[j]->PreValue))
  889. {
  890. if (abs(std::stod(NUMBERS[j]->ReturnRateValue)) > abs(NUMBERS[j]->MaxRateValue))
  891. {
  892. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  893. NUMBERS[j]->timeStampLastValue = imagetime;
  894. NUMBERS[j]->ErrorMessage = true;
  895. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
  896. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  897. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
  898. WriteDataLog(j);
  899. continue;
  900. }
  901. }
  902. }
  903. NUMBERS[j]->ReturnChangeAbsolute = round_output(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  904. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  905. NUMBERS[j]->PreValueValid = true;
  906. UpdatePreValueINI = true;
  907. NUMBERS[j]->ReturnValue = round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  908. NUMBERS[j]->ReturnPreValue = round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  909. NUMBERS[j]->timeStampLastValue = imagetime;
  910. NUMBERS[j]->timeStampLastPreValue = imagetime;
  911. NUMBERS[j]->ErrorMessage = false;
  912. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "no error - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
  913. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  914. LogFile.WriteToFile(ESP_LOG_INFO, TAG, temp_string);
  915. WriteDataLog(j);
  916. }
  917. SavePreValue();
  918. return true;
  919. }
  920. std::vector<double> ClassFlowPostProcessing::addNumbersTogether(std::vector<double> DigitValues, std::vector<double> AnalogValues)
  921. {
  922. std::vector<double> meterValues;
  923. for (int i = 0; i < DigitValues.size(); ++i)
  924. {
  925. meterValues.push_back(DigitValues[i]);
  926. }
  927. for (int i = 0; i < AnalogValues.size(); ++i)
  928. {
  929. meterValues.push_back(AnalogValues[i]);
  930. }
  931. return meterValues;
  932. }
  933. void ClassFlowPostProcessing::WriteDataLog(int _index)
  934. {
  935. if (!LogFile.GetDataLogToSD())
  936. {
  937. return;
  938. }
  939. std::string analog = "";
  940. std::string digit = "";
  941. char buffer[80];
  942. struct tm *timeinfo = localtime(&NUMBERS[_index]->timeStampLastValue);
  943. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  944. std::string temp_time = std::string(buffer);
  945. if (flowAnalog)
  946. {
  947. analog = flowAnalog->getReadoutRawString(_index);
  948. }
  949. if (flowDigit)
  950. {
  951. digit = flowDigit->getReadoutRawString(_index);
  952. }
  953. LogFile.WriteToData(temp_time, NUMBERS[_index]->name, NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  954. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute, NUMBERS[_index]->ErrorMessageText, digit, analog);
  955. ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digit.c_str(), analog.c_str());
  956. }
  957. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  958. {
  959. for (int j = 0; j < NUMBERS.size(); ++j)
  960. {
  961. // There are only digits
  962. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi)
  963. {
  964. // ESP_LOGD(TAG, "Nurdigit");
  965. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  966. // Extended resolution is on and should also be used for this digit.
  967. if (NUMBERS[j]->ExtendedResolution && flowDigit->isExtendedResolution())
  968. {
  969. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift - 1;
  970. }
  971. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  972. }
  973. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  974. {
  975. // ESP_LOGD(TAG, "Nur analog");
  976. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  977. if (NUMBERS[j]->ExtendedResolution && flowAnalog->isExtendedResolution())
  978. {
  979. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift - 1;
  980. }
  981. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  982. }
  983. // digit + analog
  984. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  985. {
  986. // ESP_LOGD(TAG, "Nur digit + analog");
  987. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  988. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  989. // Extended resolution is on and should also be used for this digit.
  990. if (NUMBERS[j]->ExtendedResolution && flowAnalog->isExtendedResolution())
  991. {
  992. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma + 1;
  993. }
  994. }
  995. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma, NUMBERS[j]->DecimalShift);
  996. }
  997. }
  998. std::string ClassFlowPostProcessing::getReadout(int _number)
  999. {
  1000. return NUMBERS[_number]->ReturnValue;
  1001. }
  1002. std::string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  1003. {
  1004. if (_rawValue)
  1005. {
  1006. return NUMBERS[_number]->ReturnRawValue;
  1007. }
  1008. if (_noerror)
  1009. {
  1010. return NUMBERS[_number]->ReturnValue;
  1011. }
  1012. return NUMBERS[_number]->ReturnValue;
  1013. }
  1014. std::string ClassFlowPostProcessing::ErsetzteN(std::string input, double _prevalue)
  1015. {
  1016. int pot, ziffer;
  1017. int posN = find_delimiter_pos(input, "N");
  1018. int posPunkt = find_delimiter_pos(input, ".");
  1019. if (posPunkt == std::string::npos)
  1020. {
  1021. posPunkt = input.length();
  1022. }
  1023. while (posN != std::string::npos)
  1024. {
  1025. if (posN < posPunkt)
  1026. {
  1027. pot = posPunkt - posN - 1;
  1028. }
  1029. else
  1030. {
  1031. pot = posPunkt - posN;
  1032. }
  1033. float temp_value = _prevalue / pow(10, pot);
  1034. ziffer = ((int)temp_value) % 10;
  1035. input[posN] = ziffer + 48;
  1036. posN = find_delimiter_pos(input, "N");
  1037. }
  1038. return input;
  1039. }
  1040. std::string ClassFlowPostProcessing::getReadoutRate(int _number)
  1041. {
  1042. return std::to_string(NUMBERS[_number]->FlowRateAct);
  1043. }
  1044. std::string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  1045. {
  1046. return NUMBERS[_number]->timeStamp;
  1047. }
  1048. std::string ClassFlowPostProcessing::getReadoutError(int _number)
  1049. {
  1050. return NUMBERS[_number]->ErrorMessageText;
  1051. }