ClassFlowPostProcessing.cpp 25 KB

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