ClassFlowControll.cpp 20 KB

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