ClassFlowControll.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. #include "ClassFlowControll.h"
  2. #include "connect_wlan.h"
  3. #include "read_wlanini.h"
  4. #include "freertos/task.h"
  5. #include <sys/stat.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #include <dirent.h>
  10. #ifdef __cplusplus
  11. }
  12. #endif
  13. #include "ClassLogFile.h"
  14. #include "time_sntp.h"
  15. #include "Helper.h"
  16. #include "server_ota.h"
  17. #ifdef ENABLE_MQTT
  18. #include "interface_mqtt.h"
  19. #include "server_mqtt.h"
  20. #endif //ENABLE_MQTT
  21. //#include "CImg.h"
  22. #include "server_help.h"
  23. //#define DEBUG_DETAIL_ON
  24. static const char* TAG = "CTRL";
  25. std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
  26. std::string _classname = "";
  27. std::string result = "";
  28. ESP_LOGD(TAG, "Step %s start", _stepname.c_str());
  29. if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){
  30. _classname = "ClassFlowMakeImage";
  31. }
  32. if ((_stepname.compare("[Alignment]") == 0) || (_stepname.compare(";[Alignment]") == 0)){
  33. _classname = "ClassFlowAlignment";
  34. }
  35. if ((_stepname.compare(0, 7, "[Digits") == 0) || (_stepname.compare(0, 8, ";[Digits") == 0)) {
  36. _classname = "ClassFlowCNNGeneral";
  37. }
  38. if ((_stepname.compare("[Analog]") == 0) || (_stepname.compare(";[Analog]") == 0)){
  39. _classname = "ClassFlowCNNGeneral";
  40. }
  41. #ifdef ENABLE_MQTT
  42. if ((_stepname.compare("[MQTT]") == 0) || (_stepname.compare(";[MQTT]") == 0)){
  43. _classname = "ClassFlowMQTT";
  44. }
  45. #endif //ENABLE_MQTT
  46. if ((_stepname.compare("[InfluxDB]") == 0) || (_stepname.compare(";[InfluxDB]") == 0)){
  47. _classname = "ClassFlowInfluxDB";
  48. }
  49. for (int i = 0; i < FlowControll.size(); ++i)
  50. if (FlowControll[i]->name().compare(_classname) == 0){
  51. if (!(FlowControll[i]->name().compare("ClassFlowMakeImage") == 0)) // falls es ein MakeImage ist, braucht das Bild nicht extra aufgenommen zu werden, dass passiert bei html-Abfrage automatisch
  52. FlowControll[i]->doFlow("");
  53. result = FlowControll[i]->getHTMLSingleStep(_host);
  54. }
  55. ESP_LOGD(TAG, "Step %s end", _stepname.c_str());
  56. return result;
  57. }
  58. std::string ClassFlowControll::TranslateAktstatus(std::string _input)
  59. {
  60. if (_input.compare("ClassFlowMakeImage") == 0)
  61. return ("Take Image");
  62. if (_input.compare("ClassFlowAlignment") == 0)
  63. return ("Aligning");
  64. if (_input.compare("ClassFlowCNNGeneral") == 0)
  65. return ("Digitalization of ROIs");
  66. #ifdef ENABLE_MQTT
  67. if (_input.compare("ClassFlowMQTT") == 0)
  68. return ("Sending MQTT");
  69. #endif //ENABLE_MQTT
  70. if (_input.compare("ClassFlowInfluxDB") == 0)
  71. return ("Sending InfluxDB");
  72. if (_input.compare("ClassFlowPostProcessing") == 0)
  73. return ("Post-Processing");
  74. if (_input.compare("ClassFlowWriteList") == 0)
  75. return ("Writing List");
  76. return "Unkown Status";
  77. }
  78. std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
  79. {
  80. if (flowdigit)
  81. {
  82. ESP_LOGD(TAG, "ClassFlowControll::GetAllDigital - flowdigit != NULL");
  83. return flowdigit->GetHTMLInfo();
  84. }
  85. std::vector<HTMLInfo*> empty;
  86. return empty;
  87. }
  88. std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog()
  89. {
  90. if (flowanalog)
  91. return flowanalog->GetHTMLInfo();
  92. std::vector<HTMLInfo*> empty;
  93. return empty;
  94. }
  95. t_CNNType ClassFlowControll::GetTypeDigital()
  96. {
  97. if (flowdigit)
  98. return flowdigit->getCNNType();
  99. return t_CNNType::None;
  100. }
  101. t_CNNType ClassFlowControll::GetTypeAnalog()
  102. {
  103. if (flowanalog)
  104. return flowanalog->getCNNType();
  105. return t_CNNType::None;
  106. }
  107. #ifdef ENABLE_MQTT
  108. string ClassFlowControll::GetMQTTMainTopic()
  109. {
  110. for (int i = 0; i < FlowControll.size(); ++i)
  111. if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0)
  112. return ((ClassFlowMQTT*) (FlowControll[i]))->GetMQTTMainTopic();
  113. return "";
  114. }
  115. bool ClassFlowControll::StartMQTTService() {
  116. /* Start the MQTT service */
  117. for (int i = 0; i < FlowControll.size(); ++i) {
  118. if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0) {
  119. return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoIntervall);
  120. }
  121. }
  122. return false;
  123. }
  124. #endif //ENABLE_MQTT
  125. void ClassFlowControll::SetInitialParameter(void)
  126. {
  127. AutoStart = false;
  128. SetupModeActive = false;
  129. AutoIntervall = 10; // Minutes
  130. flowdigit = NULL;
  131. flowanalog = NULL;
  132. flowpostprocessing = NULL;
  133. disabled = false;
  134. aktRunNr = 0;
  135. aktstatus = "Booting ...";
  136. }
  137. bool ClassFlowControll::isAutoStart(long &_intervall)
  138. {
  139. _intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms
  140. return AutoStart;
  141. }
  142. ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
  143. {
  144. ClassFlow* cfc = NULL;
  145. _type = trim(_type);
  146. if (toUpper(_type).compare("[MAKEIMAGE]") == 0)
  147. {
  148. cfc = new ClassFlowMakeImage(&FlowControll);
  149. flowmakeimage = (ClassFlowMakeImage*) cfc;
  150. }
  151. if (toUpper(_type).compare("[ALIGNMENT]") == 0)
  152. {
  153. cfc = new ClassFlowAlignment(&FlowControll);
  154. flowalignment = (ClassFlowAlignment*) cfc;
  155. }
  156. if (toUpper(_type).compare("[ANALOG]") == 0)
  157. {
  158. cfc = new ClassFlowCNNGeneral(flowalignment);
  159. flowanalog = (ClassFlowCNNGeneral*) cfc;
  160. }
  161. if (toUpper(_type).compare(0, 7, "[DIGITS") == 0)
  162. {
  163. cfc = new ClassFlowCNNGeneral(flowalignment);
  164. flowdigit = (ClassFlowCNNGeneral*) cfc;
  165. }
  166. #ifdef ENABLE_MQTT
  167. if (toUpper(_type).compare("[MQTT]") == 0)
  168. cfc = new ClassFlowMQTT(&FlowControll);
  169. #endif //ENABLE_MQTT
  170. if (toUpper(_type).compare("[INFLUXDB]") == 0)
  171. cfc = new ClassFlowInfluxDB(&FlowControll);
  172. if (toUpper(_type).compare("[WRITELIST]") == 0)
  173. cfc = new ClassFlowWriteList(&FlowControll);
  174. if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
  175. {
  176. cfc = new ClassFlowPostProcessing(&FlowControll, flowanalog, flowdigit);
  177. flowpostprocessing = (ClassFlowPostProcessing*) cfc;
  178. }
  179. if (cfc) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
  180. FlowControll.push_back(cfc);
  181. if (toUpper(_type).compare("[AUTOTIMER]") == 0)
  182. cfc = this;
  183. if (toUpper(_type).compare("[DATALOGGING]") == 0)
  184. cfc = this;
  185. if (toUpper(_type).compare("[DEBUG]") == 0)
  186. cfc = this;
  187. if (toUpper(_type).compare("[SYSTEM]") == 0)
  188. cfc = this;
  189. return cfc;
  190. }
  191. void ClassFlowControll::InitFlow(std::string config)
  192. {
  193. string line;
  194. flowpostprocessing = NULL;
  195. ClassFlow* cfc;
  196. FILE* pFile;
  197. config = FormatFileName(config);
  198. pFile = OpenFileAndWait(config.c_str(), "r");
  199. line = "";
  200. char zw[1024];
  201. if (pFile != NULL)
  202. {
  203. fgets(zw, 1024, pFile);
  204. ESP_LOGD(TAG, "%s", zw);
  205. line = std::string(zw);
  206. }
  207. while ((line.size() > 0) && !(feof(pFile)))
  208. {
  209. cfc = CreateClassFlow(line);
  210. if (cfc)
  211. {
  212. ESP_LOGD(TAG, "Start ReadParameter (%s)", line.c_str());
  213. cfc->ReadParameter(pFile, line);
  214. }
  215. else
  216. {
  217. line = "";
  218. if (fgets(zw, 1024, pFile) && !feof(pFile))
  219. {
  220. ESP_LOGD(TAG, "Read: %s", zw);
  221. line = std::string(zw);
  222. }
  223. }
  224. }
  225. fclose(pFile);
  226. }
  227. std::string* ClassFlowControll::getActStatus(){
  228. return &aktstatus;
  229. }
  230. void ClassFlowControll::doFlowMakeImageOnly(string time){
  231. std::string zw_time;
  232. for (int i = 0; i < FlowControll.size(); ++i)
  233. {
  234. if (FlowControll[i]->name() == "ClassFlowMakeImage") {
  235. // zw_time = gettimestring("%Y%m%d-%H%M%S");
  236. zw_time = gettimestring("%H:%M:%S");
  237. std::string flowStatus = TranslateAktstatus(FlowControll[i]->name());
  238. aktstatus = flowStatus + " (" + zw_time + ")";
  239. #ifdef ENABLE_MQTT
  240. MQTTPublish(mqttServer_getMainTopic() + "/" + "status", flowStatus, false);
  241. #endif //ENABLE_MQTT
  242. FlowControll[i]->doFlow(time);
  243. }
  244. }
  245. }
  246. bool ClassFlowControll::doFlow(string time)
  247. {
  248. // CleanTempFolder(); // dazu muss man noch eine Rolling einführen
  249. bool result = true;
  250. std::string zw_time;
  251. int repeat = 0;
  252. #ifdef DEBUG_DETAIL_ON
  253. LogFile.WriteHeapInfo("ClassFlowControll::doFlow - Start");
  254. #endif
  255. /* Check if we have a valid date/time and if not restart the NTP client */
  256. if (! getTimeIsSet()) {
  257. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time not set, restarting NTP Client!");
  258. restartNtpClient();
  259. }
  260. for (int i = 0; i < FlowControll.size(); ++i)
  261. {
  262. zw_time = gettimestring("%H:%M:%S");
  263. std::string flowStatus = TranslateAktstatus(FlowControll[i]->name());
  264. aktstatus = flowStatus + " (" + zw_time + ")";
  265. #ifdef ENABLE_MQTT
  266. MQTTPublish(mqttServer_getMainTopic() + "/" + "status", flowStatus, false);
  267. #endif //ENABLE_MQTT
  268. string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
  269. #ifdef DEBUG_DETAIL_ON
  270. LogFile.WriteHeapInfo(zw);
  271. #endif
  272. if (!FlowControll[i]->doFlow(time)){
  273. repeat++;
  274. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt");
  275. if (i) i -= 1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen)
  276. result = false;
  277. if (repeat > 5) {
  278. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Wiederholung 5x nicht erfolgreich --> reboot");
  279. doReboot();
  280. // Schritt wurde 5x wiederholt --> reboot
  281. }
  282. }
  283. else
  284. {
  285. result = true;
  286. }
  287. #ifdef DEBUG_DETAIL_ON
  288. LogFile.WriteHeapInfo("ClassFlowControll::doFlow");
  289. #endif
  290. }
  291. zw_time = gettimestring("%H:%M:%S");
  292. std::string flowStatus = "Flow finished";
  293. aktstatus = flowStatus + " (" + zw_time + ")";
  294. #ifdef ENABLE_MQTT
  295. MQTTPublish(mqttServer_getMainTopic() + "/" + "status", flowStatus, false);
  296. #endif //ENABLE_MQTT
  297. return result;
  298. }
  299. string ClassFlowControll::getReadoutAll(int _type)
  300. {
  301. std::string out = "";
  302. if (flowpostprocessing)
  303. {
  304. std::vector<NumberPost*> *numbers = flowpostprocessing->GetNumbers();
  305. for (int i = 0; i < (*numbers).size(); ++i)
  306. {
  307. out = out + (*numbers)[i]->name + "\t";
  308. switch (_type) {
  309. case READOUT_TYPE_VALUE:
  310. out = out + (*numbers)[i]->ReturnValue;
  311. break;
  312. case READOUT_TYPE_PREVALUE:
  313. if (flowpostprocessing->PreValueUse)
  314. {
  315. if ((*numbers)[i]->PreValueOkay)
  316. out = out + (*numbers)[i]->ReturnPreValue;
  317. else
  318. out = out + "PreValue too old";
  319. }
  320. else
  321. out = out + "PreValue deactivated";
  322. break;
  323. case READOUT_TYPE_RAWVALUE:
  324. out = out + (*numbers)[i]->ReturnRawValue;
  325. break;
  326. case READOUT_TYPE_ERROR:
  327. out = out + (*numbers)[i]->ErrorMessageText;
  328. break;
  329. }
  330. if (i < (*numbers).size()-1)
  331. out = out + "\r\n";
  332. }
  333. // ESP_LOGD(TAG, "OUT: %s", out.c_str());
  334. }
  335. return out;
  336. }
  337. string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
  338. {
  339. if (flowpostprocessing)
  340. return flowpostprocessing->getReadoutParam(_rawvalue, _noerror);
  341. string zw = "";
  342. string result = "";
  343. for (int i = 0; i < FlowControll.size(); ++i)
  344. {
  345. zw = FlowControll[i]->getReadout();
  346. if (zw.length() > 0)
  347. {
  348. if (result.length() == 0)
  349. result = zw;
  350. else
  351. result = result + "\t" + zw;
  352. }
  353. }
  354. return result;
  355. }
  356. string ClassFlowControll::GetPrevalue(std::string _number)
  357. {
  358. if (flowpostprocessing)
  359. {
  360. return flowpostprocessing->GetPreValue(_number);
  361. }
  362. return std::string("");
  363. }
  364. std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbers, bool _extern)
  365. {
  366. float zw;
  367. char* p;
  368. _newvalue = trim(_newvalue);
  369. // ESP_LOGD(TAG, "Input UpdatePreValue: %s", _newvalue.c_str());
  370. if (_newvalue.compare("0.0") == 0)
  371. {
  372. zw = 0;
  373. }
  374. else
  375. {
  376. zw = strtof(_newvalue.c_str(), &p);
  377. if (zw == 0)
  378. return "- Error in String to Value Conversion!!! Must be of format value=123.456";
  379. }
  380. if (flowpostprocessing)
  381. {
  382. flowpostprocessing->SetPreValue(zw, _numbers, _extern);
  383. return _newvalue;
  384. }
  385. return std::string();
  386. }
  387. bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
  388. {
  389. std::vector<string> zerlegt;
  390. aktparamgraph = trim(aktparamgraph);
  391. if (aktparamgraph.size() == 0)
  392. if (!this->GetNextParagraph(pfile, aktparamgraph))
  393. return false;
  394. if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) &&
  395. (toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu MakeImage
  396. return false;
  397. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  398. {
  399. zerlegt = ZerlegeZeile(aktparamgraph, " =");
  400. if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
  401. {
  402. if (toUpper(zerlegt[1]) == "TRUE")
  403. {
  404. AutoStart = true;
  405. }
  406. }
  407. if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
  408. {
  409. AutoIntervall = std::stof(zerlegt[1]);
  410. }
  411. if ((toUpper(zerlegt[0]) == "DATALOGACTIVE") && (zerlegt.size() > 1))
  412. {
  413. if (toUpper(zerlegt[1]) == "TRUE")
  414. {
  415. LogFile.SetDataLogToSD(true);
  416. }
  417. else {
  418. LogFile.SetDataLogToSD(false);
  419. }
  420. }
  421. if ((toUpper(zerlegt[0]) == "DATALOGRETENTIONINDAYS") && (zerlegt.size() > 1))
  422. {
  423. LogFile.SetDataLogRetention(std::stoi(zerlegt[1]));
  424. }
  425. if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
  426. {
  427. /* matches esp_log_level_t */
  428. if ((toUpper(zerlegt[1]) == "TRUE") || (toUpper(zerlegt[1]) == "2"))
  429. {
  430. LogFile.setLogLevel(ESP_LOG_WARN);
  431. }
  432. else if ((toUpper(zerlegt[1]) == "FALSE") || (toUpper(zerlegt[1]) == "0") || (toUpper(zerlegt[1]) == "1"))
  433. {
  434. LogFile.setLogLevel(ESP_LOG_ERROR);
  435. }
  436. else if (toUpper(zerlegt[1]) == "3")
  437. {
  438. LogFile.setLogLevel(ESP_LOG_INFO);
  439. }
  440. else if (toUpper(zerlegt[1]) == "4")
  441. {
  442. LogFile.setLogLevel(ESP_LOG_DEBUG);
  443. }
  444. }
  445. if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1))
  446. {
  447. LogFile.SetLogFileRetention(std::stoi(zerlegt[1]));
  448. }
  449. if ((toUpper(zerlegt[0]) == "TIMEZONE") && (zerlegt.size() > 1))
  450. {
  451. string zw = "Set TimeZone: " + zerlegt[1];
  452. setTimeZone(zerlegt[1]);
  453. }
  454. if ((toUpper(zerlegt[0]) == "TIMESERVER") && (zerlegt.size() > 1))
  455. {
  456. string zw = "Set TimeZone: " + zerlegt[1];
  457. reset_servername(zerlegt[1]);
  458. }
  459. if ((toUpper(zerlegt[0]) == "HOSTNAME") && (zerlegt.size() > 1))
  460. {
  461. if (ChangeHostName("/sdcard/wlan.ini", zerlegt[1]))
  462. {
  463. // reboot notwendig damit die neue wlan.ini auch benutzt wird !!!
  464. fclose(pfile);
  465. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new HOSTNAME...");
  466. esp_restart();
  467. hard_restart();
  468. doReboot();
  469. }
  470. }
  471. if ((toUpper(zerlegt[0]) == "SETUPMODE") && (zerlegt.size() > 1))
  472. {
  473. if (toUpper(zerlegt[1]) == "TRUE")
  474. {
  475. SetupModeActive = true;
  476. }
  477. }
  478. }
  479. return true;
  480. }
  481. int ClassFlowControll::CleanTempFolder() {
  482. const char* folderPath = "/sdcard/img_tmp";
  483. ESP_LOGD(TAG, "Clean up temporary folder to avoid damage of sdcard sectors: %s", folderPath);
  484. DIR *dir = opendir(folderPath);
  485. if (!dir) {
  486. ESP_LOGE(TAG, "Failed to stat dir: %s", folderPath);
  487. return -1;
  488. }
  489. struct dirent *entry;
  490. int deleted = 0;
  491. while ((entry = readdir(dir)) != NULL) {
  492. std::string path = string(folderPath) + "/" + entry->d_name;
  493. if (entry->d_type == DT_REG) {
  494. if (unlink(path.c_str()) == 0) {
  495. deleted ++;
  496. } else {
  497. ESP_LOGE(TAG, "can't delete file: %s", path.c_str());
  498. }
  499. } else if (entry->d_type == DT_DIR) {
  500. deleted += removeFolder(path.c_str(), TAG);
  501. }
  502. }
  503. closedir(dir);
  504. ESP_LOGD(TAG, "%d files deleted", deleted);
  505. return 0;
  506. }
  507. esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
  508. {
  509. return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
  510. }
  511. esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
  512. {
  513. ESP_LOGD(TAG, "ClassFlowControll::GetJPGStream %s", _fn.c_str());
  514. CImageBasis *_send = NULL;
  515. esp_err_t result = ESP_FAIL;
  516. bool Dodelete = false;
  517. if (flowalignment == NULL)
  518. {
  519. ESP_LOGD(TAG, "Can't continue, flowalignment is NULL");
  520. return ESP_FAIL;
  521. }
  522. if (_fn == "alg.jpg")
  523. {
  524. _send = flowalignment->ImageBasis;
  525. }
  526. else
  527. {
  528. if (_fn == "alg_roi.jpg")
  529. {
  530. CImageBasis* _imgzw = new CImageBasis(flowalignment->ImageBasis);
  531. flowalignment->DrawRef(_imgzw);
  532. if (flowdigit) flowdigit->DrawROI(_imgzw);
  533. if (flowanalog) flowanalog->DrawROI(_imgzw);
  534. _send = _imgzw;
  535. Dodelete = true;
  536. }
  537. else
  538. {
  539. std::vector<HTMLInfo*> htmlinfo;
  540. htmlinfo = GetAllDigital();
  541. ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigital");
  542. for (int i = 0; i < htmlinfo.size(); ++i)
  543. {
  544. if (_fn == htmlinfo[i]->filename)
  545. {
  546. if (htmlinfo[i]->image)
  547. _send = htmlinfo[i]->image;
  548. }
  549. if (_fn == htmlinfo[i]->filename_org)
  550. {
  551. if (htmlinfo[i]->image_org)
  552. _send = htmlinfo[i]->image_org;
  553. }
  554. delete htmlinfo[i];
  555. }
  556. htmlinfo.clear();
  557. if (!_send)
  558. {
  559. htmlinfo = GetAllAnalog();
  560. for (int i = 0; i < htmlinfo.size(); ++i)
  561. {
  562. if (_fn == htmlinfo[i]->filename)
  563. {
  564. if (htmlinfo[i]->image)
  565. _send = htmlinfo[i]->image;
  566. }
  567. if (_fn == htmlinfo[i]->filename_org)
  568. {
  569. if (htmlinfo[i]->image_org)
  570. _send = htmlinfo[i]->image_org;
  571. }
  572. delete htmlinfo[i];
  573. }
  574. htmlinfo.clear();
  575. }
  576. }
  577. }
  578. if (_send)
  579. {
  580. ESP_LOGD(TAG, "Sending file: %s ...", _fn.c_str());
  581. set_content_type_from_file(req, _fn.c_str());
  582. result = _send->SendJPGtoHTTP(req);
  583. ESP_LOGD(TAG, "File sending complete");
  584. /* Respond with an empty chunk to signal HTTP response completion */
  585. httpd_resp_send_chunk(req, NULL, 0);
  586. }
  587. if (Dodelete)
  588. {
  589. delete _send;
  590. }
  591. return result;
  592. }
  593. string ClassFlowControll::getNumbersName()
  594. {
  595. return flowpostprocessing->getNumbersName();
  596. }
  597. string ClassFlowControll::getJSON()
  598. {
  599. return flowpostprocessing->GetJSON();
  600. }