On Mon, 10 Sep 2007, Maurice Janssen wrote:
quoted text > On Monday, September 10, 2007 at 19:48:59 +0200, Henning Brauer wrote:
> >i think that is super useful, so a commit-ready diff would be awesome :)
>
> OK, here it is. Feel free to change where necessary.
A quick look shows it is probably not needed to have a "offset" non-terminal,
if you define sensor_offset as
sensor_offset : /* empty */ { $$ = 0; }
| SENSOROFFSET number {
etc
-Otto
quoted text >
>
> Index: ntpd.conf.5
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ntpd/ntpd.conf.5,v
> retrieving revision 1.16
> diff -u -r1.16 ntpd.conf.5
> --- ntpd.conf.5 31 May 2007 19:20:26 -0000 1.16
> +++ ntpd.conf.5 10 Sep 2007 18:14:14 -0000
> @@ -72,6 +72,7 @@
> .Ed
> .It Xo Ic sensor Ar device
> .Op Ic weight Ar weight-value
> +.Op Ic offset Ar milliseconds
> .Xc
> Specify a timedelta sensor device
> .Xr ntpd 8
> @@ -91,6 +92,15 @@
> .Bd -literal -offset indent
> sensor *
> sensor udcf0
> +.Ed
> +.Pp
> +An optional offset in milliseconds can be given to compensate
> +for the sensors offset. Negative numbers must be enclosed in
> +double quotes.
> +For example, if your DCF77 receiver is lagging 15 ms behind
> +actual time:
> +.Bd -literal -offset indent
> +sensor udcf0 offset "-15"
> .Ed
> .It Xo Ic server Ar address
> .Op Ic weight Ar weight-value
> Index: ntpd.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ntpd/ntpd.h,v
> retrieving revision 1.85
> diff -u -r1.85 ntpd.h
> --- ntpd.h 4 Aug 2007 02:58:02 -0000 1.85
> +++ ntpd.h 10 Sep 2007 18:14:14 -0000
> @@ -143,12 +143,14 @@
> int sensordevid;
> u_int8_t weight;
> u_int8_t shift;
> + int32_t sensor_offset;
> };
>
> struct ntp_conf_sensor {
> TAILQ_ENTRY(ntp_conf_sensor) entry;
> char *device;
> u_int8_t weight;
> + int32_t sensor_offset;
> };
>
> struct ntp_freq {
> Index: parse.y
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ntpd/parse.y,v
> retrieving revision 1.30
> diff -u -r1.30 parse.y
> --- parse.y 3 Oct 2006 00:49:09 -0000 1.30
> +++ parse.y 10 Sep 2007 18:14:14 -0000
> @@ -54,6 +54,7 @@
> typedef struct {
> union {
> u_int32_t number;
> + int32_t mseconds;
> char *string;
> struct ntp_addr_wrap *addr;
> } v;
> @@ -63,11 +64,12 @@
> %}
>
> %token LISTEN ON
> -%token SERVER SERVERS SENSOR WEIGHT
> +%token SERVER SERVERS SENSOR WEIGHT SENSOROFFSET
> %token ERROR
> %token <v.string> STRING
> %type <v.addr> address
> %type <v.number> number weight
> +%type <v.mseconds> mseconds sensor_offset
> %%
>
> grammar : /* empty */
> @@ -180,11 +182,12 @@
> free(->name);
> free();
> }
> - | SENSOR STRING weight {
> + | SENSOR STRING weight sensor_offset {
> struct ntp_conf_sensor *s;
>
> s = new_sensor();
> s->weight = ;
> + s->sensor_offset = ;
> free();
> TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry);
> }
> @@ -220,6 +223,21 @@
> }
> ;
>
> +mseconds : STRING {
> + long lval;
> + const char *errstr;
> +
> + lval = strtonum(, INT_MIN, INT_MAX, &errstr);
> + if (errstr) {
> + yyerror("\"%s\" invalid: %s", , errstr);
> + free();
> + YYERROR;
> + } else
> + $$ = lval;
> + free();
> + }
> + ;
> +
> weight : /* empty */ { $$ = 1; }
> | WEIGHT number {
> if ( < 1 || > 10) {
> @@ -230,6 +248,16 @@
> }
> ;
>
> +sensor_offset : /* empty */ { $$ = 0; }
> + | SENSOROFFSET mseconds {
> + if ( < -127000 || > 127000) {
> + yyerror("offset must be between -127000 and 127000 milliseconds");
> + YYERROR;
> + }
> + $$ = ;
> + }
> + ;
> +
> %%
>
> struct keywords {
> @@ -265,6 +293,7 @@
> /* this has to be sorted always */
> static const struct keywords keywords[] = {
> { "listen", LISTEN},
> + { "offset", SENSOROFFSET},
> { "on", ON},
> { "sensor", SENSOR},
> { "server", SERVER},
> Index: sensors.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ntpd/sensors.c,v
> retrieving revision 1.33
> diff -u -r1.33 sensors.c
> --- sensors.c 4 Aug 2007 02:58:02 -0000 1.33
> +++ sensors.c 10 Sep 2007 18:14:14 -0000
> @@ -121,6 +121,7 @@
>
> s->next = getmonotime();
> s->weight = cs->weight;
> + s->sensor_offset = cs->sensor_offset;
> if ((s->device = strdup(dxname)) == NULL)
> fatal("sensor_add strdup");
> s->sensordevid = sensordev;
> @@ -176,7 +177,8 @@
> * sensor.value = TS - TD in ns
> * if value is positive, system time is ahead
> */
> - s->offsets[s->shift].offset = (sensor.value / -1e9) - getoffset();
> + s->offsets[s->shift].offset = (sensor.value / -1e9) - getoffset() -
> + (s->sensor_offset / 1e3);
> s->offsets[s->shift].rcvd = sensor.tv.tv_sec;
> s->offsets[s->shift].good = 1;