ClassFlowPostProcessing.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. #include "ClassFlowPostProcessing.h"
  2. #include "Helper.h"
  3. #include "ClassFlowTakeImage.h"
  4. #include "ClassLogFile.h"
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <time.h>
  8. #include "time_sntp.h"
  9. #include "esp_log.h"
  10. #include "../../include/defines.h"
  11. static const char* TAG = "POSTPROC";
  12. std::string ClassFlowPostProcessing::getNumbersName()
  13. {
  14. std::string ret="";
  15. for (int i = 0; i < NUMBERS.size(); ++i)
  16. {
  17. ret += NUMBERS[i]->name;
  18. if (i < NUMBERS.size()-1)
  19. ret = ret + "\t";
  20. }
  21. // ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str());
  22. return ret;
  23. }
  24. std::string ClassFlowPostProcessing::GetJSON(std::string _lineend)
  25. {
  26. std::string json="{" + _lineend;
  27. for (int i = 0; i < NUMBERS.size(); ++i)
  28. {
  29. json += "\"" + NUMBERS[i]->name + "\":" + _lineend;
  30. json += getJsonFromNumber(i, _lineend) + _lineend;
  31. if ((i+1) < NUMBERS.size())
  32. json += "," + _lineend;
  33. }
  34. json += "}";
  35. return json;
  36. }
  37. string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _lineend) {
  38. std::string json = "";
  39. json += " {" + _lineend;
  40. if (NUMBERS[i]->ReturnValue.length() > 0)
  41. json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend;
  42. else
  43. json += " \"value\": \"\"," + _lineend;
  44. json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend;
  45. json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend;
  46. json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend;
  47. if (NUMBERS[i]->ReturnRateValue.length() > 0)
  48. json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend;
  49. else
  50. json += " \"rate\": \"\"," + _lineend;
  51. json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend;
  52. json += " }" + _lineend;
  53. return json;
  54. }
  55. string ClassFlowPostProcessing::GetPreValue(std::string _number)
  56. {
  57. std::string result;
  58. int index = -1;
  59. if (_number == "")
  60. _number = "default";
  61. for (int i = 0; i < NUMBERS.size(); ++i)
  62. if (NUMBERS[i]->name == _number)
  63. index = i;
  64. if (index == -1)
  65. return std::string("");
  66. result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma);
  67. return result;
  68. }
  69. bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern)
  70. {
  71. //ESP_LOGD(TAG, "SetPrevalue: %f, %s", zw, _numbers.c_str());
  72. for (int j = 0; j < NUMBERS.size(); ++j) {
  73. //ESP_LOGD(TAG, "Number %d, %s", j, NUMBERS[j]->name.c_str());
  74. if (NUMBERS[j]->name == _numbers) {
  75. if (_newvalue >= 0) { // if new value posivive, use provided value to preset PreValue
  76. NUMBERS[j]->PreValue = _newvalue;
  77. }
  78. else { // if new value negative, use last raw value to preset PreValue
  79. char* p;
  80. double ReturnRawValueAsDouble = strtod(NUMBERS[j]->ReturnRawValue.c_str(), &p);
  81. if (ReturnRawValueAsDouble == 0) {
  82. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: "
  83. + NUMBERS[j]->ReturnRawValue);
  84. return false;
  85. }
  86. NUMBERS[j]->PreValue = ReturnRawValueAsDouble;
  87. }
  88. NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue);
  89. NUMBERS[j]->PreValueOkay = true;
  90. if (_extern)
  91. {
  92. time(&(NUMBERS[j]->lastvalue));
  93. localtime(&(NUMBERS[j]->lastvalue));
  94. }
  95. //ESP_LOGD(TAG, "Found %d! - set to %.8f", j, NUMBERS[j]->PreValue);
  96. UpdatePreValueINI = true; // Only update prevalue file if a new value is set
  97. SavePreValue();
  98. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " +
  99. std::to_string(NUMBERS[j]->PreValue));
  100. return true;
  101. }
  102. }
  103. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: Numbersname not found or not valid");
  104. return false; // No new value was set (e.g. wrong numbersname, no numbers at all)
  105. }
  106. bool ClassFlowPostProcessing::LoadPreValue(void)
  107. {
  108. std::vector<string> splitted;
  109. FILE* pFile;
  110. char zw[1024];
  111. string zwtime, zwvalue, name;
  112. bool _done = false;
  113. UpdatePreValueINI = false; // Conversion to the new format
  114. pFile = fopen(FilePreValue.c_str(), "r");
  115. if (pFile == NULL)
  116. return false;
  117. fgets(zw, 1024, pFile);
  118. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
  119. zwtime = trim(std::string(zw));
  120. if (zwtime.length() == 0)
  121. return false;
  122. splitted = HelperZerlegeZeile(zwtime, "\t");
  123. if (splitted.size() > 1) // Conversion to the new format
  124. {
  125. while ((splitted.size() > 1) && !_done)
  126. {
  127. name = trim(splitted[0]);
  128. zwtime = trim(splitted[1]);
  129. zwvalue = trim(splitted[2]);
  130. for (int j = 0; j < NUMBERS.size(); ++j)
  131. {
  132. if (NUMBERS[j]->name == name)
  133. {
  134. NUMBERS[j]->PreValue = stod(zwvalue.c_str());
  135. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // To be on the safe side, 1 digit more, as Exgtended Resolution may be on (will only be set during the first run).
  136. time_t tStart;
  137. int yy, month, dd, hh, mm, ss;
  138. struct tm whenStart;
  139. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  140. whenStart.tm_year = yy - 1900;
  141. whenStart.tm_mon = month - 1;
  142. whenStart.tm_mday = dd;
  143. whenStart.tm_hour = hh;
  144. whenStart.tm_min = mm;
  145. whenStart.tm_sec = ss;
  146. whenStart.tm_isdst = -1;
  147. NUMBERS[j]->lastvalue = mktime(&whenStart);
  148. time(&tStart);
  149. localtime(&tStart);
  150. double difference = difftime(tStart, NUMBERS[j]->lastvalue);
  151. difference /= 60;
  152. if (difference > PreValueAgeStartup)
  153. NUMBERS[j]->PreValueOkay = false;
  154. else
  155. NUMBERS[j]->PreValueOkay = true;
  156. }
  157. }
  158. if (!fgets(zw, 1024, pFile))
  159. _done = true;
  160. else
  161. {
  162. ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
  163. splitted = HelperZerlegeZeile(trim(std::string(zw)), "\t");
  164. if (splitted.size() > 1)
  165. {
  166. name = trim(splitted[0]);
  167. zwtime = trim(splitted[1]);
  168. zwvalue = trim(splitted[2]);
  169. }
  170. }
  171. }
  172. fclose(pFile);
  173. }
  174. else // Old Format
  175. {
  176. fgets(zw, 1024, pFile);
  177. fclose(pFile);
  178. ESP_LOGD(TAG, "%s", zw);
  179. zwvalue = trim(std::string(zw));
  180. NUMBERS[0]->PreValue = stod(zwvalue.c_str());
  181. time_t tStart;
  182. int yy, month, dd, hh, mm, ss;
  183. struct tm whenStart;
  184. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  185. whenStart.tm_year = yy - 1900;
  186. whenStart.tm_mon = month - 1;
  187. whenStart.tm_mday = dd;
  188. whenStart.tm_hour = hh;
  189. whenStart.tm_min = mm;
  190. whenStart.tm_sec = ss;
  191. whenStart.tm_isdst = -1;
  192. ESP_LOGD(TAG, "TIME: %d, %d, %d, %d, %d, %d", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec);
  193. NUMBERS[0]->lastvalue = mktime(&whenStart);
  194. time(&tStart);
  195. localtime(&tStart);
  196. double difference = difftime(tStart, NUMBERS[0]->lastvalue);
  197. difference /= 60;
  198. if (difference > PreValueAgeStartup)
  199. return false;
  200. NUMBERS[0]->Value = NUMBERS[0]->PreValue;
  201. NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
  202. if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
  203. {
  204. NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma);
  205. }
  206. UpdatePreValueINI = true; // Conversion to the new format
  207. SavePreValue();
  208. }
  209. return true;
  210. }
  211. void ClassFlowPostProcessing::SavePreValue()
  212. {
  213. FILE* pFile;
  214. string _zw;
  215. if (!UpdatePreValueINI) // PreValues unchanged --> File does not have to be rewritten
  216. return;
  217. pFile = fopen(FilePreValue.c_str(), "w");
  218. for (int j = 0; j < NUMBERS.size(); ++j)
  219. {
  220. char buffer[80];
  221. struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue);
  222. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  223. NUMBERS[j]->timeStamp = std::string(buffer);
  224. // ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  225. _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n";
  226. ESP_LOGD(TAG, "Write PreValue line: %s", _zw.c_str());
  227. if (pFile) {
  228. fputs(_zw.c_str(), pFile);
  229. }
  230. }
  231. UpdatePreValueINI = false;
  232. fclose(pFile);
  233. }
  234. ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit)
  235. {
  236. PreValueUse = false;
  237. PreValueAgeStartup = 30;
  238. ErrorMessage = false;
  239. ListFlowControll = NULL;
  240. FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
  241. ListFlowControll = lfc;
  242. flowTakeImage = NULL;
  243. UpdatePreValueINI = false;
  244. IgnoreLeadingNaN = false;
  245. flowAnalog = _analog;
  246. flowDigit = _digit;
  247. for (int i = 0; i < ListFlowControll->size(); ++i)
  248. {
  249. if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0)
  250. {
  251. flowTakeImage = (ClassFlowTakeImage*) (*ListFlowControll)[i];
  252. }
  253. }
  254. }
  255. void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, string _value)
  256. {
  257. string _digit, _decpos;
  258. int _pospunkt = _decsep.find_first_of(".");
  259. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  260. if (_pospunkt > -1)
  261. _digit = _decsep.substr(0, _pospunkt);
  262. else
  263. _digit = "default";
  264. for (int j = 0; j < NUMBERS.size(); ++j)
  265. {
  266. bool _zwdc = false;
  267. if (toUpper(_value) == "TRUE")
  268. _zwdc = true;
  269. if (_digit == "default") // Set to default first (if nothing else is set)
  270. {
  271. NUMBERS[j]->isExtendedResolution = _zwdc;
  272. }
  273. if (NUMBERS[j]->name == _digit)
  274. {
  275. NUMBERS[j]->isExtendedResolution = _zwdc;
  276. }
  277. }
  278. }
  279. void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value)
  280. {
  281. string _digit, _decpos;
  282. int _pospunkt = _decsep.find_first_of(".");
  283. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  284. if (_pospunkt > -1)
  285. _digit = _decsep.substr(0, _pospunkt);
  286. else
  287. _digit = "default";
  288. for (int j = 0; j < NUMBERS.size(); ++j)
  289. {
  290. int _zwdc = 0;
  291. // try
  292. {
  293. _zwdc = stoi(_value);
  294. }
  295. /* catch(const std::exception& e)
  296. {
  297. ESP_LOGD(TAG, "ERROR - Decimalshift is not a number: %s", _value.c_str());
  298. }
  299. */
  300. if (_digit == "default") // Set to default first (if nothing else is set)
  301. {
  302. NUMBERS[j]->DecimalShift = _zwdc;
  303. NUMBERS[j]->DecimalShiftInitial = _zwdc;
  304. }
  305. if (NUMBERS[j]->name == _digit)
  306. {
  307. NUMBERS[j]->DecimalShift = _zwdc;
  308. NUMBERS[j]->DecimalShiftInitial = _zwdc;
  309. }
  310. NUMBERS[j]->Nachkomma = NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift;
  311. }
  312. }
  313. void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value)
  314. {
  315. string _digit, _decpos;
  316. int _pospunkt = _decsep.find_first_of(".");
  317. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  318. if (_pospunkt > -1)
  319. _digit = _decsep.substr(0, _pospunkt);
  320. else
  321. _digit = "default";
  322. for (int j = 0; j < NUMBERS.size(); ++j)
  323. {
  324. float _zwdc = 9.2;
  325. {
  326. _zwdc = stof(_value);
  327. }
  328. if (_digit == "default" || NUMBERS[j]->name == _digit) // Set to default first (if nothing else is set)
  329. {
  330. NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc;
  331. }
  332. }
  333. }
  334. void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _value)
  335. {
  336. string _digit, _decpos;
  337. int _pospunkt = _decsep.find_first_of(".");
  338. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  339. if (_pospunkt > -1)
  340. _digit = _decsep.substr(0, _pospunkt);
  341. else
  342. _digit = "default";
  343. for (int j = 0; j < NUMBERS.size(); ++j)
  344. {
  345. bool _rt = false;
  346. if (toUpper(_value) == "TRUE")
  347. _rt = true;
  348. if (_digit == "default") // Set to default first (if nothing else is set)
  349. {
  350. NUMBERS[j]->AllowNegativeRates = _rt;
  351. }
  352. if (NUMBERS[j]->name == _digit)
  353. {
  354. NUMBERS[j]->AllowNegativeRates = _rt;
  355. }
  356. }
  357. }
  358. void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value)
  359. {
  360. string _digit, _decpos;
  361. int _pospunkt = _decsep.find_first_of(".");
  362. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  363. if (_pospunkt > -1)
  364. _digit = _decsep.substr(0, _pospunkt);
  365. else
  366. _digit = "default";
  367. for (int j = 0; j < NUMBERS.size(); ++j)
  368. {
  369. t_RateType _rt = AbsoluteChange;
  370. if (toUpper(_value) == "RATECHANGE")
  371. _rt = RateChange;
  372. if (_digit == "default") // Set to default first (if nothing else is set)
  373. {
  374. NUMBERS[j]->RateType = _rt;
  375. }
  376. if (NUMBERS[j]->name == _digit)
  377. {
  378. NUMBERS[j]->RateType = _rt;
  379. }
  380. }
  381. }
  382. void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value)
  383. {
  384. string _digit, _decpos;
  385. int _pospunkt = _decsep.find_first_of(".");
  386. // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
  387. if (_pospunkt > -1)
  388. _digit = _decsep.substr(0, _pospunkt);
  389. else
  390. _digit = "default";
  391. for (int j = 0; j < NUMBERS.size(); ++j)
  392. {
  393. float _zwdc = 1;
  394. // try
  395. {
  396. _zwdc = stof(_value);
  397. }
  398. /* catch(const std::exception& e)
  399. {
  400. ESP_LOGD(TAG, "ERROR - MaxRateValue is not a number: %s", _value.c_str());
  401. }
  402. */
  403. if (_digit == "default") // Set to default first (if nothing else is set)
  404. {
  405. NUMBERS[j]->useMaxRateValue = true;
  406. NUMBERS[j]->MaxRateValue = _zwdc;
  407. }
  408. if (NUMBERS[j]->name == _digit)
  409. {
  410. NUMBERS[j]->useMaxRateValue = true;
  411. NUMBERS[j]->MaxRateValue = _zwdc;
  412. }
  413. }
  414. }
  415. bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
  416. {
  417. std::vector<string> splitted;
  418. int _n;
  419. aktparamgraph = trim(aktparamgraph);
  420. if (aktparamgraph.size() == 0)
  421. if (!this->GetNextParagraph(pfile, aktparamgraph))
  422. return false;
  423. if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph does not fit PostProcessing
  424. return false;
  425. InitNUMBERS();
  426. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  427. {
  428. splitted = ZerlegeZeile(aktparamgraph);
  429. std::string _param = GetParameterName(splitted[0]);
  430. if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (splitted.size() > 1))
  431. {
  432. handleDecimalExtendedResolution(splitted[0], splitted[1]);
  433. }
  434. if ((toUpper(_param) == "DECIMALSHIFT") && (splitted.size() > 1))
  435. {
  436. handleDecimalSeparator(splitted[0], splitted[1]);
  437. }
  438. if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (splitted.size() > 1))
  439. {
  440. handleAnalogDigitalTransitionStart(splitted[0], splitted[1]);
  441. }
  442. if ((toUpper(_param) == "MAXRATEVALUE") && (splitted.size() > 1))
  443. {
  444. handleMaxRateValue(splitted[0], splitted[1]);
  445. }
  446. if ((toUpper(_param) == "MAXRATETYPE") && (splitted.size() > 1))
  447. {
  448. handleMaxRateType(splitted[0], splitted[1]);
  449. }
  450. if ((toUpper(_param) == "PREVALUEUSE") && (splitted.size() > 1))
  451. {
  452. if (toUpper(splitted[1]) == "TRUE")
  453. {
  454. PreValueUse = true;
  455. }
  456. }
  457. if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1))
  458. {
  459. if (toUpper(splitted[1]) == "TRUE")
  460. for (_n = 0; _n < NUMBERS.size(); ++_n)
  461. NUMBERS[_n]->checkDigitIncreaseConsistency = true;
  462. }
  463. if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1))
  464. {
  465. handleAllowNegativeRate(splitted[0], splitted[1]);
  466. /* Updated to allow individual Settings
  467. if (toUpper(splitted[1]) == "TRUE")
  468. for (_n = 0; _n < NUMBERS.size(); ++_n)
  469. NUMBERS[_n]->AllowNegativeRates = true;
  470. */
  471. }
  472. if ((toUpper(_param) == "ERRORMESSAGE") && (splitted.size() > 1))
  473. {
  474. if (toUpper(splitted[1]) == "TRUE")
  475. ErrorMessage = true;
  476. }
  477. if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1))
  478. {
  479. if (toUpper(splitted[1]) == "TRUE")
  480. IgnoreLeadingNaN = true;
  481. }
  482. if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1))
  483. {
  484. PreValueAgeStartup = std::stoi(splitted[1]);
  485. }
  486. }
  487. if (PreValueUse) {
  488. LoadPreValue();
  489. }
  490. return true;
  491. }
  492. void ClassFlowPostProcessing::InitNUMBERS()
  493. {
  494. int anzDIGIT = 0;
  495. int anzANALOG = 0;
  496. std::vector<std::string> name_numbers;
  497. if (flowDigit)
  498. {
  499. anzDIGIT = flowDigit->getNumberGENERAL();
  500. flowDigit->UpdateNameNumbers(&name_numbers);
  501. }
  502. if (flowAnalog)
  503. {
  504. anzANALOG = flowAnalog->getNumberGENERAL();
  505. flowAnalog->UpdateNameNumbers(&name_numbers);
  506. }
  507. ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG);
  508. for (int _num = 0; _num < name_numbers.size(); ++_num)
  509. {
  510. NumberPost *_number = new NumberPost;
  511. _number->name = name_numbers[_num];
  512. _number->digit_roi = NULL;
  513. if (flowDigit)
  514. _number->digit_roi = flowDigit->FindGENERAL(name_numbers[_num]);
  515. if (_number->digit_roi)
  516. _number->AnzahlDigital = _number->digit_roi->ROI.size();
  517. else
  518. _number->AnzahlDigital = 0;
  519. _number->analog_roi = NULL;
  520. if (flowAnalog)
  521. _number->analog_roi = flowAnalog->FindGENERAL(name_numbers[_num]);
  522. if (_number->analog_roi)
  523. _number->AnzahlAnalog = _number->analog_roi->ROI.size();
  524. else
  525. _number->AnzahlAnalog = 0;
  526. _number->ReturnRawValue = ""; // Raw value (with N & leading 0).
  527. _number->ReturnValue = ""; // corrected return value, possibly with error message
  528. _number->ErrorMessageText = ""; // Error message for consistency check
  529. _number->ReturnPreValue = "";
  530. _number->PreValueOkay = false;
  531. _number->AllowNegativeRates = false;
  532. _number->MaxRateValue = 0.1;
  533. _number->RateType = AbsoluteChange;
  534. _number->useMaxRateValue = false;
  535. _number->checkDigitIncreaseConsistency = false;
  536. _number->DecimalShift = 0;
  537. _number->DecimalShiftInitial = 0;
  538. _number->isExtendedResolution = false;
  539. _number->AnalogDigitalTransitionStart=9.2;
  540. _number->FlowRateAct = 0; // m3 / min
  541. _number->PreValue = 0; // last value read out well
  542. _number->Value = 0; // last value read out, incl. corrections
  543. _number->ReturnRawValue = ""; // raw value (with N & leading 0)
  544. _number->ReturnValue = ""; // corrected return value, possibly with error message
  545. _number->ErrorMessageText = ""; // Error message for consistency check
  546. _number->Nachkomma = _number->AnzahlAnalog;
  547. NUMBERS.push_back(_number);
  548. }
  549. for (int i = 0; i < NUMBERS.size(); ++i) {
  550. ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog);
  551. }
  552. }
  553. string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
  554. if (_decShift == 0){
  555. return in;
  556. }
  557. int _pos_dec_org, _pos_dec_neu;
  558. _pos_dec_org = findDelimiterPos(in, ".");
  559. if (_pos_dec_org == std::string::npos) {
  560. _pos_dec_org = in.length();
  561. }
  562. else
  563. {
  564. in = in.erase(_pos_dec_org, 1);
  565. }
  566. _pos_dec_neu = _pos_dec_org + _decShift;
  567. if (_pos_dec_neu <= 0) { // comma is before the first digit
  568. for (int i = 0; i > _pos_dec_neu; --i){
  569. in = in.insert(0, "0");
  570. }
  571. in = "0." + in;
  572. return in;
  573. }
  574. if (_pos_dec_neu > in.length()){ // Comma should be after string (123 --> 1230)
  575. for (int i = in.length(); i < _pos_dec_neu; ++i){
  576. in = in.insert(in.length(), "0");
  577. }
  578. return in;
  579. }
  580. string zw;
  581. zw = in.substr(0, _pos_dec_neu);
  582. zw = zw + ".";
  583. zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  584. return zw;
  585. }
  586. bool ClassFlowPostProcessing::doFlow(string zwtime)
  587. {
  588. string result = "";
  589. string digit = "";
  590. string analog = "";
  591. string zwvalue;
  592. string zw;
  593. time_t imagetime = 0;
  594. string rohwert;
  595. // Update decimal point, as the decimal places can also change when changing from CNNType Auto --> xyz:
  596. imagetime = flowTakeImage->getTimeImageTaken();
  597. if (imagetime == 0)
  598. time(&imagetime);
  599. struct tm* timeinfo;
  600. timeinfo = localtime(&imagetime);
  601. char strftime_buf[64];
  602. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  603. zwtime = std::string(strftime_buf);
  604. ESP_LOGD(TAG, "Quantity NUMBERS: %d", NUMBERS.size());
  605. for (int j = 0; j < NUMBERS.size(); ++j)
  606. {
  607. NUMBERS[j]->ReturnRawValue = "";
  608. NUMBERS[j]->ReturnRateValue = "";
  609. NUMBERS[j]->ReturnValue = "";
  610. NUMBERS[j]->ErrorMessageText = "";
  611. NUMBERS[j]->Value = -1;
  612. /* calculate time difference BEFORE we overwrite the 'lastvalue' */
  613. double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in seconds
  614. /* TODO:
  615. * We could call `NUMBERS[j]->lastvalue = imagetime;` here and remove all other such calls further down.
  616. * But we should check nothing breaks! */
  617. UpdateNachkommaDecimalShift();
  618. int previous_value = -1;
  619. if (NUMBERS[j]->analog_roi)
  620. {
  621. NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution);
  622. if (NUMBERS[j]->ReturnRawValue.length() > 0)
  623. {
  624. char zw = NUMBERS[j]->ReturnRawValue[0];
  625. if (zw >= 48 && zw <=57)
  626. previous_value = zw - 48;
  627. }
  628. }
  629. #ifdef SERIAL_DEBUG
  630. ESP_LOGD(TAG, "After analog->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  631. #endif
  632. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  633. NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue;
  634. if (NUMBERS[j]->digit_roi)
  635. {
  636. if (NUMBERS[j]->analog_roi)
  637. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue;
  638. else
  639. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits
  640. }
  641. #ifdef SERIAL_DEBUG
  642. ESP_LOGD(TAG, "After digital->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  643. #endif
  644. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  645. #ifdef SERIAL_DEBUG
  646. ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  647. #endif
  648. if (IgnoreLeadingNaN)
  649. while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N'))
  650. NUMBERS[j]->ReturnRawValue.erase(0, 1);
  651. #ifdef SERIAL_DEBUG
  652. ESP_LOGD(TAG, "After IgnoreLeadingNaN: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
  653. #endif
  654. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
  655. if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos)
  656. {
  657. if (PreValueUse && NUMBERS[j]->PreValueOkay)
  658. {
  659. NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue);
  660. }
  661. else
  662. {
  663. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  664. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  665. /* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */
  666. NUMBERS[j]->lastvalue = imagetime;
  667. WriteDataLog(j);
  668. continue; // there is no number because there is still an N.
  669. }
  670. }
  671. #ifdef SERIAL_DEBUG
  672. ESP_LOGD(TAG, "After findDelimiterPos: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str());
  673. #endif
  674. // Delete leading zeros (unless there is only one 0 left)
  675. while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
  676. NUMBERS[j]->ReturnValue.erase(0, 1);
  677. #ifdef SERIAL_DEBUG
  678. ESP_LOGD(TAG, "After removeLeadingZeros: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str());
  679. #endif
  680. NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue);
  681. #ifdef SERIAL_DEBUG
  682. ESP_LOGD(TAG, "After setting the Value: Value %f and as double is %f", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue));
  683. #endif
  684. if (NUMBERS[j]->checkDigitIncreaseConsistency)
  685. {
  686. if (flowDigit)
  687. {
  688. if (flowDigit->getCNNType() != Digital)
  689. ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)");
  690. else
  691. NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
  692. }
  693. else
  694. {
  695. #ifdef SERIAL_DEBUG
  696. ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digital numbers defined!");
  697. #endif
  698. }
  699. }
  700. #ifdef SERIAL_DEBUG
  701. ESP_LOGD(TAG, "After checkDigitIncreaseConsistency: Value %f", NUMBERS[j]->Value);
  702. #endif
  703. if (!NUMBERS[j]->AllowNegativeRates)
  704. {
  705. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name);
  706. if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  707. {
  708. // more debug if extended resolution is on, see #2447
  709. if (NUMBERS[j]->isExtendedResolution) {
  710. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value)
  711. + ", preValue=" + std::to_string(NUMBERS[j]->PreValue)
  712. + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))));
  713. }
  714. // Include inaccuracy of 0.2 for isExtendedResolution.
  715. if ((NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution)
  716. // not extended resolution allows -1 on the lowest digit
  717. || (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(1/pow(10, NUMBERS[j]->Nachkomma))) && !NUMBERS[j]->isExtendedResolution)) {
  718. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  719. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
  720. }
  721. else {
  722. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
  723. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  724. NUMBERS[j]->ReturnValue = "";
  725. NUMBERS[j]->lastvalue = imagetime;
  726. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  727. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  728. WriteDataLog(j);
  729. continue;
  730. }
  731. }
  732. }
  733. #ifdef SERIAL_DEBUG
  734. ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value);
  735. #endif
  736. difference /= 60;
  737. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  738. NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct);
  739. if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
  740. {
  741. double _ratedifference;
  742. if (NUMBERS[j]->RateType == RateChange)
  743. _ratedifference = NUMBERS[j]->FlowRateAct;
  744. else
  745. _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue);
  746. if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
  747. {
  748. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + RundeOutput(_ratedifference, NUMBERS[j]->Nachkomma);
  749. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  750. NUMBERS[j]->ReturnValue = "";
  751. NUMBERS[j]->ReturnRateValue = "";
  752. NUMBERS[j]->lastvalue = imagetime;
  753. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  754. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  755. WriteDataLog(j);
  756. continue;
  757. }
  758. }
  759. #ifdef SERIAL_DEBUG
  760. ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value);
  761. #endif
  762. NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  763. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  764. NUMBERS[j]->PreValueOkay = true;
  765. NUMBERS[j]->lastvalue = imagetime;
  766. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  767. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  768. NUMBERS[j]->ErrorMessageText = "no error";
  769. UpdatePreValueINI = true;
  770. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  771. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  772. WriteDataLog(j);
  773. }
  774. SavePreValue();
  775. return true;
  776. }
  777. void ClassFlowPostProcessing::WriteDataLog(int _index)
  778. {
  779. if (!LogFile.GetDataLogToSD()){
  780. return;
  781. }
  782. string analog = "";
  783. string digital = "";
  784. string timezw = "";
  785. char buffer[80];
  786. struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue);
  787. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  788. timezw = std::string(buffer);
  789. if (flowAnalog)
  790. analog = flowAnalog->getReadoutRawString(_index);
  791. if (flowDigit)
  792. digital = flowDigit->getReadoutRawString(_index);
  793. LogFile.WriteToData(timezw, NUMBERS[_index]->name,
  794. NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  795. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute,
  796. NUMBERS[_index]->ErrorMessageText,
  797. digital, analog);
  798. ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digital.c_str(), analog.c_str());
  799. }
  800. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  801. {
  802. for (int j = 0; j < NUMBERS.size(); ++j)
  803. {
  804. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits
  805. {
  806. // ESP_LOGD(TAG, "Nurdigital");
  807. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  808. if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  809. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  810. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  811. }
  812. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  813. {
  814. // ESP_LOGD(TAG, "Nur analog");
  815. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  816. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  817. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  818. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  819. }
  820. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog
  821. {
  822. // ESP_LOGD(TAG, "Nur digital + analog");
  823. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  824. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  825. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  826. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1;
  827. }
  828. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift);
  829. }
  830. }
  831. string ClassFlowPostProcessing::getReadout(int _number)
  832. {
  833. return NUMBERS[_number]->ReturnValue;
  834. }
  835. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  836. {
  837. if (_rawValue)
  838. return NUMBERS[_number]->ReturnRawValue;
  839. if (_noerror)
  840. return NUMBERS[_number]->ReturnValue;
  841. return NUMBERS[_number]->ReturnValue;
  842. }
  843. string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
  844. {
  845. int posN, posPunkt;
  846. int pot, ziffer;
  847. float zw;
  848. posN = findDelimiterPos(input, "N");
  849. posPunkt = findDelimiterPos(input, ".");
  850. if (posPunkt == std::string::npos){
  851. posPunkt = input.length();
  852. }
  853. while (posN != std::string::npos)
  854. {
  855. if (posN < posPunkt) {
  856. pot = posPunkt - posN - 1;
  857. }
  858. else {
  859. pot = posPunkt - posN;
  860. }
  861. zw =_prevalue / pow(10, pot);
  862. ziffer = ((int) zw) % 10;
  863. input[posN] = ziffer + 48;
  864. posN = findDelimiterPos(input, "N");
  865. }
  866. return input;
  867. }
  868. float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
  869. int aktdigit, olddigit;
  870. int aktdigit_before, olddigit_before;
  871. int pot, pot_max;
  872. float zw;
  873. bool no_nulldurchgang = false;
  874. pot = _decilamshift;
  875. if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated
  876. {
  877. pot++;
  878. }
  879. #ifdef SERIAL_DEBUG
  880. ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift);
  881. #endif
  882. pot_max = ((int) log10(input)) + 1;
  883. while (pot <= pot_max)
  884. {
  885. zw = input / pow(10, pot-1);
  886. aktdigit_before = ((int) zw) % 10;
  887. zw = _preValue / pow(10, pot-1);
  888. olddigit_before = ((int) zw) % 10;
  889. zw = input / pow(10, pot);
  890. aktdigit = ((int) zw) % 10;
  891. zw = _preValue / pow(10, pot);
  892. olddigit = ((int) zw) % 10;
  893. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  894. if (no_nulldurchgang)
  895. {
  896. if (aktdigit != olddigit)
  897. {
  898. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit;
  899. }
  900. }
  901. else
  902. {
  903. if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1
  904. {
  905. input = input + ((float) (1)) * pow(10, pot); // add 1 at the point
  906. }
  907. }
  908. #ifdef SERIAL_DEBUG
  909. ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input);
  910. #endif
  911. pot++;
  912. }
  913. return input;
  914. }
  915. string ClassFlowPostProcessing::getReadoutRate(int _number)
  916. {
  917. return std::to_string(NUMBERS[_number]->FlowRateAct);
  918. }
  919. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  920. {
  921. return NUMBERS[_number]->timeStamp;
  922. }
  923. string ClassFlowPostProcessing::getReadoutError(int _number)
  924. {
  925. return NUMBERS[_number]->ErrorMessageText;
  926. }