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
+25 -2
View File
@@ -1,7 +1,30 @@
#include "aes67_ptp.h"
// Stub (build step 0).
#include "aes67_cfg.h"
// Core defaults: Riedel SIC intervals, role auto with fallback priorities (docs/aes67-core-base.md).
static const char PTP_DEFAULTS[] =
"{\"mode\":\"multicast\",\"role\":\"auto\",\"domain\":0,\"priority1\":250,\"priority2\":250,"
"\"log_sync\":0,\"log_announce\":1,\"announce_timeout\":3,\"log_delay_req\":0,"
"\"dscp\":46,\"hw_ts\":true}";
static bool ptp_validate(const cJSON *g, char *err, size_t n)
{
static const char *const modes[] = { "multicast", "hybrid", NULL };
static const char *const roles[] = { "slave", "auto", "master", NULL };
return cfg_check_enum(g, "mode", modes, err, n) &&
cfg_check_enum(g, "role", roles, err, n) &&
cfg_check_int(g, "domain", 0, 127, err, n) &&
cfg_check_int(g, "priority1", 0, 255, err, n) &&
cfg_check_int(g, "priority2", 0, 255, err, n) &&
cfg_check_int(g, "log_sync", -4, 1, err, n) &&
cfg_check_int(g, "log_announce", 0, 4, err, n) &&
cfg_check_int(g, "announce_timeout", 2, 10, err, n) &&
cfg_check_int(g, "log_delay_req", -4, 1, err, n) &&
cfg_check_int(g, "dscp", 0, 63, err, n);
}
esp_err_t aes67_ptp_init(void)
{
return ESP_OK;
return cfg_register("ptp", PTP_DEFAULTS, ptp_validate, NULL);
}