ClassFlowControll.cpp 20 KB

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