Skip to content

Commit

Permalink
ptp4l: add missing options to config file
Browse files Browse the repository at this point in the history
This patch adds support to the configuration file for all of the options
specified on the command line.

-v2
* Fix string length to account for null byte
* Add PRINT_LEVEL_MIN/MAX defines

Signed-off-by: Jacob Keller <[email protected]>
  • Loading branch information
jacob-keller authored and richardcochran committed Aug 21, 2012
1 parent 7a69db2 commit fcdc675
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
59 changes: 58 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string.h>
#include "config.h"
#include "ether.h"
#include "print.h"

static void scan_line(char *s, struct config *cfg)
{
Expand All @@ -29,14 +30,15 @@ static void scan_line(char *s, struct config *cfg)
UInteger16 u16;
UInteger8 u8;
unsigned char mac[MAC_LEN];
char string[1024];

struct defaultDS *dds = &cfg->dds;
struct port_defaults *pod = &cfg->pod;

if (1 == sscanf(s, " twoStepFlag %d", &val)) {

if (val) /* TODO - implement one step */
dds->twoStepFlag = val ? 1 : 0;
dds->twoStepFlag = val ? 1 : 0;

} else if (1 == sscanf(s, " slaveOnly %d", &val)) {

Expand Down Expand Up @@ -133,6 +135,61 @@ static void scan_line(char *s, struct config *cfg)

for (i = 0; i < MAC_LEN; i++)
cfg->p2p_dst_mac[i] = mac[i];

} else if (1 == sscanf(s, " logging_level %d", &val)) {

if (val >= PRINT_LEVEL_MIN && val <= PRINT_LEVEL_MAX)
cfg->print_level = val;

} else if (1 == sscanf(s, " verbose %d", &val)) {

cfg->verbose = val ? 1 : 0;

} else if (1 == sscanf(s, " use_syslog %d", &val)) {

cfg->use_syslog = val ? 1 : 0;

} else if (1 == sscanf(s, " time_stamping %1023s", string)) {

if (0 == strcasecmp("hardware", string))

cfg->timestamping = TS_HARDWARE;

else if (0 == strcasecmp("software", string))

cfg->timestamping = TS_SOFTWARE;

else if (0 == strcasecmp("legacy", string))

cfg->timestamping = TS_LEGACY_HW;

} else if (1 == sscanf(s, " delay_mechanism %1023s", string)) {

if (0 == strcasecmp("E2E", string))

cfg->dm = DM_E2E;

else if (0 == strcasecmp("P2P", string))

cfg->dm = DM_P2P;

else if (0 == strcasecmp("Auto", string))

cfg->dm = DM_AUTO;
} else if (1 == sscanf(s, " network_transport %1023s", string)) {

if (0 == strcasecmp("UDPv4", string))

cfg->transport = TRANS_UDP_IPV4;

else if (0 == strcasecmp("UDPv6", string))

cfg->transport = TRANS_UDP_IPV6;

else if (0 == strcasecmp("L2", string))

cfg->transport = TRANS_IEEE_802_3;

}
}

Expand Down
4 changes: 4 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ struct config {
double *pi_integral_const;
unsigned char *ptp_dst_mac;
unsigned char *p2p_dst_mac;

int print_level;
int use_syslog;
int verbose;
};

int config_read(char *name, struct config *cfg);
Expand Down
3 changes: 3 additions & 0 deletions print.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include <syslog.h>

#define PRINT_LEVEL_MIN LOG_EMERG
#define PRINT_LEVEL_MAX LOG_DEBUG

void print(int level, char const *format, ...);

void print_set_syslog(int value);
Expand Down
14 changes: 11 additions & 3 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ static struct config cfg_settings = {
.pi_integral_const = &configured_pi_ki,
.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,

.print_level = LOG_INFO,
.use_syslog = 1,
.verbose = 0,
};

static void usage(char *progname)
Expand Down Expand Up @@ -162,13 +166,13 @@ int main(int argc, char *argv[])
slaveonly = 1;
break;
case 'l':
print_set_level(atoi(optarg));
cfg_settings.print_level = atoi(optarg);
break;
case 'q':
print_set_syslog(1);
cfg_settings.use_syslog = 0;
break;
case 'v':
print_set_verbose(1);
cfg_settings.verbose = 1;
break;
case 'h':
usage(progname);
Expand Down Expand Up @@ -221,6 +225,10 @@ int main(int argc, char *argv[])
ds->clockQuality.clockClass = 255;
}

print_set_verbose(cfg_settings.verbose);
print_set_syslog(cfg_settings.use_syslog);
print_set_level(cfg_settings.print_level);

clock = clock_create(phc_index, iface, *nports, *timestamping, ds);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
Expand Down

0 comments on commit fcdc675

Please sign in to comment.