ClassFlowPostProcessing.cpp 38 KB

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