[LinuxPPS] refclock_nmea patch

Udo van den Heuvel udovdh at xs4all.nl
Sun Oct 21 11:18:40 CEST 2007


Udo van den Heuvel wrote:
> Udo van den Heuvel wrote:
>> I changed the code to refclock_nmea.c (from ntp-4.2.4p2) as hinted by
>> Rodolfo some time ago. I used the old reflock_nmea patch as a basis.
> 
> I left too much of the old patch in I just noticed.
> How much of the 'old' initialisation is needed in the new situation?

Please forget the previous patch.
I reworked stuff a bit.
See the attached result which also open for comments.
-------------- next part --------------
--- refclock_nmea.c.origineel	2007-10-21 10:49:00.000000000 +0200
+++ refclock_nmea.c	2007-10-21 11:12:55.000000000 +0200
@@ -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/pps%d" /* name of PPS radio device */
 #endif
 #define	SPEED232	B4800	/* uart speed (4800 bps) */
 #define	PRECISION	(-9)	/* precision assumed (about 2 ms) */
@@ -238,27 +239,33 @@
 	 * 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);
+	if (time_pps_create(fd, &up->handle) < 0) {
 
-	/* 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);
+		/* Try the alternare PPS device */
+		msyslog(LOG_ERR, "refclock_nmea: try alternate PPS device");
+                (void) sprintf(device, DEVICEPPS, unit);
+                fd = open(device, O_RDWR);
+                if (fd < 0)
+                	goto pps_error;
+                  
+		if (time_pps_create(fd, &up->handle) < 0)
+               		goto pps_error;
 	}
 	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_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);
+#endif /* PPS_HAVE_FINDPATH */
+
+pps_error:
+	/* No luck, no PPS unit available! */
+	up->handle = 0;
+	up->handle_created = 0;
+	msyslog(LOG_ERR, "refclock_nmea: alternate PPS device %s fail : %m", device);
+	return (1);
+#else
+	return (1);
 #endif /* HAVE_PPSAPI */
 }
 


More information about the LinuxPPS mailing list