]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1341] NMEA driver requires working PPSAPI #ifdef HAVE_PPSAPI.
authorDave Hart <hart@ntp.org>
Tue, 13 Oct 2009 23:48:18 +0000 (23:48 +0000)
committerDave Hart <hart@ntp.org>
Tue, 13 Oct 2009 23:48:18 +0000 (23:48 +0000)
bk: 4ad511c2FqDKesHHQNNefwgURU-qCw

ChangeLog
libntp/refnumtoa.c
ntpd/ntp_control.c
ntpd/refclock_nmea.c

index f86a5be54bb2b40e1c8ba9fd3ac529a378df0b51..4513b2ac2b56074d932785b5471d355826a47f6e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 1341] NMEA driver requires working PPSAPI #ifdef HAVE_PPSAPI.
 (4.2.5p231-RC) 2009/10/10 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1335] Broadcast client degraded by wildcard default change.
 (4.2.5p230-RC) 2009/10/09 Released by Harlan Stenn <stenn@ntp.org>
index 106d0b841dccd154e7c5c1236a8df47fb697cc09..c52bc28b6389cdbb595a490c7a9325502e5a5bfd 100644 (file)
@@ -18,7 +18,7 @@ refnumtoa(
 
        LIB_GETBUF(buf);
 
-       if (IS_IPV4(num)) {
+       if (ISREFCLOCKADR(num)) {
                netnum = SRCADR(num);
                rclock = clockname((int)((u_long)netnum >> 8) & 0xff);
 
@@ -30,10 +30,7 @@ refnumtoa(
                                 ((u_long)netnum >> 8) & 0xff,
                                 (u_long)netnum & 0xff);
 
-       } else
-               strncpy(buf,
-                       "refclock address type not implemented, use IPv4 refclock address.",
-                       LIB_BUFLENGTH);
+       }
 
        return buf;
 }
index 2a74c2939aadcff63b95a3d85831db424289c8e9..8d2f3919f7bb4e0294d36a08b2b8fac3be239e81 100644 (file)
@@ -2950,12 +2950,11 @@ report_event(
 
                peer->last_event = errlast;
                peer->num_events++;
-#ifdef REFCLOCK
                if (ISREFCLOCKADR(&peer->srcadr))
                        src = refnumtoa(&peer->srcadr);
                else
-#endif
                        src = stoa(&peer->srcadr);
+
                snprintf(statstr, NTP_MAXSTRLEN,
                    "%s %04x %02x %s", src,
                    ctlpeerstatus(peer), err, eventstr(err));
index f3c23fcb11380f72d87e769635d646615379fb8c..e9645942f9342ea3158f3e0278b46f4812f25b0f 100644 (file)
@@ -104,6 +104,8 @@ extern int async_write(int, const void *, unsigned int);
 struct nmeaunit {
 #ifdef HAVE_PPSAPI
        struct refclock_atom atom; /* PPSAPI structure */
+       int     ppsapi_tried;   /* attempt PPSAPI once */
+       int     ppsapi_lit;     /* time_pps_create() worked */
        int     tcount;         /* timecode sample counter */
        int     pcount;         /* PPS sample counter */
 #endif /* HAVE_PPSAPI */
@@ -119,7 +121,14 @@ static     void    nmea_shutdown   (int, struct peer *);
 static void    nmea_receive    (struct recvbuf *);
 static void    nmea_poll       (int, struct peer *);
 #ifdef HAVE_PPSAPI
+static void    nmea_control    (int, struct refclockstat *,
+                                struct refclockstat *, struct peer *);
 static  void   nmea_timer      (int, struct peer *);
+#define                NMEA_CONTROL    nmea_control
+#define                NMEA_TIMER      nmea_timer
+#else
+#define                NMEA_CONTROL    noentry
+#define                NMEA_TIMER      noentry
 #endif /* HAVE_PPSAPI */
 static void    gps_send        (int, const char *, struct peer *);
 static char *  field_parse     (char *, int);
@@ -132,14 +141,10 @@ struct    refclock refclock_nmea = {
        nmea_start,             /* start up driver */
        nmea_shutdown,          /* shut down driver */
        nmea_poll,              /* transmit poll message */
-       noentry,                /* fudge control */
+       NMEA_CONTROL,           /* fudge control */
        noentry,                /* initialize driver */
        noentry,                /* buginfo */
-#ifdef HAVE_PPSAPI
-       nmea_timer,             /* called once per second */
-#else
-       noentry,                /* timer */
-#endif
+       NMEA_TIMER              /* called once per second */
 };
 
 /*
@@ -254,8 +259,8 @@ nmea_start(
 #endif
        }
 
-       msyslog(LOG_NOTICE, "refclock_nmea: serial %s open at %s bps",
-               device, baudtext);
+       msyslog(LOG_NOTICE, "%s serial %s open at %s bps",
+               refnumtoa(&peer->srcadr), device, baudtext);
 
        /*
         * Allocate and initialize unit structure
@@ -287,16 +292,10 @@ nmea_start(
 
        gps_send(fd,"$PMOTG,RMC,0000*1D\r\n", peer);
 
-#ifdef HAVE_PPSAPI
-       /*
-        * Light up the PPSAPI interface.
-        */
-       return (refclock_ppsapi(fd, &up->atom));
-#else /* HAVE_PPSAPI */
        return (1);
-#endif /* HAVE_PPSAPI */
 }
 
+
 /*
  * nmea_shutdown - shut down a GPS clock
  */
@@ -317,6 +316,60 @@ nmea_shutdown(
        free(up);
 }
 
+/*
+ * nmea_control - configure fudge params
+ */
+#ifdef HAVE_PPSAPI
+static void
+nmea_control(
+       int unit,
+       struct refclockstat *in_st,
+       struct refclockstat *out_st,
+       struct peer *peer
+       )
+{
+       register struct nmeaunit *up;
+       struct refclockproc *pp;
+       
+       UNUSED_ARG(unit);
+       UNUSED_ARG(in_st);
+       UNUSED_ARG(out_st);
+
+       pp = peer->procptr;
+       up = (struct nmeaunit *)pp->unitptr;
+
+       if (!(CLK_FLAG1 & pp->sloppyclockflag)) {
+               if (!up->ppsapi_tried)
+                       return;
+               up->ppsapi_tried = 0;
+               if (!up->ppsapi_lit)
+                       return;
+               peer->flags &= ~FLAG_PPS;
+               peer->precision = PRECISION;
+               time_pps_destroy(up->atom.handle);
+               up->atom.handle = 0;
+               up->ppsapi_lit = 0;
+               return;
+       }
+
+       if (up->ppsapi_tried)
+               return;
+       /*
+        * Light up the PPSAPI interface.
+        */
+       up->ppsapi_tried = 1;
+       if (refclock_ppsapi(pp->io.fd, &up->atom)) {
+               up->ppsapi_lit = 1;
+               return;
+       }
+
+       NLOG(NLOG_CLOCKINFO)
+               msyslog(LOG_WARNING, "%s flag1 1 but PPSAPI fails",
+                       refnumtoa(&peer->srcadr));
+}
+#endif /* HAVE_PPSAPI */
+
+
 /*
  * nmea_timer - called once per second, fetches PPS
  *             timestamp and stuffs in median filter.
@@ -336,13 +389,11 @@ nmea_timer(
        pp = peer->procptr;
        up = (struct nmeaunit *)pp->unitptr;
 
-       if (pp->sloppyclockflag & CLK_FLAG1) {
-               if (refclock_pps(peer, &up->atom, pp->sloppyclockflag) >
-                   0) {
-                       up->pcount++,
-                       peer->flags |= FLAG_PPS;
-                       peer->precision = PPS_PRECISION;
-               }
+       if (up->ppsapi_lit &&
+           refclock_pps(peer, &up->atom, pp->sloppyclockflag) > 0) {
+               up->pcount++,
+               peer->flags |= FLAG_PPS;
+               peer->precision = PPS_PRECISION;
        }
 }
 #endif /* HAVE_PPSAPI */