ClassFlowPostProcessing.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. #include "ClassFlowPostProcessing.h"
  2. #include "Helper.h"
  3. #include "ClassFlowMakeImage.h"
  4. #include "ClassLogFile.h"
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <time.h>
  8. #include "time_sntp.h"
  9. #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S"
  10. #define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
  11. string ClassFlowPostProcessing::GetPreValue(std::string _number)
  12. {
  13. std::string result;
  14. int index = -1;
  15. if (_number == "")
  16. _number = "default";
  17. for (int i = 0; i < NUMBERS.size(); ++i)
  18. if (NUMBERS[i]->name == _number)
  19. index = i;
  20. result = RundeOutput(NUMBERS[index]->PreValue, -NUMBERS[index]->DecimalShift);
  21. if (NUMBERS[index]->digit_roi && NUMBERS[index]->analog_roi)
  22. result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->AnzahlAnalog - NUMBERS[index]->DecimalShift);
  23. return result;
  24. }
  25. void ClassFlowPostProcessing::SetPreValue(float zw, string _numbers)
  26. {
  27. for (int j = 0; j < NUMBERS.size(); ++j)
  28. {
  29. if (NUMBERS[j]->name == _numbers)
  30. NUMBERS[j]->PreValue = zw;
  31. }
  32. UpdatePreValueINI = true;
  33. SavePreValue();
  34. }
  35. bool ClassFlowPostProcessing::LoadPreValue(void)
  36. {
  37. std::vector<string> zerlegt;
  38. FILE* pFile;
  39. char zw[1024];
  40. string zwtime, zwvalue, name;
  41. bool _done = false;
  42. UpdatePreValueINI = false; // Konvertierung ins neue Format
  43. pFile = fopen(FilePreValue.c_str(), "r");
  44. if (pFile == NULL)
  45. return false;
  46. fgets(zw, 1024, pFile);
  47. printf("Read Zeile Prevalue.ini: %s", zw);
  48. zwtime = trim(std::string(zw));
  49. if (zwtime.length() == 0)
  50. return false;
  51. zerlegt = HelperZerlegeZeile(zwtime, "\t");
  52. if (zerlegt.size() > 1) // neues Format
  53. {
  54. while ((zerlegt.size() > 1) && !_done)
  55. {
  56. name = trim(zerlegt[0]);
  57. zwtime = trim(zerlegt[1]);
  58. zwvalue = trim(zerlegt[2]);
  59. for (int j = 0; j < NUMBERS.size(); ++j)
  60. {
  61. if (NUMBERS[j]->name == name)
  62. {
  63. NUMBERS[j]->PreValue = stof(zwvalue.c_str());
  64. time_t tStart;
  65. int yy, month, dd, hh, mm, ss;
  66. struct tm whenStart;
  67. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  68. whenStart.tm_year = yy - 1900;
  69. whenStart.tm_mon = month - 1;
  70. whenStart.tm_mday = dd;
  71. whenStart.tm_hour = hh;
  72. whenStart.tm_min = mm;
  73. whenStart.tm_sec = ss;
  74. whenStart.tm_isdst = -1;
  75. NUMBERS[j]->lastvalue = mktime(&whenStart);
  76. time(&tStart);
  77. localtime(&tStart);
  78. double difference = difftime(tStart, NUMBERS[j]->lastvalue);
  79. difference /= 60;
  80. if (difference > PreValueAgeStartup)
  81. {
  82. NUMBERS[j]->PreValueOkay = false;
  83. }
  84. else
  85. {
  86. NUMBERS[j]->PreValueOkay = true;
  87. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  88. NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->Value);
  89. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  90. if (NUMBERS[j]->digit_roi || NUMBERS[j]->analog_roi)
  91. {
  92. NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  93. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  94. }
  95. }
  96. }
  97. }
  98. if (!fgets(zw, 1024, pFile))
  99. _done = true;
  100. else
  101. {
  102. printf("Read Zeile Prevalue.ini: %s", zw);
  103. zerlegt = HelperZerlegeZeile(trim(std::string(zw)), "\t");
  104. if (zerlegt.size() > 1)
  105. {
  106. name = trim(zerlegt[0]);
  107. zwtime = trim(zerlegt[1]);
  108. zwvalue = trim(zerlegt[2]);
  109. }
  110. }
  111. }
  112. fclose(pFile);
  113. }
  114. else // altes Format
  115. {
  116. fgets(zw, 1024, pFile);
  117. fclose(pFile);
  118. printf("%s", zw);
  119. zwvalue = trim(std::string(zw));
  120. NUMBERS[0]->PreValue = stof(zwvalue.c_str());
  121. time_t tStart;
  122. int yy, month, dd, hh, mm, ss;
  123. struct tm whenStart;
  124. sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
  125. whenStart.tm_year = yy - 1900;
  126. whenStart.tm_mon = month - 1;
  127. whenStart.tm_mday = dd;
  128. whenStart.tm_hour = hh;
  129. whenStart.tm_min = mm;
  130. whenStart.tm_sec = ss;
  131. whenStart.tm_isdst = -1;
  132. printf("TIME: %d, %d, %d, %d, %d, %d\n", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec);
  133. NUMBERS[0]->lastvalue = mktime(&whenStart);
  134. time(&tStart);
  135. localtime(&tStart);
  136. double difference = difftime(tStart, NUMBERS[0]->lastvalue);
  137. difference /= 60;
  138. if (difference > PreValueAgeStartup)
  139. return false;
  140. NUMBERS[0]->Value = NUMBERS[0]->PreValue;
  141. NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
  142. NUMBERS[0]->ReturnValueNoError = NUMBERS[0]->ReturnValue;
  143. if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
  144. {
  145. NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->AnzahlAnalog - NUMBERS[0]->DecimalShift);
  146. NUMBERS[0]->ReturnValueNoError = NUMBERS[0]->ReturnValue;
  147. }
  148. UpdatePreValueINI = true; // Konvertierung ins neue Format
  149. SavePreValue();
  150. }
  151. return true;
  152. }
  153. void ClassFlowPostProcessing::SavePreValue()
  154. {
  155. FILE* pFile;
  156. string _zw;
  157. if (!UpdatePreValueINI) // PreValues unverändert --> File muss nicht neu geschrieben werden
  158. return;
  159. pFile = fopen(FilePreValue.c_str(), "w");
  160. for (int j = 0; j < NUMBERS.size(); ++j)
  161. {
  162. char buffer[80];
  163. struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue);
  164. strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
  165. NUMBERS[j]->timeStamp = std::string(buffer);
  166. _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + to_string(NUMBERS[j]->PreValue) + "\n";
  167. printf("Write PreValue Zeile: %s\n", _zw.c_str());
  168. fputs(_zw.c_str(), pFile);
  169. }
  170. UpdatePreValueINI = false;
  171. fclose(pFile);
  172. }
  173. ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
  174. {
  175. // FlowRateAct = 0;
  176. PreValueUse = false;
  177. PreValueAgeStartup = 30;
  178. ErrorMessage = false;
  179. ListFlowControll = NULL;
  180. // PreValueOkay = false;
  181. // DecimalShift = 0;
  182. // ErrorMessageText = "";
  183. // timeStamp = "";
  184. FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
  185. ListFlowControll = lfc;
  186. flowMakeImage = NULL;
  187. UpdatePreValueINI = false;
  188. for (int i = 0; i < ListFlowControll->size(); ++i)
  189. {
  190. if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
  191. {
  192. flowMakeImage = (ClassFlowMakeImage*) (*ListFlowControll)[i];
  193. }
  194. }
  195. }
  196. void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value)
  197. {
  198. string _digit, _decpos;
  199. int _pospunkt = _decsep.find_first_of(".");
  200. // printf("Name: %s, Pospunkt: %d\n", _name.c_str(), _pospunkt);
  201. if (_pospunkt > -1)
  202. {
  203. _digit = _decsep.substr(_pospunkt+1, _decsep.length() - _pospunkt - 1);
  204. }
  205. else
  206. {
  207. _digit = "default";
  208. }
  209. for (int j = 0; j < NUMBERS.size(); ++j)
  210. {
  211. if (_digit == "default") // erstmal auf default setzen (falls sonst nichts gesetzt)
  212. NUMBERS[j]->DecimalShift = stoi(_value);
  213. if (NUMBERS[j]->name == _digit)
  214. NUMBERS[j]->DecimalShift = stoi(_value);
  215. }
  216. }
  217. bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
  218. {
  219. std::vector<string> zerlegt;
  220. int _n;
  221. aktparamgraph = trim(aktparamgraph);
  222. if (aktparamgraph.size() == 0)
  223. if (!this->GetNextParagraph(pfile, aktparamgraph))
  224. return false;
  225. if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph passt nich zu MakeImage
  226. return false;
  227. InitNUMBERS();
  228. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  229. {
  230. zerlegt = this->ZerlegeZeile(aktparamgraph);
  231. if ((toUpper(zerlegt[0].substr(0, 12)) == "DECIMALSHIFT") && (zerlegt.size() > 1))
  232. {
  233. handleDecimalSeparator(zerlegt[0], zerlegt[1]);
  234. }
  235. if ((toUpper(zerlegt[0]) == "PREVALUEUSE") && (zerlegt.size() > 1))
  236. {
  237. if (toUpper(zerlegt[1]) == "TRUE")
  238. {
  239. PreValueUse = true;
  240. }
  241. }
  242. if ((toUpper(zerlegt[0]) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1))
  243. {
  244. if (toUpper(zerlegt[1]) == "TRUE")
  245. for (_n = 0; _n < NUMBERS.size(); ++_n)
  246. NUMBERS[_n]->checkDigitIncreaseConsistency = true;
  247. }
  248. if ((toUpper(zerlegt[0]) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1))
  249. {
  250. if (toUpper(zerlegt[1]) == "TRUE")
  251. for (_n = 0; _n < NUMBERS.size(); ++_n)
  252. NUMBERS[_n]->AllowNegativeRates = true;
  253. }
  254. if ((toUpper(zerlegt[0]) == "ERRORMESSAGE") && (zerlegt.size() > 1))
  255. {
  256. if (toUpper(zerlegt[1]) == "TRUE")
  257. ErrorMessage = true;
  258. }
  259. if ((toUpper(zerlegt[0]) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1))
  260. {
  261. PreValueAgeStartup = std::stoi(zerlegt[1]);
  262. }
  263. if ((toUpper(zerlegt[0]) == "MAXRATEVALUE") && (zerlegt.size() > 1))
  264. {
  265. for (_n = 0; _n < NUMBERS.size(); ++_n)
  266. {
  267. NUMBERS[_n]->useMaxRateValue = true;
  268. NUMBERS[_n]->MaxRateValue = std::stof(zerlegt[1]);
  269. }
  270. }
  271. }
  272. if (PreValueUse) {
  273. LoadPreValue();
  274. }
  275. return true;
  276. }
  277. void ClassFlowPostProcessing::InitNUMBERS()
  278. {
  279. // ClassFlowDigit* _cdigit = NULL;
  280. // ClassFlowAnalog* _canalog = NULL;
  281. int anzDIGIT = 0;
  282. int anzANALOG = 0;
  283. std::vector<std::string> name_numbers;
  284. flowAnalog = NULL;
  285. flowDigit = NULL;
  286. for (int i = 0; i < ListFlowControll->size(); ++i)
  287. {
  288. if (((*ListFlowControll)[i])->name().compare("ClassFlowDigit") == 0)
  289. {
  290. flowDigit = (ClassFlowDigit*) (*ListFlowControll)[i];
  291. anzDIGIT = flowDigit->getAnzahlDIGIT();
  292. }
  293. if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
  294. {
  295. flowAnalog = (ClassFlowAnalog*)(*ListFlowControll)[i];
  296. anzANALOG = flowAnalog->getAnzahlANALOG();
  297. }
  298. }
  299. flowDigit->UpdateNameNumbers(&name_numbers);
  300. flowAnalog->UpdateNameNumbers(&name_numbers);
  301. printf("Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d\n", name_numbers.size(), anzDIGIT, anzANALOG);
  302. for (int _num = 0; _num < name_numbers.size(); ++_num)
  303. {
  304. NumberPost *_number = new NumberPost;
  305. _number->name = name_numbers[_num];
  306. _number->digit_roi = NULL;
  307. if (flowDigit)
  308. _number->digit_roi = flowDigit->FindDIGIT(name_numbers[_num]);
  309. if (_number->digit_roi)
  310. _number->AnzahlDigital = _number->digit_roi->ROI.size();
  311. else
  312. _number->AnzahlDigital = 0;
  313. _number->analog_roi = NULL;
  314. if (flowAnalog)
  315. _number->analog_roi = flowAnalog->FindANALOG(name_numbers[_num]);
  316. if (_number->analog_roi)
  317. _number->AnzahlAnalog = _number->analog_roi->ROI.size();
  318. else
  319. _number->AnzahlAnalog = 0;
  320. _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
  321. _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
  322. _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
  323. _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
  324. _number->PreValueOkay = false;
  325. _number->AllowNegativeRates = false;
  326. _number->MaxRateValue = 0.1;
  327. _number->useMaxRateValue = false;
  328. _number->checkDigitIncreaseConsistency = false;
  329. _number->PreValueOkay = false;
  330. _number->useMaxRateValue = false;
  331. _number->FlowRateAct = 0; // m3 / min
  332. _number->PreValue = 0; // letzter Wert, der gut ausgelesen wurde
  333. _number->Value = 0; // letzer ausgelesener Wert, inkl. Korrekturen
  334. _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
  335. _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
  336. _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
  337. _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
  338. NUMBERS.push_back(_number);
  339. }
  340. for (int i = 0; i < NUMBERS.size(); ++i)
  341. printf("Number %s, Anz DIG: %d, Anz ANA %d\n", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog);
  342. }
  343. string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
  344. if (_decShift == 0){
  345. return in;
  346. }
  347. int _pos_dec_org, _pos_dec_neu;
  348. _pos_dec_org = findDelimiterPos(in, ".");
  349. if (_pos_dec_org == std::string::npos) {
  350. _pos_dec_org = in.length();
  351. }
  352. else
  353. {
  354. in = in.erase(_pos_dec_org, 1);
  355. }
  356. _pos_dec_neu = _pos_dec_org + _decShift;
  357. if (_pos_dec_neu <= 0) { // Komma ist vor der ersten Ziffer
  358. for (int i = 0; i > _pos_dec_neu; --i){
  359. in = in.insert(0, "0");
  360. }
  361. in = "0." + in;
  362. return in;
  363. }
  364. if (_pos_dec_neu > in.length()){ // Komma soll hinter String (123 --> 1230)
  365. for (int i = in.length(); i < _pos_dec_neu; ++i){
  366. in = in.insert(in.length(), "0");
  367. }
  368. return in;
  369. }
  370. string zw;
  371. zw = in.substr(0, _pos_dec_neu);
  372. zw = zw + ".";
  373. zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
  374. return zw;
  375. }
  376. bool ClassFlowPostProcessing::doFlow(string zwtime)
  377. {
  378. string result = "";
  379. string digit = "";
  380. string analog = "";
  381. string zwvalue;
  382. string zw;
  383. time_t imagetime = 0;
  384. string rohwert;
  385. // ErrorMessageText = "";
  386. imagetime = flowMakeImage->getTimeImageTaken();
  387. if (imagetime == 0)
  388. time(&imagetime);
  389. struct tm* timeinfo;
  390. timeinfo = localtime(&imagetime);
  391. char strftime_buf[64];
  392. strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo);
  393. zwtime = std::string(strftime_buf);
  394. printf("Anzahl NUMBERS: %d\n", NUMBERS.size());
  395. for (int j = 0; j < NUMBERS.size(); ++j)
  396. {
  397. NUMBERS[j]->ReturnRawValue = "";
  398. NUMBERS[j]->ErrorMessageText = "";
  399. if (NUMBERS[j]->digit_roi)
  400. NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j);
  401. if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
  402. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + ".";
  403. if (NUMBERS[j]->analog_roi)
  404. NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + flowAnalog->getReadout(j);
  405. NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
  406. rohwert = NUMBERS[j]->ReturnRawValue;
  407. if (!PreValueUse || !NUMBERS[j]->PreValueOkay)
  408. {
  409. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
  410. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnRawValue;
  411. if ((findDelimiterPos(NUMBERS[j]->ReturnValue, "N") == std::string::npos) && (NUMBERS[j]->ReturnValue.length() > 0))
  412. {
  413. while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
  414. {
  415. NUMBERS[j]->ReturnValue.erase(0, 1);
  416. }
  417. NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue);
  418. NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
  419. NUMBERS[j]->PreValueOkay = true;
  420. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  421. NUMBERS[j]->lastvalue = flowMakeImage->getTimeImageTaken();
  422. zwtime = ConvertTimeToString(NUMBERS[j]->lastvalue, PREVALUE_TIME_FORMAT_OUTPUT);
  423. UpdatePreValueINI = true;
  424. SavePreValue();
  425. }
  426. }
  427. else
  428. {
  429. zw = ErsetzteN(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->PreValue);
  430. NUMBERS[j]->Value = std::stof(zw);
  431. if (NUMBERS[j]->checkDigitIncreaseConsistency)
  432. {
  433. NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
  434. }
  435. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  436. if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue))
  437. {
  438. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + std::to_string(NUMBERS[j]->Value) + " ";
  439. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  440. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  441. }
  442. if (NUMBERS[j]->useMaxRateValue && (abs(NUMBERS[j]->Value - NUMBERS[j]->PreValue) > NUMBERS[j]->MaxRateValue))
  443. {
  444. NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + zwvalue + " - Pre: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift) + " ";
  445. NUMBERS[j]->Value = NUMBERS[j]->PreValue;
  446. zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
  447. }
  448. NUMBERS[j]->ReturnValueNoError = zwvalue;
  449. NUMBERS[j]->ReturnValue = zwvalue;
  450. if (NUMBERS[j]->ErrorMessage && (NUMBERS[j]->ErrorMessageText.length() > 0))
  451. NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnValue + "\t" + NUMBERS[j]->ErrorMessageText;
  452. double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden
  453. difference /= 60; // in Minuten
  454. NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
  455. NUMBERS[j]->lastvalue = imagetime;
  456. if (NUMBERS[j]->ErrorMessageText.length() == 0)
  457. {
  458. NUMBERS[j]->PreValue = NUMBERS[j]->Value;
  459. NUMBERS[j]->ErrorMessageText = "no error";
  460. UpdatePreValueINI = true;
  461. }
  462. }
  463. }
  464. SavePreValue();
  465. return true;
  466. }
  467. string ClassFlowPostProcessing::getReadout(int _number)
  468. {
  469. return NUMBERS[_number]->ReturnValue;
  470. }
  471. string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
  472. {
  473. if (_rawValue)
  474. return NUMBERS[_number]->ReturnRawValue;
  475. if (_noerror)
  476. return NUMBERS[_number]->ReturnValueNoError;
  477. return NUMBERS[_number]->ReturnValue;
  478. }
  479. string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
  480. std::stringstream stream;
  481. int _zw = _in;
  482. // printf("AnzNachkomma: %d\n", _anzNachkomma);
  483. if (_anzNachkomma < 0) {
  484. _anzNachkomma = 0;
  485. }
  486. if (_anzNachkomma > 0)
  487. {
  488. stream << std::fixed << std::setprecision(_anzNachkomma) << _in;
  489. return stream.str();
  490. }
  491. else
  492. {
  493. stream << _zw;
  494. }
  495. return stream.str();
  496. }
  497. string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
  498. {
  499. int posN, posPunkt;
  500. int pot, ziffer;
  501. float zw;
  502. posN = findDelimiterPos(input, "N");
  503. posPunkt = findDelimiterPos(input, ".");
  504. if (posPunkt == std::string::npos){
  505. posPunkt = input.length();
  506. }
  507. while (posN != std::string::npos)
  508. {
  509. if (posN < posPunkt) {
  510. pot = posPunkt - posN - 1;
  511. }
  512. else {
  513. pot = posPunkt - posN;
  514. }
  515. zw =_prevalue / pow(10, pot);
  516. ziffer = ((int) zw) % 10;
  517. input[posN] = ziffer + 48;
  518. posN = findDelimiterPos(input, "N");
  519. }
  520. return input;
  521. }
  522. float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue){
  523. int aktdigit, olddigit;
  524. int aktdigit_before, olddigit_before;
  525. int pot, pot_max;
  526. float zw;
  527. bool no_nulldurchgang = false;
  528. pot = _decilamshift;
  529. if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewertet werden
  530. {
  531. pot++;
  532. }
  533. pot_max = ((int) log10(input)) + 1;
  534. while (pot <= pot_max)
  535. {
  536. zw = input / pow(10, pot-1);
  537. aktdigit_before = ((int) zw) % 10;
  538. zw = _preValue / pow(10, pot-1);
  539. olddigit_before = ((int) zw) % 10;
  540. zw = input / pow(10, pot);
  541. aktdigit = ((int) zw) % 10;
  542. zw = _preValue / pow(10, pot);
  543. olddigit = ((int) zw) % 10;
  544. no_nulldurchgang = (olddigit_before <= aktdigit_before);
  545. if (no_nulldurchgang)
  546. {
  547. if (aktdigit != olddigit)
  548. {
  549. input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // Neue Digit wird durch alte Digit ersetzt;
  550. }
  551. }
  552. else
  553. {
  554. if (aktdigit == olddigit) // trotz Nulldurchgang wurde Stelle nicht hochgezählt --> addiere 1
  555. {
  556. input = input + ((float) (1)) * pow(10, pot); // addiere 1 an der Stelle
  557. }
  558. }
  559. pot++;
  560. }
  561. return input;
  562. }
  563. string ClassFlowPostProcessing::getReadoutRate(int _number)
  564. {
  565. return std::to_string(NUMBERS[_number]->FlowRateAct);
  566. }
  567. string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
  568. {
  569. return NUMBERS[_number]->timeStamp;
  570. }
  571. string ClassFlowPostProcessing::getReadoutError(int _number)
  572. {
  573. return NUMBERS[_number]->ErrorMessageText;
  574. }