diff -Naurp ntp-4.2.2p4.orig/ntpd/refclock_nmea.c ntp-4.2.2p4.mash/ntpd/refclock_nmea.c --- ntp-4.2.2p4.orig/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200 +++ ntp-4.2.2p4.mash/ntpd/refclock_nmea.c 2006-12-13 16:22:26.000000000 +0100 @@ -16,6 +16,7 @@ #include #include +#include #include "ntpd.h" #include "ntp_io.h" @@ -72,6 +72,7 @@ #define RANGEGATE 500000 /* range gate (ns) */ #define LENNMEA 75 /* min timecode length */ +#define LENPPS LINUXPPS_MAX_NAME_LEN /* * Tables to compute the ddd of year form icky dd/mm timecode. Viva la @@ -92,6 +93,7 @@ struct nmeaunit { pps_params_t pps_params; /* pps parameters */ pps_info_t pps_info; /* last pps data */ pps_handle_t handle; /* pps handlebars */ + int handle_created; /* pps handle created flag */ #endif /* HAVE_PPSAPI */ }; @@ -140,7 +142,12 @@ nmea_start( register struct nmeaunit *up; struct refclockproc *pp; int fd; +#ifdef PPS_HAVE_FINDPATH + char id[LENPPS] = "", + path[LENPPS]; +#endif /* PPS_HAVE_FINDPATH */ char device[20]; + uint bits, mask=~0, outb=0; /* * Open serial port. Use CLK line discipline, if available. @@ -225,18 +232,42 @@ nmea_start( memcpy((char *)&pp->refid, REFID, 4); up->pollcnt = 2; gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer); + gps_send(pp->io.fd,"$PGRMO,,2\r\n", peer); + gps_send(pp->io.fd,"$PGRMO,GPRMC,1\r\n", peer); + gps_send(pp->io.fd,"$PGRMO,,,,,,,,,,,,2\r\n", peer); + + mask &= ~TIOCM_RTS; + mask &= ~TIOCM_DTR; + outb |= TIOCM_RTS; + ioctl(fd, TIOCMGET, &bits); + bits &= mask; + bits |= outb; + ioctl(fd, TIOCMSET, &bits); #ifdef HAVE_PPSAPI /* * Start the PPSAPI interface if it is there. Default to use * the assert edge and do not enable the kernel hardpps. */ +#ifdef PPS_HAVE_FINDPATH + /* Get the PPS source's real name */ + time_pps_readlink(device, LENPPS, path, LENPPS); + + /* Try to find the source */ + fd = time_pps_findpath(path, LENPPS, id, LENPPS); + if (fd < 0) { + msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path); + return (0); + } + msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id); +#endif /* PPS_HAVE_FINDPATH */ if (time_pps_create(fd, &up->handle) < 0) { - up->handle = 0; + up->handle_created = 0; msyslog(LOG_ERR, "refclock_nmea: time_pps_create failed: %m"); return (1); } + up->handle_created = ~0; return(nmea_ppsapi(peer, 0, 0)); #else return (1); @@ -258,8 +289,10 @@ nmea_shutdown( pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr; #ifdef HAVE_PPSAPI - if (up->handle != 0) + if (up->handle_created) { time_pps_destroy(up->handle); + up->handle_created = 0; + } #endif /* HAVE_PPSAPI */ io_closeclock(&pp->io); free(up); @@ -367,7 +400,7 @@ nmea_pps( /* * Convert the timespec nanoseconds field to ntp l_fp units. */ - if (up->handle == 0) + if (!up->handle_created) return (0); timeout.tv_sec = 0; timeout.tv_nsec = 0;