Firmware: add ETL subcomponent
This commit is contained in:
parent
d1f64b4210
commit
40f8bb884d
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
||||
[submodule "clock-pcb/vfd-lib"]
|
||||
path = clock-pcb/vfd-lib
|
||||
url = https://github.com/jh1995/KiCad-libs.git
|
||||
[submodule "firmware/components/etlcpp/etl"]
|
||||
path = firmware/components/etlcpp/etl
|
||||
url = https://github.com/ETLCPP/etl.git
|
||||
|
||||
1
firmware/components/etlcpp/CMakeLists.txt
Normal file
1
firmware/components/etlcpp/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
idf_component_register(INCLUDE_DIRS "include" "etl/include")
|
||||
1
firmware/components/etlcpp/etl
Submodule
1
firmware/components/etlcpp/etl
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 0f1840a70d11a3d317afa55b8361829b93c8eeb8
|
||||
21
firmware/components/etlcpp/include/etl_profile.h
Normal file
21
firmware/components/etlcpp/include/etl_profile.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by erki on 13/01/24.
|
||||
//
|
||||
|
||||
#ifndef ETL_COMPILER_H
|
||||
#define ETL_COMPILER_H
|
||||
|
||||
#define ETL_COMPILER_GCC
|
||||
#define ETL_CPP23_SUPPORTED 1
|
||||
|
||||
#if !defined(CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED)
|
||||
#define ETL_NO_CHECKS
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CXX_EXCEPTIONS)
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
#include "etl/profiles/gcc_generic.h"
|
||||
|
||||
#endif // ETL_COMPILER_H
|
||||
@ -1,6 +1,6 @@
|
||||
idf_component_register(
|
||||
SRCS "main.cpp" "wifi_provisioner.cpp"
|
||||
INCLUDE_DIRS ""
|
||||
REQUIRES nvs_flash esp_wifi esp_http_server
|
||||
REQUIRES nvs_flash esp_wifi esp_http_server etlcpp
|
||||
EMBED_FILES "${CMAKE_CURRENT_LIST_DIR}/static/index.html"
|
||||
)
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
#include "esp_mac.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <etl/string.h>
|
||||
|
||||
#define TRY(x) ({ \
|
||||
const auto& _x = (x); \
|
||||
if (!_x) { \
|
||||
@ -68,8 +70,35 @@ esp_err_t rootGetHandler_(httpd_req_t* req)
|
||||
|
||||
esp_err_t rootPostHandler_(httpd_req_t* req)
|
||||
{
|
||||
etl::string<1024> content;
|
||||
|
||||
content.initialize_free_space();
|
||||
const std::size_t size = MIN(req->content_len, content.max_size() - 1);
|
||||
|
||||
if (const int ret = httpd_req_recv(req, content.data_end(), size);
|
||||
ret <= 0)
|
||||
{
|
||||
if (ret == HTTPD_SOCK_ERR_TIMEOUT)
|
||||
httpd_resp_send_408(req);
|
||||
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
content.trim_to_terminator();
|
||||
|
||||
etl::string<100> header;
|
||||
if (const auto err = httpd_req_get_hdr_value_str(req, "Content-Type", header.data(), header.max_size() - 1);
|
||||
err != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Error reading content header.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
//httpd_query_key_value
|
||||
ESP_LOGI(TAG, "Data from post: %s, %s", header.data(), content.data());
|
||||
|
||||
const char resp[] = "URI POST Response";
|
||||
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@ -171,6 +200,13 @@ std::expected<httpd_handle_t, esp_err_t> WifiProvisioner::initializeCaptivePorta
|
||||
.user_ctx = this
|
||||
};
|
||||
|
||||
static httpd_uri_t uri_post = {
|
||||
.uri = "/configure",
|
||||
.method = HTTP_POST,
|
||||
.handler = rootPostHandler_,
|
||||
.user_ctx = this
|
||||
};
|
||||
|
||||
if (const auto err = httpd_register_uri_handler(server, &uri_main);
|
||||
err != ESP_OK)
|
||||
{
|
||||
@ -178,5 +214,12 @@ std::expected<httpd_handle_t, esp_err_t> WifiProvisioner::initializeCaptivePorta
|
||||
return std::unexpected(err);
|
||||
}
|
||||
|
||||
if (const auto err = httpd_register_uri_handler(server, &uri_post);
|
||||
err != ESP_OK)
|
||||
{
|
||||
httpd_stop(server);
|
||||
return std::unexpected(err);
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user