[LinuxPPS] [PATCH] time_pps_readlink()

Udo van den Heuvel udovdh at xs4all.nl
Sun Aug 27 09:26:34 CEST 2006


The new NMEA patch appears to work OK.
I attached a small update to the patch which reduces the need for
LINUXPPS_MAX_NAME_LEN a bit. Please feel free to post the patch online.


If someone can explain Rodolfo's idea to make the patch even smaller,
please post!
-------------- next part --------------
--- a/ntpd/refclock_nmea.c      2006-05-22 16:39:06.000000000 +0200
+++ b/ntpd/refclock_nmea.c      2006-05-22 16:39:54.000000000 +0200
@@ -71,6 +71,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
@@ -139,6 +140,11 @@
 	register struct nmeaunit *up;
 	struct refclockproc *pp;
 	int fd;
+#ifdef PPS_HAVE_FINDPATH
+	char id[LENPPS] = "",
+	     path[LENPPS],
+             link[LENPPS] = "/dev/gps0";    /* just a default device */
+#endif	/* PPS_HAVE_FINDPATH */
 	char device[20];
 
 	/*
@@ -230,8 +236,24 @@
 	 * 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(link, LENPPS, path, LENPPS);
+
+	/* Try to find the source */
+	fd = time_pps_findpath(path, LENPPS, id, LENPPS);
+	if (fd < 0) {
+		msyslog(LOG_ERR, "refclock: cannot find PPS path \"%s\" in the system", path);
+		return 1;
+	}
+	msyslog(LOG_INFO, "refclock: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
+#endif	/* PPS_HAVE_FINDPATH */
 	if (time_pps_create(fd, &up->handle) < 0) {
+#ifdef PPS_HAVE_FINDPATH
+		up->handle.socket = -1;
+#else
 		up->handle = 0;
+#endif	/* PPS_HAVE_FINDPATH */
 		msyslog(LOG_ERR,
 		    "refclock_nmea: time_pps_create failed: %m");
 		return (1);
@@ -257,7 +279,9 @@
 	pp = peer->procptr;
 	up = (struct nmeaunit *)pp->unitptr;
 #ifdef HAVE_PPSAPI
+#ifndef PPS_HAVE_FINDPATH
 	if (up->handle != 0)
+#endif /* PPS_HAVE_FINDPATH */
 		time_pps_destroy(up->handle);
 #endif /* HAVE_PPSAPI */
 	io_closeclock(&pp->io);
@@ -366,7 +390,11 @@
 	/*
 	 * Convert the timespec nanoseconds field to ntp l_fp units.
 	 */ 
+#ifdef PPS_HAVE_FINDPATH
+	if (up->handle.socket == -1)
+#else
 	if (up->handle == 0)
+#endif	/* PPS_HAVE_FINDPATH */
 		return (0);
 	timeout.tv_sec = 0;
 	timeout.tv_nsec = 0;


More information about the LinuxPPS mailing list