[LinuxPPS] Re: [Bug 610] Generic NMEA GPS Receiver driver w/ PPS expects PPS after NMEA data

Rodolfo Giometti giometti at enneenne.com
Mon Oct 29 10:52:39 CET 2007


On Sun, Oct 28, 2007 at 01:32:29PM +0100, Udo van den Heuvel wrote:
> 
> # ls -al /dev/*pps*
> lrwxrwxrwx 1 root root      9 2007-10-28 13:24 /dev/gpspps0 -> /dev/pps0
> crw------- 1 root root 254, 0 2007-10-23 19:30 /dev/pps0

Consider that also udev con build such symbolic link...

> --- /usr/src/redhat/ntp-4.2.4p2/ntpd/refclock_nmea.c	2006-06-06 22:16:53.000000000 +0200
> +++ refclock_nmea.c	2007-10-28 11:00:37.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 */

Ok.

>  #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,16 +232,35 @@
>  	 * 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);
> +        (void) sprintf(device, DEVICEPPS, unit);
> +        fd = open(device, O_RDWR);
> +        if (fd < 0) { /* no /dev/gpspps0 */
> +		/* Try the /dev/gps device for PPS */
> +                (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)
> +               		goto pps_error;
> +	} else {  /* /dev/gpspps0 exists */
> +		msyslog(LOG_ERR, "refclock_nmea: try \"%s\" for PPS", device);
> +		if (time_pps_create(fd, &up->handle) < 0) { 
> +			/* no PPS on /dev/gpspps0 */
> +			if (time_pps_create(pp->io.fd, &up->handle) < 0)
> +       				goto pps_error; /* no PPS on /dev/gps0 */
> +			else (void) sprintf(device, DEVICE, unit);
> +		}
>  	}
> +	msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\"", device);
>  	return(nmea_ppsapi(peer, 0, 0));

I'm not completely agree with your solution... you can recognize a PPS
source by using both open() and time_pps_create().

In your solution if the alternate device is a valid char device but
not a PPS source you return error without trying the main
device. Instead, NTPD folks asked to you to check first the alternate
device for a PPS source and then fall back to the main device.

In this situation you should do something like:

	a_fd = open(ALTERNATE);
	if (a_fd < 0)
		goto try_main_device;
	
	ret = time_pps_create(a_fd, &handle);
	if (ret < 0)
		goto try_main_device;

	...

	return	0;

try_main_device:

	ret = time_pps_create(fd, &handle);
	if (ret	< 0)
		goto pps_error;

	...

	return 0;

pps_error:
	MANAGE_PPS_ERROR

	return -1;


Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti at enneenne.com
Linux Device Driver                             giometti at gnudd.com
Embedded Systems                     		giometti at linux.it
UNIX programming                     phone:     +39 349 2432127



More information about the LinuxPPS mailing list