[LinuxPPS] another refclock_nmea patch ([Bug 610] Generic NMEA GPS
Receiver driver w/ PPS expects PPS after NMEA data)
Udo van den Heuvel
udovdh at xs4all.nl
Sat Nov 3 15:09:10 CET 2007
Hello,
I got this feedback from Frank:
I looked at the path and wonder if the leap frogging goto's could be
avoided.
Maybe a structure like:
set ppshandle invalid
open(PPSDEVICE
if (ok) {
if (create..(ppsfd...) == ok) {
log success for PPS device
} else {
close device
}
}
if (handle (still) invalid) {
if (create..(main device == ok) {
log success for main device
} else {
log failure for PPS support
}
}
I think this is easier to follow than leapfrogging gotos.
So I changed the code once more. See the attachment. Does it look OK?
Udo
-------------- next part --------------
--- org.ntp-4.2.4p2/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200
+++ ntp-4.2.4p2/ntpd/refclock_nmea.c 2007-11-03 15:06:04.000000000 +0100
@@ -61,6 +61,7 @@
# define DEVICE "COM%d:" /* COM 1 - 3 supported */
#else
# define DEVICE "/dev/gps%d" /* name of radio device */
+# define DEVICEPPS "/dev/gpspps%d" /* name of alternate PPS radio device */
#endif
#define SPEED232 B4800 /* uart speed (4800 bps) */
#define PRECISION (-9) /* precision assumed (about 2 ms) */
@@ -71,6 +72,7 @@
#define RANGEGATE 500000 /* range gate (ns) */
#define LENNMEA 75 /* min timecode length */
+#define LENPPS PPS_MAX_NAME_LEN
/*
* Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -230,13 +232,33 @@
* Start the PPSAPI interface if it is there. Default to use
* the assert edge and do not enable the kernel hardpps.
*/
- if (time_pps_create(fd, &up->handle) < 0) {
- up->handle = 0;
- msyslog(LOG_ERR,
- "refclock_nmea: time_pps_create failed: %m");
- return (1);
+ msyslog(LOG_ERR, "refclock_nmea: found GPS source \"%s\"", device);
+ fd = -1;
+ (void) sprintf(device, DEVICEPPS, unit);
+ fd = open(device, O_RDWR);
+ if (fd > 0) { /* /dev/gpspps0 exists */
+ msyslog(LOG_ERR, "refclock_nmea: try \"%s\" for PPS", device);
+ if (time_pps_create(fd, &up->handle) == 0) {
+ msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\"", device);
+ return(nmea_ppsapi(peer, 0, 0));
+ }
+ else close(fd);
}
- return(nmea_ppsapi(peer, 0, 0));
+
+ if (fd < 0) {
+ (void) sprintf(device, DEVICE, unit);
+ msyslog(LOG_ERR, "refclock_nmea: try GPS device \"%s\" for PPS", device);
+ if (time_pps_create(pp->io.fd, &up->handle) == 0) {
+ msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\"", device);
+ return(nmea_ppsapi(peer, 0, 0));
+ }
+ }
+
+ /* No luck, no PPS unit available! */
+ up->handle = -1;
+ msyslog(LOG_ERR, "refclock_nmea: no PPS devices found at " DEVICE " nor "
+ DEVICEPPS ": %m", unit, unit);
+ return (1);
#else
return (1);
#endif /* HAVE_PPSAPI */
@@ -257,8 +279,7 @@
pp = peer->procptr;
up = (struct nmeaunit *)pp->unitptr;
#ifdef HAVE_PPSAPI
- if (up->handle != 0)
- time_pps_destroy(up->handle);
+ time_pps_destroy(up->handle);
#endif /* HAVE_PPSAPI */
io_closeclock(&pp->io);
free(up);
@@ -366,7 +387,7 @@
/*
* Convert the timespec nanoseconds field to ntp l_fp units.
*/
- if (up->handle == 0)
+ if (up->handle == -1)
return (0);
timeout.tv_sec = 0;
timeout.tv_nsec = 0;
More information about the LinuxPPS
mailing list