From: Dave Hart Date: Sat, 11 Jul 2009 05:47:56 +0000 (+0000) Subject: [Bug 1237] Windows serial code treat CR and LF both as line X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2573c18f9a67b984a7c195a35627a9f00a3e44c0;p=thirdparty%2Fntp.git [Bug 1237] Windows serial code treat CR and LF both as line terminators. [Bug 1238] use fudge time2 for serial timecode offset in NMEA driver. document fudge time1 as PPS offset, fudge time2 as serial timecode offset for driver20.html (NMEA) bk: 4a58278cfU51ZGIMdfe9OaGRuGh_AA --- diff --git a/ChangeLog b/ChangeLog index 4d07fe48f5..44a459631f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,14 @@ +* [Bug 1237] Windows serial code treat CR and LF both as line + terminators. +* [Bug 1238] use fudge time2 for serial timecode offset in NMEA driver. (4.2.5p185) 2009/07/01 Released by Harlan Stenn * Documentation updates from Dave Mills. * [Bug 1234] convert NMEA driver to use common PPSAPI code. * timepps-Solaris.h pps_handle_t changed from pointer to scalar * Spectracom refclock added to Windows port of ntpd * [Bug 1236] Declaration order fixed. -* Bracket private ONCORE debug statements with #if 0 rather than #ifdef DEBUG +* Bracket private ONCORE debug statements with #if 0 rather than #ifdef + DEBUG * Delete ONCORE debug statement that is now handled elsewhere. (4.2.5p184) 2009/06/24 Released by Harlan Stenn * [Bug 1233] atom refclock fudge time1 sign flipped in 4.2.5p164. diff --git a/html/drivers/driver20.html b/html/drivers/driver20.html index c683743908..9b871a937f 100644 --- a/html/drivers/driver20.html +++ b/html/drivers/driver20.html @@ -80,9 +80,9 @@ $GPZDG,GPSTIME,DD,MM,YYYY,AA.BB,V*CS<cr><lf>

Fudge Factors

time1 time -
Specifies the time offset calibration factor, in seconds and fraction, with default 0.0. +
Specifies the PPS time offset calibration factor, in seconds and fraction, with default 0.0.
time2 time -
Not used by this driver. +
Specifies the serial end of line time offset calibration factor, in seconds and fraction, with default 0.0.
stratum number
Specifies the driver stratum, in decimal from 0 to 15, with default 0.
refid string diff --git a/ntpd/refclock_nmea.c b/ntpd/refclock_nmea.c index dd94efa828..8be9879a00 100644 --- a/ntpd/refclock_nmea.c +++ b/ntpd/refclock_nmea.c @@ -9,6 +9,11 @@ * * Updated to process 'time1' fudge factor * Venu Gopal May 05, 2008 + * + * Converted to common PPSAPI code, separate PPS fudge time1 + * from serial timecode fudge time2. + * Dave Hart July 1, 2009 + * hart@ntp.org, davehart@davehart.com */ #ifdef HAVE_CONFIG_H #include @@ -333,6 +338,7 @@ nmea_timer( 0) { up->pcount++, peer->flags |= FLAG_PPS; + peer->precision = PPS_PRECISION; } } } @@ -354,6 +360,7 @@ nmea_receive( char *cp, *dp, *msg; int cmdtype; int cmdtypezdg = 0; + l_fp lfp_fudgetime2; /* Use these variables to hold data until we decide its worth keeping */ char rd_lastcode[BMAX]; l_fp rd_timestamp; @@ -463,7 +470,10 @@ nmea_receive( memcpy(pp->a_lastcode, rd_lastcode, pp->lencode + 1); cp = pp->a_lastcode; - pp->lastrec = up->tstamp = rd_timestamp; + DTOLFP(pp->fudgetime2, &lfp_fudgetime2); + L_ADD(&rd_timestamp, &lfp_fudgetime2); + up->tstamp = rd_timestamp; + pp->lastrec = up->tstamp; DPRINTF(1, ("nmea: timecode %d %s\n", pp->lencode, pp->a_lastcode)); @@ -762,8 +772,10 @@ nmea_poll( * timeout and keep going. */ #ifdef HAVE_PPSAPI - if (up->pcount == 0) + if (up->pcount == 0) { peer->flags &= ~FLAG_PPS; + peer->precision = PRECISION; + } if (up->tcount == 0) { pp->coderecv = pp->codeproc; refclock_report(peer, CEVNT_TIMEOUT); diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index 97e341afa2..ac30fcbdc5 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -507,9 +507,11 @@ OnSerialWaitComplete(ULONG_PTR i, IoCompletionInfo *lpo, DWORD Bytes, int errsta static int OnSerialReadComplete(ULONG_PTR i, IoCompletionInfo *lpo, DWORD Bytes, int errstatus) { - recvbuf_t *buff; - struct refclockio * rio = (struct refclockio *) i; + recvbuf_t * buff; + l_fp cr_time; + struct refclockio * rio; + rio = (struct refclockio *)i; /* * Get the recvbuf pointer from the overlapped buffer. */ @@ -530,6 +532,24 @@ OnSerialReadComplete(ULONG_PTR i, IoCompletionInfo *lpo, DWORD Bytes, int errsta * have fired since the port was opened. */ if (rio->recvcount++) { + cr_time = buff->recv_time; + add_full_recv_buffer(buff); + /* + * Mimic Unix line discipline and assume CR/LF + * line termination. On Unix the CR terminates + * the line containing the timecode, and + * immediately after the LF terminates an empty + * line. So synthesize the empty LF-terminated + * line using the same CR timestamp. Both CR + * and LF are stripped by refclock_gtlin(). + */ + buff = get_free_recv_buffer_alloc(); + buff->recv_time = cr_time; + buff->recv_length = 0; + buff->fd = _get_osfhandle(rio->fd); + buff->receiver = rio->clock_recv; + buff->dstadr = NULL; + buff->recv_srcclock = rio->srcclock; add_full_recv_buffer(buff); /* * Now signal we have something to process