ClassFlowControll.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 = getCurrentTimeString("%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. //checkNtpStatus(0);
  264. for (int i = 0; i < FlowControll.size(); ++i)
  265. {
  266. zw_time = getCurrentTimeString("%H:%M:%S");
  267. std::string flowStatus = TranslateAktstatus(FlowControll[i]->name());
  268. aktstatus = flowStatus + " (" + zw_time + ")";
  269. //LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatus);
  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; // vPrevious step must be repeated (probably take pictures)
  281. result = false;
  282. if (repeat > 5) {
  283. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Wiederholung 5x nicht erfolgreich --> reboot");
  284. doReboot();
  285. //Step was repeated 5x --> 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 = getCurrentTimeString("%H:%M:%S");
  297. std::string flowStatus = "Flow finished";
  298. aktstatus = flowStatus + " (" + zw_time + ")";
  299. //LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatus);
  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> splitted;
  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. splitted = ZerlegeZeile(aktparamgraph, " =");
  406. if ((toUpper(splitted[0]) == "AUTOSTART") && (splitted.size() > 1))
  407. {
  408. if (toUpper(splitted[1]) == "TRUE")
  409. {
  410. AutoStart = true;
  411. }
  412. }
  413. if ((toUpper(splitted[0]) == "INTERVALL") && (splitted.size() > 1))
  414. {
  415. AutoIntervall = std::stof(splitted[1]);
  416. }
  417. if ((toUpper(splitted[0]) == "DATALOGACTIVE") && (splitted.size() > 1))
  418. {
  419. if (toUpper(splitted[1]) == "TRUE")
  420. {
  421. LogFile.SetDataLogToSD(true);
  422. }
  423. else {
  424. LogFile.SetDataLogToSD(false);
  425. }
  426. }
  427. if ((toUpper(splitted[0]) == "DATALOGRETENTIONINDAYS") && (splitted.size() > 1))
  428. {
  429. LogFile.SetDataLogRetention(std::stoi(splitted[1]));
  430. }
  431. if ((toUpper(splitted[0]) == "LOGFILE") && (splitted.size() > 1))
  432. {
  433. /* matches esp_log_level_t */
  434. if ((toUpper(splitted[1]) == "TRUE") || (toUpper(splitted[1]) == "2"))
  435. {
  436. LogFile.setLogLevel(ESP_LOG_WARN);
  437. }
  438. else if ((toUpper(splitted[1]) == "FALSE") || (toUpper(splitted[1]) == "0") || (toUpper(splitted[1]) == "1"))
  439. {
  440. LogFile.setLogLevel(ESP_LOG_ERROR);
  441. }
  442. else if (toUpper(splitted[1]) == "3")
  443. {
  444. LogFile.setLogLevel(ESP_LOG_INFO);
  445. }
  446. else if (toUpper(splitted[1]) == "4")
  447. {
  448. LogFile.setLogLevel(ESP_LOG_DEBUG);
  449. }
  450. }
  451. if ((toUpper(splitted[0]) == "LOGFILERETENTIONINDAYS") && (splitted.size() > 1))
  452. {
  453. LogFile.SetLogFileRetention(std::stoi(splitted[1]));
  454. }
  455. /* TimeServer and TimeZone got already read from the config, see setupTime () */
  456. if ((toUpper(splitted[0]) == "RSSITHREASHOLD") && (splitted.size() > 1))
  457. {
  458. if (ChangeRSSIThreashold("/sdcard/wlan.ini", atoi(splitted[1].c_str())))
  459. {
  460. // reboot necessary so that the new wlan.ini is also used !!!
  461. fclose(pfile);
  462. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new RSSITHREASHOLD ...");
  463. esp_restart();
  464. hard_restart();
  465. doReboot();
  466. }
  467. }
  468. if ((toUpper(splitted[0]) == "HOSTNAME") && (splitted.size() > 1))
  469. {
  470. if (ChangeHostName("/sdcard/wlan.ini", splitted[1]))
  471. {
  472. // reboot necessary so that the new wlan.ini is also used !!!
  473. fclose(pfile);
  474. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new HOSTNAME...");
  475. esp_restart();
  476. hard_restart();
  477. doReboot();
  478. }
  479. }
  480. if ((toUpper(splitted[0]) == "SETUPMODE") && (splitted.size() > 1))
  481. {
  482. if (toUpper(splitted[1]) == "TRUE")
  483. {
  484. SetupModeActive = true;
  485. }
  486. }
  487. }
  488. return true;
  489. }
  490. int ClassFlowControll::CleanTempFolder() {
  491. const char* folderPath = "/sdcard/img_tmp";
  492. ESP_LOGD(TAG, "Clean up temporary folder to avoid damage of sdcard sectors: %s", folderPath);
  493. DIR *dir = opendir(folderPath);
  494. if (!dir) {
  495. ESP_LOGE(TAG, "Failed to stat dir: %s", folderPath);
  496. return -1;
  497. }
  498. struct dirent *entry;
  499. int deleted = 0;
  500. while ((entry = readdir(dir)) != NULL) {
  501. std::string path = string(folderPath) + "/" + entry->d_name;
  502. if (entry->d_type == DT_REG) {
  503. if (unlink(path.c_str()) == 0) {
  504. deleted ++;
  505. } else {
  506. ESP_LOGE(TAG, "can't delete file: %s", path.c_str());
  507. }
  508. } else if (entry->d_type == DT_DIR) {
  509. deleted += removeFolder(path.c_str(), TAG);
  510. }
  511. }
  512. closedir(dir);
  513. ESP_LOGD(TAG, "%d files deleted", deleted);
  514. return 0;
  515. }
  516. esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
  517. {
  518. return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
  519. }
  520. esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
  521. {
  522. ESP_LOGD(TAG, "ClassFlowControll::GetJPGStream %s", _fn.c_str());
  523. CImageBasis *_send = NULL;
  524. esp_err_t result = ESP_FAIL;
  525. bool Dodelete = false;
  526. if (flowalignment == NULL)
  527. {
  528. ESP_LOGD(TAG, "Can't continue, flowalignment is NULL");
  529. return ESP_FAIL;
  530. }
  531. if (_fn == "alg.jpg")
  532. {
  533. _send = flowalignment->ImageBasis;
  534. }
  535. else
  536. {
  537. if (_fn == "alg_roi.jpg")
  538. {
  539. CImageBasis* _imgzw = new CImageBasis(flowalignment->ImageBasis);
  540. flowalignment->DrawRef(_imgzw);
  541. if (flowdigit) flowdigit->DrawROI(_imgzw);
  542. if (flowanalog) flowanalog->DrawROI(_imgzw);
  543. _send = _imgzw;
  544. Dodelete = true;
  545. }
  546. else
  547. {
  548. std::vector<HTMLInfo*> htmlinfo;
  549. htmlinfo = GetAllDigital();
  550. ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigital");
  551. for (int i = 0; i < htmlinfo.size(); ++i)
  552. {
  553. if (_fn == htmlinfo[i]->filename)
  554. {
  555. if (htmlinfo[i]->image)
  556. _send = htmlinfo[i]->image;
  557. }
  558. if (_fn == htmlinfo[i]->filename_org)
  559. {
  560. if (htmlinfo[i]->image_org)
  561. _send = htmlinfo[i]->image_org;
  562. }
  563. delete htmlinfo[i];
  564. }
  565. htmlinfo.clear();
  566. if (!_send)
  567. {
  568. htmlinfo = GetAllAnalog();
  569. for (int i = 0; i < htmlinfo.size(); ++i)
  570. {
  571. if (_fn == htmlinfo[i]->filename)
  572. {
  573. if (htmlinfo[i]->image)
  574. _send = htmlinfo[i]->image;
  575. }
  576. if (_fn == htmlinfo[i]->filename_org)
  577. {
  578. if (htmlinfo[i]->image_org)
  579. _send = htmlinfo[i]->image_org;
  580. }
  581. delete htmlinfo[i];
  582. }
  583. htmlinfo.clear();
  584. }
  585. }
  586. }
  587. if (_send)
  588. {
  589. ESP_LOGD(TAG, "Sending file: %s ...", _fn.c_str());
  590. set_content_type_from_file(req, _fn.c_str());
  591. result = _send->SendJPGtoHTTP(req);
  592. ESP_LOGD(TAG, "File sending complete");
  593. /* Respond with an empty chunk to signal HTTP response completion */
  594. httpd_resp_send_chunk(req, NULL, 0);
  595. }
  596. if (Dodelete)
  597. {
  598. delete _send;
  599. }
  600. return result;
  601. }
  602. string ClassFlowControll::getNumbersName()
  603. {
  604. return flowpostprocessing->getNumbersName();
  605. }
  606. string ClassFlowControll::getJSON()
  607. {
  608. return flowpostprocessing->GetJSON();
  609. }