From: Dave Hart Date: Tue, 17 May 2011 23:17:51 +0000 (+0000) Subject: Bug 1933 - WWVB/Spectracom driver timestamps LFs, not CRs X-Git-Tag: NTP_4_2_7P169~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=389ef3fb89f18b59da69e685520dab3141112557;p=thirdparty%2Fntp.git Bug 1933 - WWVB/Spectracom driver timestamps LFs, not CRs bk: 4dd3021fc-hFvkEX2wp0QSoYil-BXg --- diff --git a/ChangeLog b/ChangeLog index b10ea7851..13dc235cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1933] WWVB/Spectracom driver timestamps LFs, not CRs. (4.2.7p168) 2011/05/16 Released by Harlan Stenn * Convert receive buffer queue from doubly-linked list to FIFO. (4.2.7p167) 2011/05/14 Released by Harlan Stenn diff --git a/ntpd/refclock_wwvb.c b/ntpd/refclock_wwvb.c index 39c75beb5..c9b3a34ae 100644 --- a/ntpd/refclock_wwvb.c +++ b/ntpd/refclock_wwvb.c @@ -54,7 +54,7 @@ * hh:mm:ss = hours, minutes, seconds * i = synchronization flag (' ' = in synch, '?' = out of synch) * - * The alarm condition is indicated by other than ' ' at a, which occurs + * The alarm condition is indicated by other than ' ' at i, which occurs * during initial synchronization and when received signal is lost for * about ten hours. * @@ -69,7 +69,7 @@ * ddd = day of year * hh:mm:ss.fff = hours, minutes, seconds, milliseconds * - * The alarm condition is indicated by other than ' ' at a, which occurs + * The alarm condition is indicated by other than ' ' at i, which occurs * during initial synchronization and when received signal is lost for * about ten hours. The unlock condition is indicated by other than ' ' * at q. @@ -120,9 +120,8 @@ #define DESCRIPTION "Spectracom WWVB/GPS Receiver" /* WRU */ #define LENWWVB0 22 /* format 0 timecode length */ -#define LENWWVB1 22 /* format 1 timecode length */ #define LENWWVB2 24 /* format 2 timecode length */ -#define LENWWVB3 29 /* format 3 timecode length */ +#define LENWWVB3 29 /* format 3 timecode length */ #define MONLIN 15 /* number of monitoring lines */ /* @@ -136,7 +135,8 @@ struct wwvbunit { int tcount; /* timecode sample counter */ int pcount; /* PPS sample counter */ #endif /* HAVE_PPSAPI */ - l_fp laststamp; /* last receive timestamp */ + l_fp laststamp; /* last timestamp */ + int prev_eol_cr; /* was last EOL (not )? */ u_char lasthour; /* last hour (for monitor) */ u_char linect; /* count ignored lines (for monitor */ }; @@ -249,6 +249,7 @@ wwvb_receive( struct recvbuf *rbufp ) { + const l_fp one_char_time = { { 0 }, { (u_int32)(FRAC / 960) } }; struct wwvbunit *up; struct refclockproc *pp; struct peer *peer; @@ -280,13 +281,43 @@ wwvb_receive( * reading precision is only to the millisecond. Thus, unless * you have a PPS gadget and don't have to have the year, format * 0 provides the lowest jitter. + * Save the timestamp of each in up->laststamp. Lines with + * no characters occur for every , and for some s when + * format 0 is used. Format 0 starts and ends each cycle with a + * pair, format 2 starts each cycle with its only pair. + * The preceding is the on-time character for both formats. + * The timestamp provided with non-empty lines corresponds to + * the following the timecode, which is ultimately not used + * with format 0 and is used for the following timecode for + * format 2. */ if (temp == 0) { - up->laststamp = trtmp; + if (up->prev_eol_cr) { + DPRINTF(2, ("wwvb: @ %s\n", + prettydate(&trtmp))); + } else { + up->laststamp = trtmp; + DPRINTF(2, ("wwvb: @ %s\n", + prettydate(&trtmp))); + } + up->prev_eol_cr = !up->prev_eol_cr; return; } pp->lencode = temp; pp->lastrec = up->laststamp; + up->laststamp = trtmp; + up->prev_eol_cr = TRUE; + DPRINTF(2, ("wwvb: code @ %s\n" + " using %s minus one char\n", + prettydate(&trtmp), prettydate(&pp->lastrec))); + if (L_ISZERO(&pp->lastrec)) + return; + + /* + * The start of the is the on-time event, while our + * timestamp reflects the end of that at best. Adjust. + */ + L_SUB(&pp->lastrec, &one_char_time); /* * We get down to business, check the timecode format and decode @@ -306,9 +337,11 @@ wwvb_receive( if (sscanf(pp->a_lastcode, "%c %3d %2d:%2d:%2d%c%cTZ=%2d", &syncchar, &pp->day, &pp->hour, &pp->minute, - &pp->second, &tmpchar, &dstchar, &tz) == 8) + &pp->second, &tmpchar, &dstchar, &tz) == 8) { pp->nsec = 0; break; + } + goto bad_format; case LENWWVB2: @@ -318,14 +351,19 @@ wwvb_receive( "%c%c %2d %3d %2d:%2d:%2d.%3ld %c", &syncchar, &qualchar, &pp->year, &pp->day, &pp->hour, &pp->minute, &pp->second, &pp->nsec, - &leapchar) == 9) + &leapchar) == 9) { pp->nsec *= 1000000; break; + } + goto bad_format; case LENWWVB3: - /* + /* * Timecode format 3: "0003I yyyymmdd hhmmss+0000SL#" + * WARNING: Undocumented, and the on-time character # is + * not yet handled correctly by this driver. It may be + * as simple as compensating for an additional 1/960 s. */ if (sscanf(pp->a_lastcode, "0003%c %4d%2d%2d %2d%2d%2d+0000%c%c", @@ -336,8 +374,10 @@ wwvb_receive( pp->nsec = 0; break; } + goto bad_format; default: + bad_format: /* * Unknown format: If dumping internal table, record