[LinuxPPS] [PATCH] time_pps_readlink()

Rodolfo Giometti giometti at linux.it
Sat Aug 26 18:36:25 CEST 2006


On Fri, Aug 25, 2006 at 08:03:51PM +0200, Udo van den Heuvel wrote:
> --- 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];

I think is better using "LINUXPPS_MAX_NAME_LEN" define instead of "40"
(see "ppstest.c").

> +#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

If you decide to use the time_pps_findpath() function in any case then
you can use directly the "LINUXPSS_API" define. But what you wrote is
ok.

> +	/* Get the PPS source's real name */
> +	time_pps_readlink(link, 40, path, 40);

Where do you init the "link" variable? In "ppstest.c" I did:

        char id[STRING_LEN] = "",               /* no ID string by default   */
             path[STRING_LEN],
             link[STRING_LEN] = "/dev/gps0";    /* just a default device */

> +	/* 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;

Mmm... doing like this is correct but you are using the internal
rappresentation of "handle" variable. I think you should define
another variable to be used as open/close flag so you can significally
reduce the #ifdef lines since the new flag can be used for both
LinuxPPS and the current PPS API.

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