Step 2.2: config registry and NVS store, GET/POST /api/config

- aes67_web/cfg.c: cfg_register(group, defaults, validate, apply),
  cfg_override_defaults() for project defaults, cfg_get(). Stored values
  are loaded on register and merged over defaults (known keys, matching
  types). NVS keeps only keys that differ from defaults, one JSON string
  per group, so new firmware defaults still reach untouched settings.
- POST /api/config: type check against defaults, per-group validation,
  nothing stored unless every group passes; 400 "group.key: reason".
  Unknown keys/groups are ignored. Returns the new config.
- Core groups registered by their components with the UI's ranges:
  ptp (aes67_ptp), aes67 (aes67_tx, incl. multicast range and mono_sum
  => 1 channel), net/inet (aes67_net), log (aes67_syslog).
- Project: PROJECT.def overrides (hostname p4-aes67, name P4 AES67) and
  the "source" group in main/project_cfg.c.
- Config is stored only; nothing is applied live yet.
- Verified on board: defaults, valid save, 8 rejected values (nothing
  stored), persistence across reboot, restore to defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-24 23:00:55 +10:00
parent 35275b8ccf
commit c2621f192a
20 changed files with 744 additions and 15 deletions
+11 -2
View File
@@ -1,5 +1,7 @@
#include "aes67_web.h"
#include "aes67_cfg.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_timer.h"
@@ -13,6 +15,8 @@ static const char *TAG = "web";
extern const char index_html_start[] asm("_binary_index_html_start");
extern const char index_html_end[] asm("_binary_index_html_end");
esp_err_t cfg_web_register(void); // cfg.c
static httpd_handle_t s_httpd;
static status_cb_t s_status_cbs[MAX_STATUS_CBS];
static int s_status_n;
@@ -91,13 +95,18 @@ static esp_err_t reboot_post(httpd_req_t *req)
esp_err_t aes67_web_start(void)
{
esp_err_t err = cfg_web_register();
if (err != ESP_OK) {
return err;
}
httpd_config_t cfg = HTTPD_DEFAULT_CONFIG();
cfg.max_uri_handlers = MAX_URIS;
cfg.stack_size = 8192;
cfg.lru_purge_enable = true;
cfg.uri_match_fn = httpd_uri_match_wildcard;
esp_err_t err = httpd_start(&s_httpd, &cfg);
err = httpd_start(&s_httpd, &cfg);
if (err != ESP_OK) {
ESP_LOGE(TAG, "httpd start failed: %s", esp_err_to_name(err));
return err;
@@ -116,7 +125,7 @@ esp_err_t aes67_web_start(void)
httpd_register_uri_handler(s_httpd, &s_early_uris[i]);
}
ESP_LOGI(TAG, "httpd started, index.html %d bytes, %d project routes",
ESP_LOGI(TAG, "httpd started, index.html %d bytes, %d extra routes",
(int)(index_html_end - index_html_start - 1), s_early_n);
return ESP_OK;
}