Files
aes67-ESP32-P4/components/aes67_syslog/aes67_syslog.c
T
bsncubed c2621f192a 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>
2026-09-24 23:00:55 +10:00

29 lines
1.0 KiB
C

#include "aes67_syslog.h"
#include <stdio.h>
#include "aes67_cfg.h"
// facility: 16 = local0 (PRI = facility * 8 + severity).
static const char LOG_DEFAULTS[] =
"{\"syslog\":false,\"host\":\"\",\"port\":514,\"level\":\"info\",\"facility\":16,\"format\":\"rfc5424\"}";
static bool log_validate(const cJSON *g, char *err, size_t n)
{
static const char *const levels[] = { "error", "warn", "info", "debug", NULL };
static const char *const formats[] = { "rfc5424", "rfc3164", NULL };
static const double facilities[] = { 1, 3, 16, 17, 18, 19, 20, 21, 22, 23 };
bool on = cJSON_IsTrue(cJSON_GetObjectItemCaseSensitive(g, "syslog"));
return cfg_check_str(g, "host", on ? 1 : 0, 63, err, n) &&
cfg_check_int(g, "port", 1, 65535, err, n) &&
cfg_check_enum(g, "level", levels, err, n) &&
cfg_check_num_in(g, "facility", facilities, 10, err, n) &&
cfg_check_enum(g, "format", formats, err, n);
}
esp_err_t aes67_syslog_init(void)
{
return cfg_register("log", LOG_DEFAULTS, log_validate, NULL);
}