ClassFlowControll.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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)) // falls es ein MakeImage ist, braucht das Bild nicht extra aufgenommen zu werden, dass passiert bei html-Abfrage automatisch
  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; // AutoIntervall: Minuten -> 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) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für 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 = OpenFileAndWait(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("%Y%m%d-%H%M%S");
  241. zw_time = gettimestring("%H:%M:%S");
  242. std::string flowStatus = TranslateAktstatus(FlowControll[i]->name());
  243. aktstatus = flowStatus + " (" + zw_time + ")";
  244. #ifdef ENABLE_MQTT
  245. MQTTPublish(mqttServer_getMainTopic() + "/" + "status", flowStatus, false);
  246. #endif //ENABLE_MQTT
  247. FlowControll[i]->doFlow(time);
  248. }
  249. }
  250. }
  251. bool ClassFlowControll::doFlow(string time)
  252. {
  253. // CleanTempFolder(); // dazu muss man noch eine Rolling einführen
  254. bool result = true;
  255. std::string zw_time;
  256. int repeat = 0;
  257. #ifdef DEBUG_DETAIL_ON
  258. LogFile.WriteHeapInfo("ClassFlowControll::doFlow - Start");
  259. #endif
  260. /* Check if we have a valid date/time and if not restart the NTP client */
  261. if (! getTimeIsSet()) {
  262. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time not set, restarting NTP Client!");
  263. restartNtpClient();
  264. }
  265. for (int i = 0; i < FlowControll.size(); ++i)
  266. {
  267. zw_time = gettimestring("%H:%M:%S");
  268. std::string flowStatus = TranslateAktstatus(FlowControll[i]->name());
  269. aktstatus = flowStatus + " (" + zw_time + ")";
  270. #ifdef ENABLE_MQTT
  271. MQTTPublish(mqttServer_getMainTopic() + "/" + "status", flowStatus, false);
  272. #endif //ENABLE_MQTT
  273. string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
  274. #ifdef DEBUG_DETAIL_ON
  275. LogFile.WriteHeapInfo(zw);
  276. #endif
  277. if (!FlowControll[i]->doFlow(time)){
  278. repeat++;
  279. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt");
  280. if (i) i -= 1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen)
  281. result = false;
  282. if (repeat > 5) {
  283. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Wiederholung 5x nicht erfolgreich --> reboot");
  284. doReboot();
  285. // Schritt wurde 5x wiederholt --> reboot
  286. }
  287. }
  288. else
  289. {
  290. result = true;
  291. }
  292. #ifdef DEBUG_DETAIL_ON
  293. LogFile.WriteHeapInfo("ClassFlowControll::doFlow");
  294. #endif
  295. }
  296. zw_time = gettimestring("%H:%M:%S");
  297. std::string flowStatus = "Flow finished";
  298. aktstatus = flowStatus + " (" + zw_time + ")";
  299. #ifdef ENABLE_MQTT
  300. MQTTPublish(mqttServer_getMainTopic() + "/" + "status", flowStatus, false);
  301. #endif //ENABLE_MQTT
  302. return result;
  303. }
  304. string ClassFlowControll::getReadoutAll(int _type)
  305. {
  306. std::string out = "";
  307. if (flowpostprocessing)
  308. {
  309. std::vector<NumberPost*> *numbers = flowpostprocessing->GetNumbers();
  310. for (int i = 0; i < (*numbers).size(); ++i)
  311. {
  312. out = out + (*numbers)[i]->name + "\t";
  313. switch (_type) {
  314. case READOUT_TYPE_VALUE:
  315. out = out + (*numbers)[i]->ReturnValue;
  316. break;
  317. case READOUT_TYPE_PREVALUE:
  318. if (flowpostprocessing->PreValueUse)
  319. {
  320. if ((*numbers)[i]->PreValueOkay)
  321. out = out + (*numbers)[i]->ReturnPreValue;
  322. else
  323. out = out + "PreValue too old";
  324. }
  325. else
  326. out = out + "PreValue deactivated";
  327. break;
  328. case READOUT_TYPE_RAWVALUE:
  329. out = out + (*numbers)[i]->ReturnRawValue;
  330. break;
  331. case READOUT_TYPE_ERROR:
  332. out = out + (*numbers)[i]->ErrorMessageText;
  333. break;
  334. }
  335. if (i < (*numbers).size()-1)
  336. out = out + "\r\n";
  337. }
  338. // ESP_LOGD(TAG, "OUT: %s", out.c_str());
  339. }
  340. return out;
  341. }
  342. string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
  343. {
  344. if (flowpostprocessing)
  345. return flowpostprocessing->getReadoutParam(_rawvalue, _noerror);
  346. string zw = "";
  347. string result = "";
  348. for (int i = 0; i < FlowControll.size(); ++i)
  349. {
  350. zw = FlowControll[i]->getReadout();
  351. if (zw.length() > 0)
  352. {
  353. if (result.length() == 0)
  354. result = zw;
  355. else
  356. result = result + "\t" + zw;
  357. }
  358. }
  359. return result;
  360. }
  361. string ClassFlowControll::GetPrevalue(std::string _number)
  362. {
  363. if (flowpostprocessing)
  364. {
  365. return flowpostprocessing->GetPreValue(_number);
  366. }
  367. return std::string("");
  368. }
  369. std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbers, bool _extern)
  370. {
  371. float zw;
  372. char* p;
  373. _newvalue = trim(_newvalue);
  374. // ESP_LOGD(TAG, "Input UpdatePreValue: %s", _newvalue.c_str());
  375. if (_newvalue.compare("0.0") == 0)
  376. {
  377. zw = 0;
  378. }
  379. else
  380. {
  381. zw = strtof(_newvalue.c_str(), &p);
  382. if (zw == 0)
  383. return "- Error in String to Value Conversion!!! Must be of format value=123.456";
  384. }
  385. if (flowpostprocessing)
  386. {
  387. flowpostprocessing->SetPreValue(zw, _numbers, _extern);
  388. return _newvalue;
  389. }
  390. return std::string();
  391. }
  392. bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
  393. {
  394. std::vector<string> zerlegt;
  395. aktparamgraph = trim(aktparamgraph);
  396. if (aktparamgraph.size() == 0)
  397. if (!this->GetNextParagraph(pfile, aktparamgraph))
  398. return false;
  399. if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) &&
  400. (toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu MakeImage
  401. return false;
  402. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  403. {
  404. zerlegt = ZerlegeZeile(aktparamgraph, " =");
  405. if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
  406. {
  407. if (toUpper(zerlegt[1]) == "TRUE")
  408. {
  409. AutoStart = true;
  410. }
  411. }
  412. if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
  413. {
  414. AutoIntervall = std::stof(zerlegt[1]);
  415. }
  416. if ((toUpper(zerlegt[0]) == "DATALOGACTIVE") && (zerlegt.size() > 1))
  417. {
  418. if (toUpper(zerlegt[1]) == "TRUE")
  419. {
  420. LogFile.SetDataLogToSD(true);
  421. }
  422. else {
  423. LogFile.SetDataLogToSD(false);
  424. }
  425. }
  426. if ((toUpper(zerlegt[0]) == "DATALOGRETENTIONINDAYS") && (zerlegt.size() > 1))
  427. {
  428. LogFile.SetDataLogRetention(std::stoi(zerlegt[1]));
  429. }
  430. if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
  431. {
  432. /* matches esp_log_level_t */
  433. if ((toUpper(zerlegt[1]) == "TRUE") || (toUpper(zerlegt[1]) == "2"))
  434. {
  435. LogFile.setLogLevel(ESP_LOG_WARN);
  436. }
  437. else if ((toUpper(zerlegt[1]) == "FALSE") || (toUpper(zerlegt[1]) == "0") || (toUpper(zerlegt[1]) == "1"))
  438. {
  439. LogFile.setLogLevel(ESP_LOG_ERROR);
  440. }
  441. else if (toUpper(zerlegt[1]) == "3")
  442. {
  443. LogFile.setLogLevel(ESP_LOG_INFO);
  444. }
  445. else if (toUpper(zerlegt[1]) == "4")
  446. {
  447. LogFile.setLogLevel(ESP_LOG_DEBUG);
  448. }
  449. }
  450. if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1))
  451. {
  452. LogFile.SetLogFileRetention(std::stoi(zerlegt[1]));
  453. }
  454. if ((toUpper(zerlegt[0]) == "TIMEZONE") && (zerlegt.size() > 1))
  455. {
  456. string zw = "Set TimeZone: " + zerlegt[1];
  457. setTimeZone(zerlegt[1]);
  458. }
  459. if ((toUpper(zerlegt[0]) == "TIMESERVER") && (zerlegt.size() > 1))
  460. {
  461. string zw = "Set TimeZone: " + zerlegt[1];
  462. reset_servername(zerlegt[1]);
  463. }
  464. if ((toUpper(zerlegt[0]) == "HOSTNAME") && (zerlegt.size() > 1))
  465. {
  466. if (ChangeHostName("/sdcard/wlan.ini", zerlegt[1]))
  467. {
  468. // reboot notwendig damit die neue wlan.ini auch benutzt wird !!!
  469. fclose(pfile);
  470. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new HOSTNAME...");
  471. esp_restart();
  472. hard_restart();
  473. doReboot();
  474. }
  475. }
  476. if ((toUpper(zerlegt[0]) == "SETUPMODE") && (zerlegt.size() > 1))
  477. {
  478. if (toUpper(zerlegt[1]) == "TRUE")
  479. {
  480. SetupModeActive = true;
  481. }
  482. }
  483. }
  484. return true;
  485. }
  486. int ClassFlowControll::CleanTempFolder() {
  487. const char* folderPath = "/sdcard/img_tmp";
  488. ESP_LOGD(TAG, "Clean up temporary folder to avoid damage of sdcard sectors: %s", folderPath);
  489. DIR *dir = opendir(folderPath);
  490. if (!dir) {
  491. ESP_LOGE(TAG, "Failed to stat dir: %s", folderPath);
  492. return -1;
  493. }
  494. struct dirent *entry;
  495. int deleted = 0;
  496. while ((entry = readdir(dir)) != NULL) {
  497. std::string path = string(folderPath) + "/" + entry->d_name;
  498. if (entry->d_type == DT_REG) {
  499. if (unlink(path.c_str()) == 0) {
  500. deleted ++;
  501. } else {
  502. ESP_LOGE(TAG, "can't delete file: %s", path.c_str());
  503. }
  504. } else if (entry->d_type == DT_DIR) {
  505. deleted += removeFolder(path.c_str(), TAG);
  506. }
  507. }
  508. closedir(dir);
  509. ESP_LOGD(TAG, "%d files deleted", deleted);
  510. return 0;
  511. }
  512. esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
  513. {
  514. return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
  515. }
  516. esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
  517. {
  518. ESP_LOGD(TAG, "ClassFlowControll::GetJPGStream %s", _fn.c_str());
  519. CImageBasis *_send = NULL;
  520. esp_err_t result = ESP_FAIL;
  521. bool Dodelete = false;
  522. if (flowalignment == NULL)
  523. {
  524. ESP_LOGD(TAG, "Can't continue, flowalignment is NULL");
  525. return ESP_FAIL;
  526. }
  527. if (_fn == "alg.jpg")
  528. {
  529. _send = flowalignment->ImageBasis;
  530. }
  531. else
  532. {
  533. if (_fn == "alg_roi.jpg")
  534. {
  535. CImageBasis* _imgzw = new CImageBasis(flowalignment->ImageBasis);
  536. flowalignment->DrawRef(_imgzw);
  537. if (flowdigit) flowdigit->DrawROI(_imgzw);
  538. if (flowanalog) flowanalog->DrawROI(_imgzw);
  539. _send = _imgzw;
  540. Dodelete = true;
  541. }
  542. else
  543. {
  544. std::vector<HTMLInfo*> htmlinfo;
  545. htmlinfo = GetAllDigital();
  546. ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigital");
  547. for (int i = 0; i < htmlinfo.size(); ++i)
  548. {
  549. if (_fn == htmlinfo[i]->filename)
  550. {
  551. if (htmlinfo[i]->image)
  552. _send = htmlinfo[i]->image;
  553. }
  554. if (_fn == htmlinfo[i]->filename_org)
  555. {
  556. if (htmlinfo[i]->image_org)
  557. _send = htmlinfo[i]->image_org;
  558. }
  559. delete htmlinfo[i];
  560. }
  561. htmlinfo.clear();
  562. if (!_send)
  563. {
  564. htmlinfo = GetAllAnalog();
  565. for (int i = 0; i < htmlinfo.size(); ++i)
  566. {
  567. if (_fn == htmlinfo[i]->filename)
  568. {
  569. if (htmlinfo[i]->image)
  570. _send = htmlinfo[i]->image;
  571. }
  572. if (_fn == htmlinfo[i]->filename_org)
  573. {
  574. if (htmlinfo[i]->image_org)
  575. _send = htmlinfo[i]->image_org;
  576. }
  577. delete htmlinfo[i];
  578. }
  579. htmlinfo.clear();
  580. }
  581. }
  582. }
  583. if (_send)
  584. {
  585. ESP_LOGD(TAG, "Sending file: %s ...", _fn.c_str());
  586. set_content_type_from_file(req, _fn.c_str());
  587. result = _send->SendJPGtoHTTP(req);
  588. ESP_LOGD(TAG, "File sending complete");
  589. /* Respond with an empty chunk to signal HTTP response completion */
  590. httpd_resp_send_chunk(req, NULL, 0);
  591. }
  592. if (Dodelete)
  593. {
  594. delete _send;
  595. }
  596. return result;
  597. }
  598. string ClassFlowControll::getNumbersName()
  599. {
  600. return flowpostprocessing->getNumbersName();
  601. }
  602. string ClassFlowControll::getJSON()
  603. {
  604. return flowpostprocessing->GetJSON();
  605. }