1 diff -Naurp ntp-4.2.2p4.orig/ntpd/refclock_nmea.c ntp-4.2.2p4.mash/ntpd/refclock_nmea.c
2 --- ntp-4.2.2p4.orig/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200
3 +++ ntp-4.2.2p4.mash/ntpd/refclock_nmea.c 2006-12-13 16:22:26.000000000 +0100
8 +#include <sys/ioctl.h>
13 #define RANGEGATE 500000 /* range gate (ns) */
15 #define LENNMEA 75 /* min timecode length */
16 +#define LENPPS LINUXPPS_MAX_NAME_LEN
19 * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
20 @@ -92,6 +93,7 @@ struct nmeaunit {
21 pps_params_t pps_params; /* pps parameters */
22 pps_info_t pps_info; /* last pps data */
23 pps_handle_t handle; /* pps handlebars */
24 + int handle_created; /* pps handle created flag */
25 #endif /* HAVE_PPSAPI */
28 @@ -140,7 +142,12 @@ nmea_start(
29 register struct nmeaunit *up;
30 struct refclockproc *pp;
32 +#ifdef PPS_HAVE_FINDPATH
33 + char id[LENPPS] = "",
35 +#endif /* PPS_HAVE_FINDPATH */
37 + uint bits, mask=~0, outb=0;
40 * Open serial port. Use CLK line discipline, if available.
41 @@ -225,18 +232,42 @@ nmea_start(
42 memcpy((char *)&pp->refid, REFID, 4);
44 gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer);
45 + gps_send(pp->io.fd,"$PGRMO,,2\r\n", peer);
46 + gps_send(pp->io.fd,"$PGRMO,GPRMC,1\r\n", peer);
47 + gps_send(pp->io.fd,"$PGRMO,,,,,,,,,,,,2\r\n", peer);
52 + ioctl(fd, TIOCMGET, &bits);
55 + ioctl(fd, TIOCMSET, &bits);
59 * Start the PPSAPI interface if it is there. Default to use
60 * the assert edge and do not enable the kernel hardpps.
62 +#ifdef PPS_HAVE_FINDPATH
63 + /* Get the PPS source's real name */
64 + time_pps_readlink(device, LENPPS, path, LENPPS);
66 + /* Try to find the source */
67 + fd = time_pps_findpath(path, LENPPS, id, LENPPS);
69 + msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path);
72 + msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
73 +#endif /* PPS_HAVE_FINDPATH */
74 if (time_pps_create(fd, &up->handle) < 0) {
76 + up->handle_created = 0;
78 "refclock_nmea: time_pps_create failed: %m");
81 + up->handle_created = ~0;
82 return(nmea_ppsapi(peer, 0, 0));
85 @@ -258,8 +289,10 @@ nmea_shutdown(
87 up = (struct nmeaunit *)pp->unitptr;
89 - if (up->handle != 0)
90 + if (up->handle_created) {
91 time_pps_destroy(up->handle);
92 + up->handle_created = 0;
94 #endif /* HAVE_PPSAPI */
95 io_closeclock(&pp->io);
97 @@ -367,7 +400,7 @@ nmea_pps(
99 * Convert the timespec nanoseconds field to ntp l_fp units.
101 - if (up->handle == 0)
102 + if (!up->handle_created)