1 --- a/ntpd/refclock_nmea.c
2 +++ b/ntpd/refclock_nmea.c
7 +#include <sys/ioctl.h>
11 @@ -72,6 +73,7 @@ extern int async_write(int, const void *
12 #define RANGEGATE 500000 /* range gate (ns) */
14 #define LENNMEA 75 /* min timecode length */
15 +#define LENPPS LINUXPPS_MAX_NAME_LEN
18 * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
19 @@ -92,6 +94,7 @@ struct nmeaunit {
20 pps_params_t pps_params; /* pps parameters */
21 pps_info_t pps_info; /* last pps data */
22 pps_handle_t handle; /* pps handlebars */
23 + int handle_created; /* pps handle created flag */
24 #endif /* HAVE_PPSAPI */
27 @@ -140,7 +143,12 @@ nmea_start(
28 register struct nmeaunit *up;
29 struct refclockproc *pp;
31 +#ifdef PPS_HAVE_FINDPATH
32 + char id[LENPPS] = "",
34 +#endif /* PPS_HAVE_FINDPATH */
36 + uint bits, mask=~0, outb=0;
39 * Open serial port. Use CLK line discipline, if available.
40 @@ -225,18 +233,42 @@ nmea_start(
41 memcpy((char *)&pp->refid, REFID, 4);
43 gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer);
44 + gps_send(pp->io.fd,"$PGRMO,,2\r\n", peer);
45 + gps_send(pp->io.fd,"$PGRMO,GPRMC,1\r\n", peer);
46 + gps_send(pp->io.fd,"$PGRMO,,,,,,,,,,,,2\r\n", peer);
51 + ioctl(fd, TIOCMGET, &bits);
54 + ioctl(fd, TIOCMSET, &bits);
58 * Start the PPSAPI interface if it is there. Default to use
59 * the assert edge and do not enable the kernel hardpps.
61 +#ifdef PPS_HAVE_FINDPATH
62 + /* Get the PPS source's real name */
63 + time_pps_readlink(device, LENPPS, path, LENPPS);
65 + /* Try to find the source */
66 + fd = time_pps_findpath(path, LENPPS, id, LENPPS);
68 + msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path);
71 + msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
72 +#endif /* PPS_HAVE_FINDPATH */
73 if (time_pps_create(fd, &up->handle) < 0) {
75 + up->handle_created = 0;
77 "refclock_nmea: time_pps_create failed: %m");
80 + up->handle_created = ~0;
81 return(nmea_ppsapi(peer, 0, 0));
84 @@ -258,8 +290,10 @@ nmea_shutdown(
86 up = (struct nmeaunit *)pp->unitptr;
88 - if (up->handle != 0)
89 + if (up->handle_created) {
90 time_pps_destroy(up->handle);
91 + up->handle_created = 0;
93 #endif /* HAVE_PPSAPI */
94 io_closeclock(&pp->io);
96 @@ -367,7 +401,7 @@ nmea_pps(
98 * Convert the timespec nanoseconds field to ntp l_fp units.
100 - if (up->handle == 0)
101 + if (!up->handle_created)