[LinuxPPS] [PATCH] time_pps_readlink()

Udo van den Heuvel udovdh at xs4all.nl
Fri Aug 25 20:03:51 CEST 2006


Rodolfo Giometti wrote:
> On Sun, Aug 13, 2006 at 02:54:43PM +0200, Udo van den Heuvel wrote:
>> Rodolfo Giometti wrote:
>>
>> [...[
>>
>>> to this code:

[...]

>>>    +#endif   /* PPS_HAVE_FINDPATH */
>> Where does PPS_DEVICE come from? (where is it declared, filled, etc?)
>> I could not locate that info in include/linux/timepps.h.
> 
> Mmm... that is just an example code, maybe it should be replaced with
> the "path" variable.

Although my hardware issue is not solved I made a patch for ntpd's
refclock_nmea.c that uses the new functions.
The code appears to compile. The results were not yet tested.
Please have a look at the patch and give feedback if necessary.
If the patch is OK, feel free to post it online.

Udo
-------------- 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
@@ -139,6 +139,9 @@
 	register struct nmeaunit *up;
 	struct refclockproc *pp;
 	int fd;
+#ifdef PPS_HAVE_FINDSOURCE
+	char id[40], path[40];
+#endif	/* PPS_HAVE_FINDSOURCE */
 	char device[20];
 
 	/*
@@ -230,8 +233,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, 40, path, 40);
+
+	/* Try to find the source */
+	fd = time_pps_findpath(path, 40, id, 40);
+	if (fd < 0) {
+		msyslog(LOG_ERR, "refclock: cannot find PPS source \"%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 +276,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 +387,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