Make use of the configuration file for the default data set.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2011-12-31 09:18:25 +01:00
parent ec5e783e84
commit 1092c4237b
1 changed files with 21 additions and 5 deletions

26
ptp4l.c
View File

@ -22,6 +22,7 @@
#include <unistd.h>
#include "clock.h"
#include "config.h"
#include "print.h"
#include "transport.h"
#include "udp.h"
@ -30,6 +31,7 @@
static int running = 1;
static struct defaultDS ds;
static struct port_defaults pod;
static int generate_clock_identity(struct ClockIdentity *ci, char *name)
{
@ -60,11 +62,12 @@ static void usage(char *progname)
" -s SOFTWARE\n"
" -z LEGACY HW\n\n"
" Other Options\n\n"
" -f [file] read configuration from 'file'\n"
" -h prints this message and exits\n"
" -i [dev] interface device to use, for example 'eth0'\n"
" (may be specified multiple times)\n"
" -l [num] set the logging level to 'num'\n"
" -m slave only mode\n"
" -m slave only mode (overrides configuration file)\n"
" -p [dev] PTP hardware clock device to use, default '%s'\n"
" (ignored for SOFTWARE/LEGACY HW time stamping)\n\n",
progname, DEFAULT_PHC);
@ -72,7 +75,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
char *phc = DEFAULT_PHC, *progname;
char *config = NULL, *phc = DEFAULT_PHC, *progname;
int c, i, nports = 0, slaveonly = 0;
struct interface iface[MAX_PORTS];
enum transport_type transport = TRANS_UDP_IPV4;
@ -82,7 +85,7 @@ int main(int argc, char *argv[])
/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
while (EOF != (c = getopt(argc, argv, "246hi:l:mp:rsz"))) {
while (EOF != (c = getopt(argc, argv, "246f:hi:l:mp:rsz"))) {
switch (c) {
case '2':
transport = TRANS_IEEE_802_3;
@ -93,6 +96,9 @@ int main(int argc, char *argv[])
case '6':
transport = TRANS_UDP_IPV6;
break;
case 'f':
config = optarg;
break;
case 'i':
if (nports < MAX_PORTS) {
iface[nports++].name = optarg;
@ -143,9 +149,9 @@ int main(int argc, char *argv[])
phc = NULL;
}
ds.slaveOnly = slaveonly ? TRUE : FALSE;
ds.slaveOnly = FALSE;
ds.priority1 = 128;
ds.clockQuality.clockClass = slaveonly ? 255 : 248;
ds.clockQuality.clockClass = 248;
ds.clockQuality.clockAccuracy = 0xfe;
ds.clockQuality.offsetScaledLogVariance = 0xffff;
ds.priority2 = 128;
@ -155,6 +161,16 @@ int main(int argc, char *argv[])
return -1;
}
if (config && config_read(config, &ds, &pod)) {
fprintf(stderr, "failed to read configuration file\n");
return -1;
}
if (slaveonly) {
ds.slaveOnly = TRUE;
ds.clockQuality.clockClass = 255;
}
clock = clock_create(phc, iface, nports, &ds);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");