ClassFlowControll.cpp 20 KB

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