ClassFlowControll.cpp 20 KB

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