PTP: drop the "Preferred TimeTransmitter" role
It behaved exactly like auto (clock class 248); the only difference was a priority1 suggestion in the page. Roles are now slave|auto; to prefer this device, use auto with a low priority1. A stored "master" is converted to auto at boot (new cfg_set_string, like cfg_set_number). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "aes67_ptp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "aes67_cfg.h"
|
||||
#include "aes67_web.h"
|
||||
#include "esp_log.h"
|
||||
#include "ptp_clock.h"
|
||||
#include "ptp_hw.h"
|
||||
|
||||
@@ -14,7 +17,7 @@ static const char PTP_DEFAULTS[] =
|
||||
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 };
|
||||
static const char *const roles[] = { "slave", "auto", 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) &&
|
||||
@@ -34,7 +37,20 @@ static void ptp_apply(const cJSON *g)
|
||||
|
||||
esp_err_t aes67_ptp_init(void)
|
||||
{
|
||||
return cfg_register("ptp", PTP_DEFAULTS, ptp_validate, ptp_apply);
|
||||
esp_err_t err = cfg_register("ptp", PTP_DEFAULTS, ptp_validate, ptp_apply);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
// Role "master" was dropped (it behaved like auto; a low priority1 does the same). Stored values
|
||||
// aren't re-validated, so convert it here.
|
||||
cJSON *c = cfg_get("ptp");
|
||||
bool master = !strcmp(cJSON_GetObjectItemCaseSensitive(c, "role")->valuestring, "master");
|
||||
cJSON_Delete(c);
|
||||
if (master) {
|
||||
ESP_LOGW("ptp", "stored role \"master\" is no longer offered: now \"auto\" (same behaviour)");
|
||||
cfg_set_string("ptp", "role", "auto", false);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t aes67_ptp_start(esp_eth_handle_t eth)
|
||||
|
||||
@@ -622,8 +622,8 @@ static void load_config(void)
|
||||
s.cfg_log_sync = cJSON_GetObjectItem(c, "log_sync")->valueint;
|
||||
s.cfg_log_announce = cJSON_GetObjectItem(c, "log_announce")->valueint;
|
||||
s.cfg_log_dreq = cJSON_GetObjectItem(c, "log_delay_req")->valueint;
|
||||
// Roles (docs): slave = clockClass 255, never transmits; auto/master = 248 with the configured
|
||||
// priorities (auto 250/250 by default, master e.g. p1 100).
|
||||
// Roles (docs): slave = clockClass 255, never transmits; auto = 248 with the configured priorities
|
||||
// (250/250 by default: loses to any real GM; a lower priority1 prefers this device).
|
||||
s.slave_only = strcmp(cJSON_GetObjectItem(c, "role")->valuestring, "slave") == 0;
|
||||
s.hybrid = strcmp(cJSON_GetObjectItem(c, "mode")->valuestring, "hybrid") == 0;
|
||||
s.own_class = s.slave_only ? 255 : 248;
|
||||
@@ -711,7 +711,7 @@ static void ptp_task(void *arg)
|
||||
int tos2 = s.dscp << 2;
|
||||
setsockopt(s.gen, IPPROTO_IP, IP_TOS, &tos2, sizeof(tos2));
|
||||
ESP_LOGI(TAG, "config applied: role %s, mode %s, p1 %u p2 %u, domain %u",
|
||||
s.slave_only ? "slave" : "auto/master", s.hybrid ? "hybrid" : "multicast",
|
||||
s.slave_only ? "slave" : "auto", s.hybrid ? "hybrid" : "multicast",
|
||||
s.own.p1, s.own.p2, s.domain);
|
||||
// Re-run the decision: a foreign GM worse than our new dataset is dropped; as
|
||||
// TimeTransmitter with role slave we stop.
|
||||
|
||||
Reference in New Issue
Block a user