ClassFlowPostProcessing.cpp 38 KB

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