From ea574c7e4f6b45bee2f8663e11249f1b1fe1435e Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 15 Aug 2015 19:16:32 +0200 Subject: [PATCH] config: convert 'slaveOnly' and 'twoStepFlag' to the new scheme. Signed-off-by: Richard Cochran --- config.c | 29 +++++------------------------ config.h | 1 - ptp4l.c | 14 +++++++++++--- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/config.c b/config.c index 1c4421b..87d944f 100644 --- a/config.c +++ b/config.c @@ -126,11 +126,13 @@ struct config_item config_tab[] = { GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0), GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX), GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX), + GLOB_ITEM_INT("slaveOnly", 0, 0, 1), GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX), GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX), PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX), GLOB_ITEM_INT("timeSource", INTERNAL_OSCILLATOR, 0x10, 0xfe), PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F), + GLOB_ITEM_INT("twoStepFlag", 1, 0, 1), GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX), PORT_ITEM_INT("udp_ttl", 1, 1, 255), PORT_ITEM_INT("udp6_scope", 0x0E, 0x00, 0x0F), @@ -382,7 +384,7 @@ static enum parser_result parse_global_setting(const char *option, const char *value, struct config *cfg) { - int i, val, cfg_ignore = cfg->cfg_ignore; + int i, cfg_ignore = cfg->cfg_ignore; unsigned int uval; unsigned char mac[MAC_LEN]; unsigned char oui[OUI_LEN]; @@ -394,27 +396,7 @@ static enum parser_result parse_global_setting(const char *option, if (r != NOT_PARSED) return r; - if (!strcmp(option, "twoStepFlag")) { - r = get_ranged_int(value, &val, 0, 1); - if (r != PARSED_OK) - return r; - if (val) - dds->flags |= DDS_TWO_STEP_FLAG; - else - dds->flags &= ~DDS_TWO_STEP_FLAG; - - } else if (!strcmp(option, "slaveOnly")) { - r = get_ranged_int(value, &val, 0, 1); - if (r != PARSED_OK) - return r; - if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY)) { - if (val) - dds->flags |= DDS_SLAVE_ONLY; - else - dds->flags &= ~DDS_SLAVE_ONLY; - } - - } else if (!strcmp(option, "priority1")) { + if (!strcmp(option, "priority1")) { r = get_ranged_uint(value, &uval, 0, UINT8_MAX); if (r != PARSED_OK) return r; @@ -436,8 +418,7 @@ static enum parser_result parse_global_setting(const char *option, r = get_ranged_uint(value, &uval, 0, UINT8_MAX); if (r != PARSED_OK) return r; - if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY)) - dds->clockQuality.clockClass = uval; + dds->clockQuality.clockClass = uval; } else if (!strcmp(option, "clockAccuracy")) { r = get_ranged_uint(value, &uval, 0, UINT8_MAX); diff --git a/config.h b/config.h index 0ccb3ea..9100083 100644 --- a/config.h +++ b/config.h @@ -45,7 +45,6 @@ struct interface { #define CFG_IGNORE_DM (1 << 0) #define CFG_IGNORE_TRANSPORT (1 << 1) #define CFG_IGNORE_TIMESTAMPING (1 << 2) -#define CFG_IGNORE_SLAVEONLY (1 << 3) struct config { /* configuration override */ diff --git a/ptp4l.c b/ptp4l.c index 08f7512..89a659d 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -44,7 +44,6 @@ static struct config cfg_settings = { .dds = { .dds = { - .flags = DDS_TWO_STEP_FLAG, .priority1 = 128, .clockQuality.clockClass = 248, .clockQuality.clockAccuracy = 0xfe, @@ -187,8 +186,9 @@ int main(int argc, char *argv[]) req_phc = optarg; break; case 's': - ds->flags |= DDS_SLAVE_ONLY; - *cfg_ignore |= CFG_IGNORE_SLAVEONLY; + if (config_set_int(cfg, "slaveOnly", 1)) { + return -1; + } break; case 'l': if (get_arg_val_i(c, optarg, &print_level, @@ -225,6 +225,14 @@ int main(int argc, char *argv[]) sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync"); sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout"); + if (config_get_int(cfg, NULL, "slaveOnly")) { + ds->flags |= DDS_SLAVE_ONLY; + ds->clockQuality.clockClass = 248; + } + if (config_get_int(cfg, NULL, "twoStepFlag")) { + ds->flags |= DDS_TWO_STEP_FLAG; + } + if (!config_get_int(cfg, NULL, "gmCapable") && ds->flags & DDS_SLAVE_ONLY) { fprintf(stderr,