ClassFlowPostProcessing.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. SkipErrorMessage = false;
  287. ListFlowControll = NULL;
  288. FilePreValue = format_filename("/sdcard/config/prevalue.ini");
  289. ListFlowControll = lfc;
  290. flowTakeImage = NULL;
  291. UpdatePreValueINI = false;
  292. flowAnalog = _analog;
  293. flowDigit = _digit;
  294. for (int i = 0; i < ListFlowControll->size(); ++i)
  295. {
  296. if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0)
  297. {
  298. flowTakeImage = (ClassFlowTakeImage *)(*ListFlowControll)[i];
  299. }
  300. }
  301. }
  302. void ClassFlowPostProcessing::handleDecimalExtendedResolution(std::string _decsep, std::string _value)
  303. {
  304. std::string _digit;
  305. int _pospunkt = _decsep.find_first_of(".");
  306. if (_pospunkt > -1)
  307. {
  308. _digit = _decsep.substr(0, _pospunkt);
  309. }
  310. else
  311. {
  312. _digit = "default";
  313. }
  314. for (int j = 0; j < NUMBERS.size(); ++j)
  315. {
  316. bool temp_value = alphanumeric_to_boolean(_value);
  317. // Set to default first (if nothing else is set)
  318. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  319. {
  320. NUMBERS[j]->isExtendedResolution = temp_value;
  321. }
  322. }
  323. }
  324. void ClassFlowPostProcessing::handleDecimalSeparator(std::string _decsep, std::string _value)
  325. {
  326. std::string _digit;
  327. int _pospunkt = _decsep.find_first_of(".");
  328. if (_pospunkt > -1)
  329. {
  330. _digit = _decsep.substr(0, _pospunkt);
  331. }
  332. else
  333. {
  334. _digit = "default";
  335. }
  336. for (int j = 0; j < NUMBERS.size(); ++j)
  337. {
  338. int temp_value = 0;
  339. if (is_string_numeric(_value))
  340. {
  341. temp_value = std::stoi(_value);
  342. }
  343. // Set to default first (if nothing else is set)
  344. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  345. {
  346. NUMBERS[j]->DecimalShift = temp_value;
  347. NUMBERS[j]->DecimalShiftInitial = temp_value;
  348. }
  349. NUMBERS[j]->Nachkomma = NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift;
  350. }
  351. }
  352. void ClassFlowPostProcessing::handleAnalogToDigitTransitionStart(std::string _decsep, std::string _value)
  353. {
  354. std::string _digit;
  355. int _pospunkt = _decsep.find_first_of(".");
  356. if (_pospunkt > -1)
  357. {
  358. _digit = _decsep.substr(0, _pospunkt);
  359. }
  360. else
  361. {
  362. _digit = "default";
  363. }
  364. for (int j = 0; j < NUMBERS.size(); ++j)
  365. {
  366. float temp_value = 9.2;
  367. if (is_string_numeric(_value))
  368. {
  369. temp_value = std::stof(_value);
  370. }
  371. // Set to default first (if nothing else is set)
  372. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  373. {
  374. NUMBERS[j]->AnalogToDigitTransitionStart = temp_value;
  375. }
  376. }
  377. }
  378. void ClassFlowPostProcessing::handleAllowNegativeRate(std::string _decsep, std::string _value)
  379. {
  380. std::string _digit;
  381. int _pospunkt = _decsep.find_first_of(".");
  382. if (_pospunkt > -1)
  383. {
  384. _digit = _decsep.substr(0, _pospunkt);
  385. }
  386. else
  387. {
  388. _digit = "default";
  389. }
  390. for (int j = 0; j < NUMBERS.size(); ++j)
  391. {
  392. bool temp_value = alphanumeric_to_boolean(_value);
  393. // Set to default first (if nothing else is set)
  394. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  395. {
  396. NUMBERS[j]->AllowNegativeRates = temp_value;
  397. }
  398. }
  399. }
  400. void ClassFlowPostProcessing::handleIgnoreLeadingNaN(std::string _decsep, std::string _value)
  401. {
  402. std::string _digit;
  403. int _pospunkt = _decsep.find_first_of(".");
  404. if (_pospunkt > -1)
  405. {
  406. _digit = _decsep.substr(0, _pospunkt);
  407. }
  408. else
  409. {
  410. _digit = "default";
  411. }
  412. for (int j = 0; j < NUMBERS.size(); ++j)
  413. {
  414. bool temp_value = alphanumeric_to_boolean(_value);
  415. // Set to default first (if nothing else is set)
  416. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  417. {
  418. NUMBERS[j]->IgnoreLeadingNaN = temp_value;
  419. }
  420. }
  421. }
  422. void ClassFlowPostProcessing::handleMaxFlowRate(std::string _decsep, std::string _value)
  423. {
  424. std::string _digit;
  425. int _pospunkt = _decsep.find_first_of(".");
  426. if (_pospunkt > -1)
  427. {
  428. _digit = _decsep.substr(0, _pospunkt);
  429. }
  430. else
  431. {
  432. _digit = "default";
  433. }
  434. for (int j = 0; j < NUMBERS.size(); ++j)
  435. {
  436. float temp_value = 4.0;
  437. if (is_string_numeric(_value))
  438. {
  439. temp_value = std::stof(_value);
  440. }
  441. // Set to default first (if nothing else is set)
  442. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  443. {
  444. NUMBERS[j]->useMaxFlowRate = true;
  445. NUMBERS[j]->MaxFlowRate = temp_value;
  446. }
  447. }
  448. }
  449. void ClassFlowPostProcessing::handleMaxRateType(std::string _decsep, std::string _value)
  450. {
  451. std::string _digit, _decpos;
  452. int _pospunkt = _decsep.find_first_of(".");
  453. if (_pospunkt > -1)
  454. {
  455. _digit = _decsep.substr(0, _pospunkt);
  456. }
  457. else
  458. {
  459. _digit = "default";
  460. }
  461. for (int j = 0; j < NUMBERS.size(); ++j)
  462. {
  463. t_RateType temp_value = AbsoluteChange;
  464. if (to_upper(_value) == "RATECHANGE")
  465. {
  466. temp_value = RateChange;
  467. }
  468. // Set to default first (if nothing else is set)
  469. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  470. {
  471. NUMBERS[j]->MaxRateType = temp_value;
  472. }
  473. }
  474. }
  475. void ClassFlowPostProcessing::handleMaxRateValue(std::string _decsep, std::string _value)
  476. {
  477. std::string _digit;
  478. int _pospunkt = _decsep.find_first_of(".");
  479. if (_pospunkt > -1)
  480. {
  481. _digit = _decsep.substr(0, _pospunkt);
  482. }
  483. else
  484. {
  485. _digit = "default";
  486. }
  487. for (int j = 0; j < NUMBERS.size(); ++j)
  488. {
  489. float temp_value = 1;
  490. if (is_string_numeric(_value))
  491. {
  492. temp_value = std::stof(_value);
  493. }
  494. // Set to default first (if nothing else is set)
  495. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  496. {
  497. NUMBERS[j]->useMaxRateValue = true;
  498. NUMBERS[j]->MaxRateValue = temp_value;
  499. }
  500. }
  501. }
  502. void ClassFlowPostProcessing::handleChangeRateThreshold(std::string _decsep, std::string _value)
  503. {
  504. std::string _digit;
  505. int _pospunkt = _decsep.find_first_of(".");
  506. if (_pospunkt > -1)
  507. {
  508. _digit = _decsep.substr(0, _pospunkt);
  509. }
  510. else
  511. {
  512. _digit = "default";
  513. }
  514. for (int j = 0; j < NUMBERS.size(); ++j)
  515. {
  516. int temp_value = 2;
  517. if (is_string_numeric(_value))
  518. {
  519. temp_value = std::stof(_value);
  520. }
  521. // Set to default first (if nothing else is set)
  522. if ((_digit == "default") || (NUMBERS[j]->name == _digit))
  523. {
  524. NUMBERS[j]->ChangeRateThreshold = temp_value;
  525. }
  526. }
  527. }
  528. bool ClassFlowPostProcessing::ReadParameter(FILE *pFile, std::string &aktparamgraph)
  529. {
  530. aktparamgraph = trim_string_left_right(aktparamgraph);
  531. if (aktparamgraph.size() == 0)
  532. {
  533. if (!GetNextParagraph(pFile, aktparamgraph))
  534. {
  535. return false;
  536. }
  537. }
  538. // Paragraph does not fit PostProcessing
  539. if ((to_upper(aktparamgraph).compare("[POSTPROCESSING]") != 0) && (to_upper(aktparamgraph).compare(";[POSTPROCESSING]") != 0))
  540. {
  541. return false;
  542. }
  543. InitNUMBERS();
  544. std::vector<std::string> splitted;
  545. while (getNextLine(pFile, &aktparamgraph) && !isNewParagraph(aktparamgraph))
  546. {
  547. splitted = split_line(aktparamgraph);
  548. if (splitted.size() > 1)
  549. {
  550. std::string _param = to_upper(GetParameterName(splitted[0]));
  551. if (_param == "PREVALUEUSE")
  552. {
  553. PreValueUse = alphanumeric_to_boolean(splitted[1]);
  554. }
  555. else if (_param == "PREVALUEAGESTARTUP")
  556. {
  557. if (is_string_numeric(splitted[1]))
  558. {
  559. PreValueAgeStartup = std::stoi(splitted[1]);
  560. }
  561. }
  562. else if (_param == "SKIPERRORMESSAGE")
  563. {
  564. SkipErrorMessage = alphanumeric_to_boolean(splitted[1]);
  565. }
  566. else if (_param == "ALLOWNEGATIVERATES")
  567. {
  568. handleAllowNegativeRate(splitted[0], splitted[1]);
  569. }
  570. else if (_param == "DECIMALSHIFT")
  571. {
  572. handleDecimalSeparator(splitted[0], splitted[1]);
  573. }
  574. else if (_param == "ANALOGTODIGITTRANSITIONSTART")
  575. {
  576. handleAnalogToDigitTransitionStart(splitted[0], splitted[1]);
  577. }
  578. else if (_param == "MAXFLOWRATE")
  579. {
  580. handleMaxFlowRate(splitted[0], splitted[1]);
  581. }
  582. else if (_param == "MAXRATEVALUE")
  583. {
  584. handleMaxRateValue(splitted[0], splitted[1]);
  585. }
  586. else if (_param == "MAXRATETYPE")
  587. {
  588. handleMaxRateType(splitted[0], splitted[1]);
  589. }
  590. else if (_param == "CHANGERATETHRESHOLD")
  591. {
  592. handleChangeRateThreshold(splitted[0], splitted[1]);
  593. }
  594. else if (_param == "EXTENDEDRESOLUTION")
  595. {
  596. handleDecimalExtendedResolution(splitted[0], splitted[1]);
  597. }
  598. else if (_param == "IGNORELEADINGNAN")
  599. {
  600. handleIgnoreLeadingNaN(splitted[0], splitted[1]);
  601. }
  602. }
  603. }
  604. if (PreValueUse)
  605. {
  606. return LoadPreValue();
  607. }
  608. return true;
  609. }
  610. void ClassFlowPostProcessing::InitNUMBERS()
  611. {
  612. std::vector<std::string> name_numbers;
  613. if (flowDigit)
  614. {
  615. int anzDIGIT = flowDigit->getNumberGENERAL();
  616. flowDigit->UpdateNameNumbers(&name_numbers);
  617. ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d", name_numbers.size(), anzDIGIT);
  618. }
  619. if (flowAnalog)
  620. {
  621. int anzANALOG = flowAnalog->getNumberGENERAL();
  622. flowAnalog->UpdateNameNumbers(&name_numbers);
  623. ESP_LOGD(TAG, "Anzahl NUMBERS: %d - ANALOG: %d", name_numbers.size(), anzANALOG);
  624. }
  625. for (int _num = 0; _num < name_numbers.size(); ++_num)
  626. {
  627. NumberPost *_number = new NumberPost;
  628. _number->name = name_numbers[_num];
  629. _number->digit_roi = NULL;
  630. if (flowDigit)
  631. {
  632. _number->digit_roi = flowDigit->FindGENERAL(name_numbers[_num]);
  633. }
  634. if (_number->digit_roi)
  635. {
  636. _number->AnzahlDigit = _number->digit_roi->ROI.size();
  637. }
  638. else
  639. {
  640. _number->AnzahlDigit = 0;
  641. }
  642. _number->analog_roi = NULL;
  643. if (flowAnalog)
  644. {
  645. _number->analog_roi = flowAnalog->FindGENERAL(name_numbers[_num]);
  646. }
  647. if (_number->analog_roi)
  648. {
  649. _number->AnzahlAnalog = _number->analog_roi->ROI.size();
  650. }
  651. else
  652. {
  653. _number->AnzahlAnalog = 0;
  654. }
  655. _number->PreValue = 0.0f; // last value read out well
  656. _number->ReturnPreValue = "";
  657. _number->PreValueValid = false;
  658. _number->ErrorMessage = false;
  659. _number->ErrorMessageText = ""; // Error message for consistency check
  660. _number->AllowNegativeRates = false;
  661. _number->DecimalShift = 0;
  662. _number->DecimalShiftInitial = 0;
  663. _number->AnalogToDigitTransitionStart = 9.2f;
  664. _number->MaxFlowRate = 4.0f;
  665. _number->useMaxFlowRate = false;
  666. _number->MaxRateValue = 0.1f;
  667. _number->MaxRateType = AbsoluteChange;
  668. _number->useMaxRateValue = false;
  669. _number->ChangeRateThreshold = 2;
  670. _number->isExtendedResolution = false;
  671. _number->IgnoreLeadingNaN = false;
  672. _number->Value = 0.0f; // last value read out, incl. corrections
  673. _number->ReturnValue = ""; // corrected return value, possibly with error message
  674. _number->ReturnRawValue = ""; // raw value (with N & leading 0)
  675. _number->FlowRateAct = 0.0f; // m3 / min
  676. _number->Nachkomma = _number->AnzahlAnalog;
  677. NUMBERS.push_back(_number);
  678. }
  679. for (int i = 0; i < NUMBERS.size(); ++i)
  680. {
  681. ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigit, NUMBERS[i]->AnzahlAnalog);
  682. }
  683. }
  684. std::string ClassFlowPostProcessing::ShiftDecimal(std::string in, int _decShift)
  685. {
  686. if (_decShift == 0)
  687. {
  688. return in;
  689. }
  690. int _pos_dec_org = find_delimiter_pos(in, ".");
  691. if (_pos_dec_org == std::string::npos)
  692. {
  693. _pos_dec_org = in.length();
  694. }
  695. else
  696. {
  697. in = in.erase(_pos_dec_org, 1);
  698. }
  699. int _pos_dec_neu = _pos_dec_org + _decShift;
  700. // comma is before the first digit
  701. if (_pos_dec_neu <= 0)
  702. {
  703. for (int i = 0; i > _pos_dec_neu; --i)
  704. {
  705. in = in.insert(0, "0");
  706. }
  707. in = "0." + in;
  708. return in;
  709. }
  710. // Comma should be after string (123 --> 1230)
  711. if (_pos_dec_neu > in.length())
  712. {
  713. for (int i = in.length(); i < _pos_dec_neu; ++i)
  714. {
  715. in = in.insert(in.length(), "0");
  716. }
  717. return in;
  718. }
  719. std::string temp_string = in.substr(0, _pos_dec_neu);
  720. temp_string = temp_string + ".";
  721. temp_string = temp_string + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  722. return temp_string;
  723. }
  724. bool ClassFlowPostProcessing::doFlow(std::string temp_time)
  725. {
  726. time_t imagetime = flowTakeImage->getTimeImageTaken();
  727. if (imagetime == 0)
  728. {
  729. time(&imagetime);
  730. }
  731. struct tm *timeinfo = localtime(&imagetime);
  732. char strftime_buf[64];
  733. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  734. temp_time = std::string(strftime_buf);
  735. for (int j = 0; j < NUMBERS.size(); ++j)
  736. {
  737. NUMBERS[j]->ErrorMessage = false;
  738. NUMBERS[j]->ErrorMessageText = "";
  739. NUMBERS[j]->Value = -1;
  740. if (SkipErrorMessage)
  741. {
  742. NUMBERS[j]->ReturnValue = std::to_string(NUMBERS[j]->PreValue);
  743. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnValue;
  744. }
  745. else
  746. {
  747. NUMBERS[j]->ReturnValue = "";
  748. NUMBERS[j]->ReturnRawValue = "";
  749. }
  750. NUMBERS[j]->FlowRateAct = 0.0f;
  751. NUMBERS[j]->ReturnRateValue = round_output(0.0f, NUMBERS[j]->Nachkomma);
  752. NUMBERS[j]->ReturnChangeAbsolute = NUMBERS[j]->ReturnRateValue;
  753. // calculate time difference
  754. double LastValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastValue) / 60; // in minutes
  755. double LastPreValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastPreValue) / 60; // in minutes
  756. if (!flowctrl.AlignmentOk)
  757. {
  758. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  759. NUMBERS[j]->timeStampLastValue = imagetime;
  760. NUMBERS[j]->ErrorMessage = true;
  761. 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;
  762. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  763. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
  764. WriteDataLog(j);
  765. continue;
  766. }
  767. UpdateNachkommaDecimalShift();
  768. int previous_value = -1;
  769. if (NUMBERS[j]->analog_roi)
  770. {
  771. NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution);
  772. if (NUMBERS[j]->ReturnRawValue.length() > 0)
  773. {
  774. char temp_char = NUMBERS[j]->ReturnRawValue[0];
  775. if (temp_char >= 48 && temp_char <= 57)
  776. {
  777. previous_value = temp_char - 48;
  778. }
  779. }
  780. }
  781. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  782. {
  783. NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue;
  784. }
  785. if (NUMBERS[j]->digit_roi)
  786. {
  787. if (NUMBERS[j]->analog_roi)
  788. {
  789. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogToDigitTransitionStart) + NUMBERS[j]->ReturnRawValue;
  790. }
  791. else
  792. {
  793. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits
  794. }
  795. }
  796. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  797. if (NUMBERS[j]->IgnoreLeadingNaN)
  798. {
  799. while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N'))
  800. {
  801. NUMBERS[j]->ReturnRawValue.erase(0, 1);
  802. }
  803. }
  804. std::string TempValue = NUMBERS[j]->ReturnRawValue;
  805. if (find_delimiter_pos(TempValue, "N") != std::string::npos)
  806. {
  807. if (PreValueUse && NUMBERS[j]->PreValueValid)
  808. {
  809. TempValue = ErsetzteN(TempValue, NUMBERS[j]->PreValue);
  810. }
  811. else
  812. {
  813. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  814. NUMBERS[j]->timeStampLastValue = imagetime;
  815. NUMBERS[j]->ErrorMessage = true;
  816. 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;
  817. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  818. LogFile.WriteToFile(ESP_LOG_INFO, TAG, temp_string);
  819. WriteDataLog(j);
  820. continue; // there is no number because there is still an N.
  821. }
  822. }
  823. // Delete leading zeros (unless there is only one 0 left)
  824. while ((TempValue.length() > 1) && (TempValue[0] == '0'))
  825. {
  826. TempValue.erase(0, 1);
  827. }
  828. NUMBERS[j]->Value = std::stod(TempValue);
  829. NUMBERS[j]->ReturnChangeAbsolute = round_output(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  830. NUMBERS[j]->FlowRateAct = std::stod(round_output(((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / LastPreValueTimeDifference), NUMBERS[j]->Nachkomma));
  831. if (NUMBERS[j]->MaxRateType == RateChange)
  832. {
  833. NUMBERS[j]->ReturnRateValue = std::to_string(NUMBERS[j]->FlowRateAct);
  834. }
  835. else
  836. {
  837. // Difference per round, as a safeguard in case a reading error(Neg. Rate - Read: or Rate too high - Read:) occurs in the meantime
  838. NUMBERS[j]->ReturnRateValue = round_output((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / ((int)(round(LastPreValueTimeDifference / LastValueTimeDifference))), NUMBERS[j]->Nachkomma);
  839. }
  840. if (PreValueUse && NUMBERS[j]->PreValueValid)
  841. {
  842. if ((NUMBERS[j]->Nachkomma > 0) && (NUMBERS[j]->ChangeRateThreshold > 0))
  843. {
  844. double _difference1 = (NUMBERS[j]->PreValue - (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma)));
  845. double _difference2 = (NUMBERS[j]->PreValue + (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma)));
  846. if ((NUMBERS[j]->Value >= _difference1) && (NUMBERS[j]->Value <= _difference2))
  847. {
  848. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  849. }
  850. }
  851. if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  852. {
  853. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name);
  854. if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  855. {
  856. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  857. NUMBERS[j]->timeStampLastValue = imagetime;
  858. NUMBERS[j]->ErrorMessage = true;
  859. 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;
  860. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  861. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
  862. WriteDataLog(j);
  863. continue;
  864. }
  865. }
  866. if ((NUMBERS[j]->useMaxRateValue) && (NUMBERS[j]->Value != NUMBERS[j]->PreValue))
  867. {
  868. if (abs(std::stod(NUMBERS[j]->ReturnRateValue)) > abs(NUMBERS[j]->MaxRateValue))
  869. {
  870. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  871. NUMBERS[j]->timeStampLastValue = imagetime;
  872. NUMBERS[j]->ErrorMessage = true;
  873. 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;
  874. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  875. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
  876. WriteDataLog(j);
  877. continue;
  878. }
  879. }
  880. }
  881. NUMBERS[j]->ReturnChangeAbsolute = round_output(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  882. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  883. NUMBERS[j]->PreValueValid = true;
  884. UpdatePreValueINI = true;
  885. NUMBERS[j]->ReturnValue = round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  886. NUMBERS[j]->ReturnPreValue = round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  887. NUMBERS[j]->timeStampLastValue = imagetime;
  888. NUMBERS[j]->timeStampLastPreValue = imagetime;
  889. NUMBERS[j]->ErrorMessage = false;
  890. 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;
  891. std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  892. LogFile.WriteToFile(ESP_LOG_INFO, TAG, temp_string);
  893. WriteDataLog(j);
  894. }
  895. SavePreValue();
  896. return true;
  897. }
  898. std::vector<double> ClassFlowPostProcessing::addNumbersTogether(std::vector<double> DigitValues, std::vector<double> AnalogValues)
  899. {
  900. std::vector<double> meterValues;
  901. for (int i = 0; i < DigitValues.size(); ++i)
  902. {
  903. meterValues.push_back(DigitValues[i]);
  904. }
  905. for (int i = 0; i < AnalogValues.size(); ++i)
  906. {
  907. meterValues.push_back(AnalogValues[i]);
  908. }
  909. return meterValues;
  910. }
  911. void ClassFlowPostProcessing::WriteDataLog(int _index)
  912. {
  913. if (!LogFile.GetDataLogToSD())
  914. {
  915. return;
  916. }
  917. std::string analog = "";
  918. std::string digit = "";
  919. char buffer[80];
  920. struct tm *timeinfo = localtime(&NUMBERS[_index]->timeStampLastValue);
  921. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  922. std::string temp_time = std::string(buffer);
  923. if (flowAnalog)
  924. {
  925. analog = flowAnalog->getReadoutRawString(_index);
  926. }
  927. if (flowDigit)
  928. {
  929. digit = flowDigit->getReadoutRawString(_index);
  930. }
  931. LogFile.WriteToData(temp_time, NUMBERS[_index]->name, NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  932. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute, NUMBERS[_index]->ErrorMessageText, digit, analog);
  933. 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());
  934. }
  935. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  936. {
  937. for (int j = 0; j < NUMBERS.size(); ++j)
  938. {
  939. // There are only digits
  940. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi)
  941. {
  942. // ESP_LOGD(TAG, "Nurdigit");
  943. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  944. // Extended resolution is on and should also be used for this digit.
  945. if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution())
  946. {
  947. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift - 1;
  948. }
  949. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  950. }
  951. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  952. {
  953. // ESP_LOGD(TAG, "Nur analog");
  954. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  955. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  956. {
  957. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift - 1;
  958. }
  959. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  960. }
  961. // digit + analog
  962. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  963. {
  964. // ESP_LOGD(TAG, "Nur digit + analog");
  965. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  966. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  967. // Extended resolution is on and should also be used for this digit.
  968. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  969. {
  970. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma + 1;
  971. }
  972. }
  973. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma, NUMBERS[j]->DecimalShift);
  974. }
  975. }
  976. std::string ClassFlowPostProcessing::getReadout(int _number)
  977. {
  978. return NUMBERS[_number]->ReturnValue;
  979. }
  980. std::string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  981. {
  982. if (_rawValue)
  983. {
  984. return NUMBERS[_number]->ReturnRawValue;
  985. }
  986. if (_noerror)
  987. {
  988. return NUMBERS[_number]->ReturnValue;
  989. }
  990. return NUMBERS[_number]->ReturnValue;
  991. }
  992. std::string ClassFlowPostProcessing::ErsetzteN(std::string input, double _prevalue)
  993. {
  994. int pot, ziffer;
  995. int posN = find_delimiter_pos(input, "N");
  996. int posPunkt = find_delimiter_pos(input, ".");
  997. if (posPunkt == std::string::npos)
  998. {
  999. posPunkt = input.length();
  1000. }
  1001. while (posN != std::string::npos)
  1002. {
  1003. if (posN < posPunkt)
  1004. {
  1005. pot = posPunkt - posN - 1;
  1006. }
  1007. else
  1008. {
  1009. pot = posPunkt - posN;
  1010. }
  1011. float temp_value = _prevalue / pow(10, pot);
  1012. ziffer = ((int)temp_value) % 10;
  1013. input[posN] = ziffer + 48;
  1014. posN = find_delimiter_pos(input, "N");
  1015. }
  1016. return input;
  1017. }
  1018. std::string ClassFlowPostProcessing::getReadoutRate(int _number)
  1019. {
  1020. return std::to_string(NUMBERS[_number]->FlowRateAct);
  1021. }
  1022. std::string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  1023. {
  1024. return NUMBERS[_number]->timeStamp;
  1025. }
  1026. std::string ClassFlowPostProcessing::getReadoutError(int _number)
  1027. {
  1028. return NUMBERS[_number]->ErrorMessageText;
  1029. }