Step 6.2: role hand-over, session_ver bump on GM change

- aes67_cfg: cfg_set_number(group, key, value, apply) for firmware-side
  changes, stored in NVS like a POST; apply can be skipped.
- aes67_sdp_sap: once a second, a change of the PTP GM (ts-refclk) bumps
  aes67.session_ver without re-applying the aes67 group (no stream
  restart); SAP then re-announces. Runs whether or not SAP is on.
- Verified with ptp4l as a normal clock (p1 128): board auto (p1 250)
  steps down to SLAVE (session_ver 1->2); role master p1 100 via API ->
  board MASTER at once (->3); back to auto p1 250 -> ptp4l takes over
  within ~1 s, board SLAVE again (->4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 08:08:00 +10:00
parent 08b83a069c
commit dcea39b216
4 changed files with 56 additions and 1 deletions
+21
View File
@@ -164,6 +164,26 @@ static bool sap_wanted(uint8_t *ttl)
return on;
}
// When the PTP GM changes, the SDP's ts-refclk changes: bump the session version (RFC 4566 o=)
// so receivers see a new description. Runs whether or not SAP is on (manual SDP users too).
static void check_gm_change(void)
{
static char last[24];
char gm[24];
if (!aes67_ptp_gm_id(gm) || strcmp(gm, last) == 0) {
return;
}
if (last[0]) {
cJSON *a = cfg_get("aes67");
double ver = cJSON_GetObjectItemCaseSensitive(a, "session_ver")->valuedouble + 1;
cJSON_Delete(a);
// Not applied: re-applying the aes67 group would restart the stream.
esp_err_t err = cfg_set_number("aes67", "session_ver", ver, false);
ESP_LOGI(TAG, "PTP TimeTransmitter %s -> %s: session_ver %.0f (%s)", last, gm, ver, esp_err_to_name(err));
}
strcpy(last, gm);
}
static void sap_task(void *arg)
{
static char sdp[SDP_MAX];
@@ -172,6 +192,7 @@ static void sap_task(void *arg)
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));
check_gm_change();
esp_netif_ip_info_t ip;
esp_netif_t *netif = aes67_net_netif();
bool have_ip = netif && esp_netif_get_ip_info(netif, &ip) == ESP_OK && ip.ip.addr;