From: Dave Hart Date: Wed, 5 Oct 2011 07:49:15 +0000 (+0000) Subject: [Bug 1945] mbg_gps166.h use of _TM_DEFINED conflicts with MS VC. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fc5334435c53220bc6f5b95df1aeef6185f035f;p=thirdparty%2Fntp.git [Bug 1945] mbg_gps166.h use of _TM_DEFINED conflicts with MS VC. [Bug 1946] parse_start uses open; does not work on Windows. [Bug 1947] Porting parse-based Wharton refclock driver to Windows. bk: 4e8c0bfbfTydxEoJfkT8bJpMXfj9fQ --- diff --git a/ChangeLog b/ChangeLog index 6e1cd468e3..f38f91bbe5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* [Bug 1945] mbg_gps166.h use of _TM_DEFINED conflicts with MS VC. +* [Bug 1946] parse_start uses open; does not work on Windows. +* [Bug 1947] Porting parse-based Wharton refclock driver to Windows. * [Bug 2024] Remove unused system event code EVNT_CLKHOP. (4.2.7p219) 2011/10/04 Released by Harlan Stenn * Documentation updates from Dave Mills. diff --git a/include/mbg_gps166.h b/include/mbg_gps166.h index f4b8238108..974debafae 100644 --- a/include/mbg_gps166.h +++ b/include/mbg_gps166.h @@ -197,7 +197,7 @@ typedef struct { /* by the user. The status field can be checked to see which corrections */ /* have been applied. */ -#ifndef _TM_DEFINED +#ifndef GPS166_TM_DEFINED typedef struct { short year; /* 0..9999 */ char month; /* 1..12 */ @@ -221,7 +221,7 @@ typedef struct { # define TM_LS_ANN 0x10 /* leap second will be inserted */ # define TM_LS_ENB 0x20 /* current second is leap second */ -# define _TM_DEFINED +# define GPS166_TM_DEFINED #endif diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h index 976c6f3c65..1d7764e8d9 100644 --- a/include/ntp_refclock.h +++ b/include/ntp_refclock.h @@ -215,10 +215,13 @@ extern void refclock_timer (struct peer *); extern void refclock_transmit(struct peer *); extern int refclock_process(struct refclockproc *); extern int refclock_process_f(struct refclockproc *, double); -extern void refclock_process_offset(struct refclockproc *, l_fp, l_fp, double); +extern void refclock_process_offset(struct refclockproc *, l_fp, + l_fp, double); extern void refclock_report (struct peer *, int); extern int refclock_gtlin (struct recvbuf *, char *, int, l_fp *); extern int refclock_gtraw (struct recvbuf *, char *, int, l_fp *); +extern int indicate_refclock_packet(struct refclockio *, + struct recvbuf *); #endif /* REFCLOCK */ #endif /* NTP_REFCLOCK_H */ diff --git a/libparse/clk_wharton.c b/libparse/clk_wharton.c index 0a1ee0b03a..55ab43a9b5 100644 --- a/libparse/clk_wharton.c +++ b/libparse/clk_wharton.c @@ -91,7 +91,7 @@ cvt_wharton_400a( int i; /* The given `size' includes a terminating null-character. */ - if (size != 16 || buffer[0] != STX || buffer[14] != ETX + if (size != 15 || buffer[0] != STX || buffer[14] != ETX || buffer[13] < '0' || buffer[13] > ('0' + 0xf)) return CVT_NONE; for (i = 1; i < 13; i += 1) diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index b2c94dd177..ce9492d891 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -3084,12 +3084,17 @@ fdbits( * read it again or go on to the next one if no bytes returned */ static inline int -read_refclock_packet(SOCKET fd, struct refclockio *rp, l_fp ts) +read_refclock_packet( + SOCKET fd, + struct refclockio * rp, + l_fp ts + ) { - int i; - int buflen; - int saved_errno; - struct recvbuf *rb; + int i; + int buflen; + int saved_errno; + int consumed; + struct recvbuf * rb; rb = get_free_recv_buffer(); @@ -3130,25 +3135,13 @@ read_refclock_packet(SOCKET fd, struct refclockio *rp, l_fp ts) rb->recv_time = ts; rb->receiver = rp->clock_recv; - if (rp->io_input) { - /* - * have direct input routine for refclocks - */ - if (rp->io_input(rb) == 0) { - /* - * data was consumed - nothing to pass up - * into block input machine - */ - freerecvbuf(rb); - return (buflen); - } + consumed = indicate_refclock_packet(rp, rb); + if (!consumed) { + rp->recvcount++; + packets_received++; } - - add_full_recv_buffer(rb); - rp->recvcount++; - packets_received++; - return (buflen); + return buflen; } diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index 642e5d46de..d5a36973c0 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -646,6 +646,39 @@ refclock_gtraw( } +/* + * indicate_refclock_packet() + * + * Passes a fragment of refclock input read from the device to the + * driver direct input routine, which may consume it (batch it for + * queuing once a logical unit is assembled). If it is not so + * consumed, queue it for the driver's receive entrypoint. + * + * The return value is TRUE if the data has been consumed as a fragment + * and should not be counted as a received packet. + */ +int +indicate_refclock_packet( + struct refclockio * rio, + struct recvbuf * rb + ) +{ + /* Does this refclock use direct input routine? */ + if (rio->io_input != NULL && (*rio->io_input)(rb) == 0) { + /* + * data was consumed - nothing to pass up + * into block input machine + */ + freerecvbuf(rb); + + return TRUE; + } + add_full_recv_buffer(rb); + + return FALSE; +} + + /* * The following code does not apply to WINNT & VMS ... */ diff --git a/ntpd/refclock_parse.c b/ntpd/refclock_parse.c index 0d8e5f33e5..71ef527256 100644 --- a/ntpd/refclock_parse.c +++ b/ntpd/refclock_parse.c @@ -120,6 +120,7 @@ #endif #ifdef HAVE_TERMIOS +# include # define TTY_GETATTR(_FD_, _ARG_) tcgetattr((_FD_), (_ARG_)) # define TTY_SETATTR(_FD_, _ARG_) tcsetattr((_FD_), TCSANOW, (_ARG_)) # undef HAVE_SYSV_TTYS @@ -2312,11 +2313,15 @@ local_input( sizeof(parsetime_t)); buf->recv_length = sizeof(parsetime_t); buf->recv_time = rbufp->recv_time; +#ifndef HAVE_IO_COMPLETION_PORT buf->srcadr = rbufp->srcadr; +#endif buf->dstadr = rbufp->dstadr; buf->receiver = rbufp->receiver; buf->fd = rbufp->fd; buf->X_from_where = rbufp->X_from_where; + parse->generic->io.recvcount++; + packets_received++; add_full_recv_buffer(buf); } parse_iodone(&parse->parseio); @@ -2721,7 +2726,7 @@ parse_shutdown( } #endif if (parse->generic->io.fd != parse->ppsfd && parse->ppsfd != -1) - (void)close(parse->ppsfd); /* close separate PPS source */ + (void)closeserial(parse->ppsfd); /* close separate PPS source */ /* * print statistics a last time and @@ -2933,11 +2938,11 @@ parse_start( #define O_NOCTTY 0 #endif - fd232 = open(parsedev, O_RDWR | O_NOCTTY + fd232 = tty_open(parsedev, O_RDWR | O_NOCTTY #ifdef O_NONBLOCK - | O_NONBLOCK + | O_NONBLOCK #endif - , 0777); + , 0777); if (fd232 == -1) { @@ -2945,9 +2950,7 @@ parse_start( return 0; } - parse = (struct parseunit *)emalloc(sizeof(struct parseunit)); - - memset((char *)parse, 0, sizeof(struct parseunit)); + parse = emalloc_zero(sizeof(*parse)); parse->generic = peer->procptr; /* link up */ parse->generic->unitptr = (caddr_t)parse; /* link down */ @@ -3061,11 +3064,11 @@ parse_start( * if the PARSEPPSDEVICE can be opened that will be used * for PPS else PARSEDEVICE will be used */ - parse->ppsfd = open(parseppsdev, O_RDWR | O_NOCTTY + parse->ppsfd = tty_open(parseppsdev, O_RDWR | O_NOCTTY #ifdef O_NONBLOCK - | O_NONBLOCK + | O_NONBLOCK #endif - , 0777); + , 0777); if (parse->ppsfd == -1) { diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index 5733c98711..e1a84c034b 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -331,10 +331,23 @@ typedef int ssize_t; /* ssize is an int */ #define CLOCK_NMEA #define CLOCK_ONCORE #define CLOCK_PALISADE /* from ntpd.mak */ +#define CLOCK_PARSE +/* parse component drivers */ +#define CLOCK_COMPUTIME +#define CLOCK_DCF7000 +#define CLOCK_HOPF6021 +#define CLOCK_MEINBERG +#define CLOCK_RAWDCF +#define CLOCK_RCC8000 +#define CLOCK_SCHMID +#define CLOCK_TRIMTAIP +#define CLOCK_TRIMTSIP +#define CLOCK_VARITEXT +#define CLOCK_WHARTON_400A +/* end parse component drivers */ /* # define CLOCK_SHM */ #define CLOCK_SPECTRACOM /* refclock_wwvb.c */ #define CLOCK_TRIMBLEDC -#define CLOCK_TRIMTSIP 1 #define CLOCK_TRUETIME #define NTP_LITTLE_ENDIAN /* from libntp.mak */ diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index 125b719198..eb1c7e4408 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -569,6 +569,7 @@ OnSerialReadComplete( { recvbuf_t * buff; l_fp cr_time; + int consumed; if (!rio->active) return FALSE; @@ -586,14 +587,12 @@ OnSerialReadComplete( buff->receiver = rio->clock_recv; buff->dstadr = NULL; buff->recv_peer = rio->srcclock; - packets_received++; - handler_pkts++; /* * Eat the first line of input as it's possibly * partial and if a PPS is present, it may not * have fired since the port was opened. */ - if (rio->recvcount++) { + if (rio->recvcount++ > 0) { cr_time = buff->recv_time; buff->fd = rio->fd; /* was handle */ add_full_recv_buffer(buff); @@ -613,11 +612,12 @@ OnSerialReadComplete( buff->receiver = rio->clock_recv; buff->dstadr = NULL; buff->recv_peer = rio->srcclock; - add_full_recv_buffer(buff); - /* - * Now signal we have something to process - */ - SetEvent(WaitableIoEventHandle); + consumed = indicate_refclock_packet(rio, buff); + if (!consumed) { + packets_received++; + handler_pkts++; + SetEvent(WaitableIoEventHandle); + } buff = get_free_recv_buffer_alloc(); } } @@ -665,6 +665,7 @@ OnRawSerialReadComplete( { recvbuf_t * rbufp; l_fp arrival_time; + int consumed; get_systime(&arrival_time); @@ -681,13 +682,14 @@ OnRawSerialReadComplete( rbufp->receiver = rio->clock_recv; rbufp->recv_peer = rio->srcclock; rbufp->fd = rio->fd; /* was handle */ - packets_received++; - handler_pkts++; - add_full_recv_buffer(rbufp); - /* - * Now signal we have something to process - */ - SetEvent(WaitableIoEventHandle); + + consumed = indicate_refclock_packet(rio, rbufp); + if (!consumed) { + rio->recvcount++; + packets_received++; + handler_pkts++; + SetEvent(WaitableIoEventHandle); + } rbufp = get_free_recv_buffer_alloc(); } diff --git a/ports/winnt/vs2005/ntpd.vcproj b/ports/winnt/vs2005/ntpd.vcproj index 8e3d6666e4..fee9af8ebf 100644 --- a/ports/winnt/vs2005/ntpd.vcproj +++ b/ports/winnt/vs2005/ntpd.vcproj @@ -1797,290 +1797,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -