[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gpsd-dev
Subject:    Re: [Gpsd-dev] [PATCH 1/2] Move chrony SOCK sending to a new
From:       "Gary E. Miller" <gem () rellim ! com>
Date:       2011-04-14 17:43:11
Message-ID: alpine.LNX.1.00.1104141041370.26427 () catbert ! rellim ! com
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yo Miroslav!

I would rather not fork the PPS code.  We end up with two essentially
identical functions.  When the new ntpd SHM code is out the ntpd SHM
interface will look even more like the Chrony Sock interface.

RGDS
GARY
- ---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97701
	gem@rellim.com  Tel:+1(541)382-8588

On Thu, 14 Apr 2011, Miroslav Lichvar wrote:

> Date: Thu, 14 Apr 2011 16:27:16 +0200
> From: Miroslav Lichvar <mlichvar@redhat.com>
> Subject: [PATCH 1/2] Move chrony SOCK sending to a new function
> 
> ---
> ntpshm.c |   68 ++++++++++++++++++++++++++++++++++---------------------------
> 1 files changed, 38 insertions(+), 30 deletions(-)
> 
> diff --git a/ntpshm.c b/ntpshm.c
> index 76697c2..46cadd1 100644
> --- a/ntpshm.c
> +++ b/ntpshm.c
> @@ -417,6 +417,40 @@ static int ntpshm_pps(struct gps_device_t *session, struct \
> timeval *tv) TS_NORM( ts ); \
> } while (0)
> 
> +
> +static int chronysock_pps(struct gps_device_t *session, struct timespec *ts, int \
> fd) +{
> +/* for chrony SOCK interface, which allows nSec timekeeping */
> +#define SOCK_MAGIC 0x534f434b
> +    struct sock_sample {
> +	struct timeval tv;
> +	double offset;
> +	int pulse;
> +	int leap;
> +	int _pad;	/* unused */
> +	int magic;	/* must be SOCK_MAGIC */
> +    } sample;
> +
> +    /* chrony expects tv-sec since Jan 1970 */
> +    /* FIXME!! offset is double of the error from local time */
> +    sample.pulse = 0;
> +    sample.leap = 0;
> +    sample.magic = SOCK_MAGIC;
> +    TSTOTV(&sample.tv, ts);
> +
> +    /* FIXME!! this is wrong if signal is 5Hz or 10Hz instead of PPS */
> +    /* carefull, unix time to nSec is more precision that a double */
> +    sample.offset = 1 + session->last_fixtime - ts->tv_sec;
> +    sample.offset -= ts->tv_nsec / 1e9;
> +    (void)send(fd, &sample, sizeof (sample), 0);
> +    gpsd_report(LOG_RAW, "PPS chrony sock %lu.%06lu offset %.9f\n",
> +	    (unsigned long)sample.tv.tv_sec,
> +	    (unsigned long)sample.tv.tv_usec,
> +	    sample.offset);
> +
> +    return 1;
> +}
> +
> #endif
> 
> #if defined(PPS_ENABLE) && defined(TIOCMIWAIT)
> @@ -543,16 +577,6 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg)
> struct timespec tv_kpps;
> pps_info_t pi;
> #endif
> -/* for chrony SOCK interface, which allows nSec timekeeping */
> -#define SOCK_MAGIC 0x534f434b
> -    struct sock_sample {
> -	struct timeval tv;
> -	double offset;
> -	int pulse;
> -	int leap;
> -	int _pad;	/* unused */
> -	int magic;      /* must be SOCK_MAGIC */
> -    } sample;
> /* chrony must be started first as chrony insists on creating the socket */
> /* open the chrony socket */
> struct sockaddr_un s;
> @@ -821,11 +845,6 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg)
> 	    gpsd_report(LOG_RAW, "%.100s", log);
> 	}
> 	if (0 != ok) {
> -	    /* chrony expects tv-sec since Jan 1970 */
> -	    /* FIXME!! offset is double of the error from local time */
> -	    sample.pulse = 0;
> -	    sample.leap = 0;
> -	    sample.magic = SOCK_MAGIC;
> #if defined(HAVE_SYS_TIMEPPS_H)
> if ( 0 <= kernelpps_handle ) {
> 		/* pick the right edge */
> @@ -834,16 +853,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg)
> 		} else {
> 		    ts = pi.clear_timestamp;  /* structure copy */
> 		}
> -		TSTOTV( &sample.tv, &ts);
> -	    } else
> +		TSTOTV( &tv, &ts);
> +	    }
> #endif
> -	    {
> -		sample.tv = tv; 	/* structure copy */
> -	    }
> -	    /* FIXME!! this is wrong if signal is 5Hz or 10Hz instead of PPS */
> -	    /* carefull, unix time to nSec is more precision that a double */
> -	    sample.offset = 1 + session->last_fixtime - ts.tv_sec;
> -	    sample.offset -= ts.tv_nsec / 1e9;
> /* was: defined(ONCORE_ENABLE) && defined(BINARY_ENABLE) */
> #ifdef __UNUSED__
> 	    /*@-noeffect@*/
> @@ -857,13 +869,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg)
> #endif
> 
> 	    if ( 0 <= chronyfd ) {
> -		(void)send(chronyfd, &sample, sizeof (sample), 0);
> -		gpsd_report(LOG_RAW, "PPS chrony sock %lu.%06lu offset %.9f\n",
> -			    (unsigned long)sample.tv.tv_sec,
> -			    (unsigned long)sample.tv.tv_usec,
> -			    sample.offset);
> +		(void)chronysock_pps(session, &ts, chronyfd);
> 	    }
> -	    TSTOTV( &tv, &ts );
> +
> 	    (void)ntpshm_pps(session, &tv);
> 	} else {
> 	    gpsd_report(LOG_INF, "PPS edge rejected\n");
> --
> 1.7.4
> 
> 
> --LQksG6bCIzRHxTLp
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: attachment; \
> filename="0002-Calculate-SOCK-offset-from-SHM-clock-timestamp-inste.patch" 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFNpzI0BmnRqz71OvMRAhgCAJ9upY6rZI+Ax/IDi73qoVlGsa/HcQCg1rbK
j/wDfzXyVHr8lSdHZ+w6qgE=
=3a75
-----END PGP SIGNATURE-----

_______________________________________________
Gpsd-dev mailing list
Gpsd-dev@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/gpsd-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic