|
|
@@ -114,6 +114,96 @@ esp_err_t get_data_file_handler(httpd_req_t *req)
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+static void append_json_string(std::string &json, const std::string &value)
|
|
|
+{
|
|
|
+ static const char hex[] = "0123456789abcdef";
|
|
|
+ json += '"';
|
|
|
+ for (unsigned char c : value)
|
|
|
+ {
|
|
|
+ switch (c)
|
|
|
+ {
|
|
|
+ case '"': json += "\\\""; break;
|
|
|
+ case '\\': json += "\\\\"; break;
|
|
|
+ case '\b': json += "\\b"; break;
|
|
|
+ case '\f': json += "\\f"; break;
|
|
|
+ case '\n': json += "\\n"; break;
|
|
|
+ case '\r': json += "\\r"; break;
|
|
|
+ case '\t': json += "\\t"; break;
|
|
|
+ default:
|
|
|
+ if (c < 0x20)
|
|
|
+ {
|
|
|
+ json += "\\u00";
|
|
|
+ json += hex[(c >> 4) & 0x0f];
|
|
|
+ json += hex[c & 0x0f];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ json += static_cast<char>(c);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ json += '"';
|
|
|
+}
|
|
|
+
|
|
|
+static std::string collect_file_list(const char *directory, bool model_files)
|
|
|
+{
|
|
|
+ std::string result;
|
|
|
+ DIR *dir = opendir(directory);
|
|
|
+ if (!dir)
|
|
|
+ {
|
|
|
+ ESP_LOGW(TAG, "Cannot open list directory: %s", directory);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ struct dirent *entry;
|
|
|
+ while ((entry = readdir(dir)) != NULL)
|
|
|
+ {
|
|
|
+ const std::string filename(entry->d_name);
|
|
|
+ if (filename.empty() || filename[0] == '.')
|
|
|
+ continue;
|
|
|
+
|
|
|
+ const size_t dot = filename.find_last_of('.');
|
|
|
+ const std::string extension = dot == std::string::npos ? "" : filename.substr(dot + 1);
|
|
|
+ const bool accepted = model_files
|
|
|
+ ? (extension == "tfl" || extension == "tflite")
|
|
|
+ : (extension == "csv");
|
|
|
+
|
|
|
+ if (accepted)
|
|
|
+ {
|
|
|
+ if (model_files)
|
|
|
+ result += "/config/";
|
|
|
+ result += filename;
|
|
|
+ result += '\t';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ closedir(dir);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+esp_err_t get_editflow_lists_file_handler(httpd_req_t *req)
|
|
|
+{
|
|
|
+ const std::string numbers = flowctrl.getNumbersName();
|
|
|
+ const std::string data = collect_file_list("/sdcard/log/data", false);
|
|
|
+ const std::string tflite = collect_file_list("/sdcard/config", true);
|
|
|
+
|
|
|
+ std::string response;
|
|
|
+ response.reserve(numbers.size() + data.size() + tflite.size() + 64);
|
|
|
+ response += "{\\"numbers\\":";
|
|
|
+ append_json_string(response, numbers);
|
|
|
+ response += ",\\"data\\":";
|
|
|
+ append_json_string(response, data);
|
|
|
+ response += ",\\"tflite\\":";
|
|
|
+ append_json_string(response, tflite);
|
|
|
+ response += "}";
|
|
|
+
|
|
|
+ httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
|
|
+ httpd_resp_set_type(req, "application/json");
|
|
|
+ return httpd_resp_send(req, response.c_str(), response.length());
|
|
|
+}
|
|
|
+
|
|
|
esp_err_t get_tflite_file_handler(httpd_req_t *req)
|
|
|
{
|
|
|
struct dirent *entry;
|