ClassFlowControll.cpp 20 KB

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