ClassFlowPostProcessing.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  717. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
  718. } else {
  719. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
  720. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  721. NUMBERS[j]->ReturnValue = "";
  722. NUMBERS[j]->lastvalue = imagetime;
  723. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  724. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  725. WriteDataLog(j);
  726. continue;
  727. }
  728. }
  729. }
  730. #ifdef SERIAL_DEBUG
  731. ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value);
  732. #endif
  733. difference /= 60;
  734. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  735. NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct);
  736. if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
  737. {
  738. double _ratedifference;
  739. if (NUMBERS[j]->RateType == RateChange)
  740. _ratedifference = NUMBERS[j]->FlowRateAct;
  741. else
  742. _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue);
  743. if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
  744. {
  745. 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);
  746. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  747. NUMBERS[j]->ReturnValue = "";
  748. NUMBERS[j]->ReturnRateValue = "";
  749. NUMBERS[j]->lastvalue = imagetime;
  750. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  751. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _zw);
  752. WriteDataLog(j);
  753. continue;
  754. }
  755. }
  756. #ifdef SERIAL_DEBUG
  757. ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value);
  758. #endif
  759. NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  760. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  761. NUMBERS[j]->PreValueOkay = true;
  762. NUMBERS[j]->lastvalue = imagetime;
  763. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
  764. NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
  765. NUMBERS[j]->ErrorMessageText = "no error";
  766. UpdatePreValueINI = true;
  767. string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
  768. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  769. WriteDataLog(j);
  770. }
  771. SavePreValue();
  772. return true;
  773. }
  774. void ClassFlowPostProcessing::WriteDataLog(int _index)
  775. {
  776. if (!LogFile.GetDataLogToSD()){
  777. return;
  778. }
  779. string analog = "";
  780. string digital = "";
  781. string timezw = "";
  782. char buffer[80];
  783. struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue);
  784. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  785. timezw = std::string(buffer);
  786. if (flowAnalog)
  787. analog = flowAnalog->getReadoutRawString(_index);
  788. if (flowDigit)
  789. digital = flowDigit->getReadoutRawString(_index);
  790. LogFile.WriteToData(timezw, NUMBERS[_index]->name,
  791. NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue,
  792. NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute,
  793. NUMBERS[_index]->ErrorMessageText,
  794. digital, analog);
  795. 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());
  796. }
  797. void ClassFlowPostProcessing::UpdateNachkommaDecimalShift()
  798. {
  799. for (int j = 0; j < NUMBERS.size(); ++j)
  800. {
  801. if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits
  802. {
  803. // ESP_LOGD(TAG, "Nurdigital");
  804. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  805. if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  806. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  807. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  808. }
  809. if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  810. {
  811. // ESP_LOGD(TAG, "Nur analog");
  812. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  813. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution())
  814. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1;
  815. NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift;
  816. }
  817. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog
  818. {
  819. // ESP_LOGD(TAG, "Nur digital + analog");
  820. NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial;
  821. NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift;
  822. if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit.
  823. NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1;
  824. }
  825. ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift);
  826. }
  827. }
  828. string ClassFlowPostProcessing::getReadout(int _number)
  829. {
  830. return NUMBERS[_number]->ReturnValue;
  831. }
  832. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  833. {
  834. if (_rawValue)
  835. return NUMBERS[_number]->ReturnRawValue;
  836. if (_noerror)
  837. return NUMBERS[_number]->ReturnValue;
  838. return NUMBERS[_number]->ReturnValue;
  839. }
  840. string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
  841. {
  842. int posN, posPunkt;
  843. int pot, ziffer;
  844. float zw;
  845. posN = findDelimiterPos(input, "N");
  846. posPunkt = findDelimiterPos(input, ".");
  847. if (posPunkt == std::string::npos){
  848. posPunkt = input.length();
  849. }
  850. while (posN != std::string::npos)
  851. {
  852. if (posN < posPunkt) {
  853. pot = posPunkt - posN - 1;
  854. }
  855. else {
  856. pot = posPunkt - posN;
  857. }
  858. zw =_prevalue / pow(10, pot);
  859. ziffer = ((int) zw) % 10;
  860. input[posN] = ziffer + 48;
  861. posN = findDelimiterPos(input, "N");
  862. }
  863. return input;
  864. }
  865. float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
  866. int aktdigit, olddigit;
  867. int aktdigit_before, olddigit_before;
  868. int pot, pot_max;
  869. float zw;
  870. bool no_nulldurchgang = false;
  871. pot = _decilamshift;
  872. if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated
  873. {
  874. pot++;
  875. }
  876. #ifdef SERIAL_DEBUG
  877. ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift);
  878. #endif
  879. pot_max = ((int) log10(input)) + 1;
  880. while (pot <= pot_max)
  881. {
  882. zw = input / pow(10, pot-1);
  883. aktdigit_before = ((int) zw) % 10;
  884. zw = _preValue / pow(10, pot-1);
  885. olddigit_before = ((int) zw) % 10;
  886. zw = input / pow(10, pot);
  887. aktdigit = ((int) zw) % 10;
  888. zw = _preValue / pow(10, pot);
  889. olddigit = ((int) zw) % 10;
  890. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  891. if (no_nulldurchgang)
  892. {
  893. if (aktdigit != olddigit)
  894. {
  895. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit;
  896. }
  897. }
  898. else
  899. {
  900. if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1
  901. {
  902. input = input + ((float) (1)) * pow(10, pot); // add 1 at the point
  903. }
  904. }
  905. #ifdef SERIAL_DEBUG
  906. ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input);
  907. #endif
  908. pot++;
  909. }
  910. return input;
  911. }
  912. string ClassFlowPostProcessing::getReadoutRate(int _number)
  913. {
  914. return std::to_string(NUMBERS[_number]->FlowRateAct);
  915. }
  916. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  917. {
  918. return NUMBERS[_number]->timeStamp;
  919. }
  920. string ClassFlowPostProcessing::getReadoutError(int _number)
  921. {
  922. return NUMBERS[_number]->ErrorMessageText;
  923. }