]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
refclock_parse.c:
authorFrank Kardel <kardel@ntp.org>
Sat, 25 Jun 2005 21:28:14 +0000 (21:28 +0000)
committerFrank Kardel <kardel@ntp.org>
Sat, 25 Jun 2005 21:28:14 +0000 (21:28 +0000)
  fix acceptance of clocks unsync clocks right at start
  change status reporting to use fixed refclock_report()
  clarify trust logic
  collect samples only if samples are ok (sync or trusted flywheel)
  propagate pps phase adjustment value to kernel via PPSAPI to help HARDPPS
  en- and dis-able HARDPPS in correlation to receiver sync state
  sort out log output sequence
ntp_refclock.c:
  complete event to statistic mapping
  make refclock_report to follow RFC1305 rules for clock.status
  and event reporting
parsestreams.h:
  update copyright
parse_conf.h, parse.h, mbg_gps166.h:
  add missing log keywords
driver8.html:
  anonymize version number in sample output

bk: 42bdcc6e4i6BF9ZoPoj5U7RfCbw0YQ

html/drivers/driver8.html
include/mbg_gps166.h
include/parse.h
include/parse_conf.h
kernel/sys/parsestreams.h
ntpd/ntp_refclock.c
ntpd/refclock_parse.c

index 51524f06dcde3d3866354cb27317f6646beba5cb..52cb519fe804f47374d311abb3d6d33f6f7ee073 100644 (file)
@@ -326,7 +326,7 @@ refclock_status="UTC DISPLAY; TIME CODE; PPS; POSITION; (LEAP INDICATION; PPS SI
 refclock_format="Meinberg GPS Extended",<br>
 refclock_states="*NOMINAL: 21:21:36 (99.99%); FAULT: 00:00:03 (0.00%); running time: 21:21:39",<br>
 refclock_id="GPS", refclock_iomode="normal",<br>
-refclock_driver_version="4.13",<br>
+refclock_driver_version="x.xx",<br>
 meinberg_gps_status="[0x0000] &lt;OK&gt;",<br>
 gps_utc_correction="current correction 13 sec, last correction on c3710e80.00000000  Fri, Nov 28 2003  0:00:00.000",<br>
 gps_message="ZIGMER3TN7R9U44:6WWDEK",<br>
index 5526a4c8007f57b2f706fbb570deaae9aa957396..aa685dd5e570a72a4e4ee2cf533a332b36ec9baf 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * /src/NTP/ntp4-dev/include/mbg_gps166.h,v 4.4 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ * /src/NTP/ntp4-dev/include/mbg_gps166.h,v 4.5 2005/06/25 10:58:45 kardel RELEASE_20050625_A
  *
- * mbg_gps166.h,v 4.4 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ * mbg_gps166.h,v 4.5 2005/06/25 10:58:45 kardel RELEASE_20050625_A
  *
  * $Created: Sun Jul 20 09:20:50 1997 $
  *
@@ -552,7 +552,12 @@ unsigned long mbg_csum P((unsigned char *, unsigned int));
 
 #endif
 /*
+ * History:
+ *
  * mbg_gps166.h,v
+ * Revision 4.5  2005/06/25 10:58:45  kardel
+ * add missing log keywords
+ *
  * Revision 4.1  1998/06/12 15:07:30  kardel
  * fixed prototyping
  *
index 6139a05278e87577ce282449cb3b1b98a85c7f04..f10d4bea185ba6f9cb27c9a380a02a535de130a2 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * /src/NTP/ntp4-dev/include/parse.h,v 4.10 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ * /src/NTP/ntp4-dev/include/parse.h,v 4.11 2005/06/25 10:58:45 kardel RELEASE_20050625_A
  *
- * parse.h,v 4.10 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ * parse.h,v 4.11 2005/06/25 10:58:45 kardel RELEASE_20050625_A
  *
  * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org>
  * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
@@ -35,7 +35,7 @@
 #ifndef __PARSE_H__
 #define __PARSE_H__
 #if    !(defined(lint) || defined(__GNUC__))
-  static char parsehrcsid[]="parse.h,v 4.10 2005/04/16 17:32:10 kardel RELEASE_20050508_A";
+  static char parsehrcsid[]="parse.h,v 4.11 2005/06/25 10:58:45 kardel RELEASE_20050625_A";
 #endif
 
 #include "ntp_types.h"
@@ -390,6 +390,9 @@ extern int parse_timedout P((parse_t *, timestamp_t *, struct timeval *));
  * History:
  *
  * parse.h,v
+ * Revision 4.11  2005/06/25 10:58:45  kardel
+ * add missing log keywords
+ *
  * Revision 4.5  1998/08/09 22:23:32  kardel
  * 4.0.73e2 adjustments
  *
index 3001d367f27e37c5c79c085c70eaa889596762cb..319dd543c43c9f11d677f8777cc5c3de010aaf51 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * /src/NTP/ntp4-dev/include/parse_conf.h,v 4.6 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ * /src/NTP/ntp4-dev/include/parse_conf.h,v 4.7 2005/06/25 10:58:45 kardel RELEASE_20050625_A
  *
- * parse_conf.h,v 4.6 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ * parse_conf.h,v 4.7 2005/06/25 10:58:45 kardel RELEASE_20050625_A
  *
  * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org>
  * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
@@ -35,7 +35,7 @@
 #ifndef __PARSE_CONF_H__
 #define __PARSE_CONF_H__
 #if    !(defined(lint) || defined(__GNUC__))
-  static char prshrcsid[] = "parse_conf.h,v 4.6 2005/04/16 17:32:10 kardel RELEASE_20050508_A";
+  static char prshrcsid[] = "parse_conf.h,v 4.7 2005/06/25 10:58:45 kardel RELEASE_20050625_A";
 #endif
 
 /*
@@ -72,3 +72,12 @@ struct format
   u_long      flags;
 };
 #endif
+
+/*
+ * History:
+ *
+ * parse_conf.h,v
+ * Revision 4.7  2005/06/25 10:58:45  kardel
+ * add missing log keywords
+ *
+ */
index 0cb715f1a8358deed37308f98c3573fb56c125f9..e784f9e8b37a98a5d6944d11825da46b4f6eca4a 100644 (file)
@@ -1,19 +1,38 @@
 /*
- * /src/NTP/ntp-4/kernel/sys/parsestreams.h,v 4.4 1998/06/14 21:09:32 kardel RELEASE_19990228_A
+ * /src/NTP/ntp4-dev/kernel/sys/parsestreams.h,v 4.5 2005/06/25 10:52:47 kardel RELEASE_20050625_A
  *
- * parsestreams.h,v 4.4 1998/06/14 21:09:32 kardel RELEASE_19990228_A
+ * parsestreams.h,v 4.5 2005/06/25 10:52:47 kardel RELEASE_20050625_A
  *
- * Copyright (c) 1989-1998 by Frank Kardel
- * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
- *                                   
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org>
+ * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
  *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #if    !(defined(lint) || defined(__GNUC__))
-  static char sysparsehrcsid[] = "parsestreams.h,v 1.2 2004/11/14 16:11:05 kardel RELEASE_20050508_A";
+  static char sysparsehrcsid[] = "parsestreams.h,v 4.5 2005/06/25 10:52:47 kardel RELEASE_20050625_A";
 #endif
 
 #undef PARSEKERNEL
@@ -87,7 +106,12 @@ extern int parsedebug;
 #endif
 
 /*
+ * History:
+ *
  * parsestreams.h,v
+ * Revision 4.5  2005/06/25 10:52:47  kardel
+ * fix version id / add version log
+ *
  * Revision 4.4  1998/06/14 21:09:32  kardel
  * Sun acc cleanup
  *
index fd06c8530a902374ff67363e1c3beaa8eade507b..3cb0f2b132d5be28bbf3e44be4ed8ffaa5bdf507 100644 (file)
@@ -112,15 +112,41 @@ refclock_report(
        if (pp == NULL)
                return;
 
-       if (code == CEVNT_BADREPLY)
-               pp->badformat++;
-       if (code == CEVNT_BADTIME)
-               pp->baddata++;
-       if (code == CEVNT_TIMEOUT)
-               pp->noreply++;
+       switch (code) {
+               case CEVNT_NOMINAL:
+                       break;
+
+               case CEVNT_TIMEOUT:
+                       pp->noreply++;
+                       break;
+
+               case CEVNT_BADREPLY:
+                       pp->badformat++;
+                       break;
+
+               case CEVNT_FAULT:
+                       break;
+
+               case CEVNT_PROP:
+                       break;
+
+               case CEVNT_BADDATE:
+               case CEVNT_BADTIME:
+                       pp->baddata++;
+                       break;
+
+               default:
+                       /* shouldn't happen */
+                       break;
+       }
+
        if (pp->currentstatus != code) {
                pp->currentstatus = (u_char)code;
-               pp->lastevent = (u_char)code;
+
+               /* RFC1305: copy only iff not CEVNT_NOMINAL */
+               if (code != CEVNT_NOMINAL)
+                       pp->lastevent = (u_char)code;
+
                if (code == CEVNT_FAULT)
                        msyslog(LOG_ERR,
                            "clock %s event '%s' (0x%02x)",
@@ -133,10 +159,12 @@ refclock_report(
                            refnumtoa(&peer->srcadr),
                            ceventstr(code), code);
                }
+
+               /* RFC1305: post peer clock event */
+               report_event(EVNT_PEERCLOCK, peer);
        }
 }
 
-
 /*
  * init_refclock - initialize the reference clock drivers
  *
index 89367a70a4740bb2cf1fc42a971a0e1e8a07f3dc..b196b201990d891fcc0fe739ec1a7408b3cb4236 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * /src/NTP/ntp4-dev/ntpd/refclock_parse.c,v 4.52 2005/05/26 21:55:06 kardel RELEASE_20050526_B
+ * /src/NTP/ntp4-dev/ntpd/refclock_parse.c,v 4.57 2005/06/25 09:25:19 kardel RELEASE_20050625_A
  *
- * refclock_parse.c,v 4.52 2005/05/26 21:55:06 kardel RELEASE_20050526_B
+ * refclock_parse.c,v 4.57 2005/06/25 09:25:19 kardel RELEASE_20050625_A
  *
  * generic reference clock driver for several DCF/GPS/MSF/... receivers
  *
 #include "ascii.h"
 #include "ieee754io.h"
 
-static char rcsid[]="4.52";
+static char rcsid[]="4.57";
 
 /**===========================================================================
  ** external interface to ntp mechanism
@@ -211,6 +211,9 @@ struct      refclock refclock_parse = {
 #undef ABS
 #define ABS(_X_) (((_X_) < 0) ? -(_X_) : (_X_))
 
+#define PARSE_HARDPPS_DISABLE 0
+#define PARSE_HARDPPS_ENABLE  1
+
 /**===========================================================================
  ** function vector for dynamically binding io handling mechanism
  **/
@@ -395,6 +398,7 @@ struct parseunit
 #ifdef HAVE_PPSAPI
         pps_handle_t  ppshandle;        /* store PPSAPI handle */
         pps_params_t  ppsparams;        /* current PPS parameters */
+        int           hardppsstate;     /* current hard pps state */
 #endif
        parsetime_t   timedata;         /* last (parse module) data */
        void         *localdata;        /* optional local, receiver-specific data */
@@ -1863,7 +1867,6 @@ stream_receive(
                ERR(ERR_BADIO)
                        msyslog(LOG_ERR,"PARSE receiver #%d: stream_receive: bad size (got %d expected %d)",
                                CLK_UNIT(parse->peer), rbufp->recv_length, (int)sizeof(parsetime_t));
-               parse->generic->baddata++;
                parse_event(parse, CEVNT_BADREPLY);
                return;
        }
@@ -2210,7 +2213,6 @@ local_receive(
                ERR(ERR_BADIO)
                        msyslog(LOG_ERR,"PARSE receiver #%d: local_receive: bad size (got %d expected %d)",
                                CLK_UNIT(parse->peer), rbufp->recv_length, (int)sizeof(parsetime_t));
-               parse->generic->baddata++;
                parse_event(parse, CEVNT_BADREPLY);
                return;
        }
@@ -2600,12 +2602,54 @@ parse_shutdown(
 }
 
 #ifdef HAVE_PPSAPI
+/*----------------------------------------
+ * set up HARDPPS via PPSAPI
+ */
+static void
+parse_hardpps(
+             struct parseunit *parse,
+             int mode
+             )
+{
+        if (parse->hardppsstate == mode)
+               return;
+
+       if (CLK_PPS(parse->peer) && (parse->flags & PARSE_PPSKERNEL)) {
+               int     i = 0;
+
+               if (mode == PARSE_HARDPPS_ENABLE) 
+                       {
+                               if (parse->flags & PARSE_CLEAR)
+                                       i = PPS_CAPTURECLEAR;
+                               else
+                                       i = PPS_CAPTUREASSERT;
+                       }
+               
+               if (time_pps_kcbind(parse->ppshandle, PPS_KC_HARDPPS, i,
+                   PPS_TSFMT_TSPEC) < 0) {
+                       msyslog(LOG_ERR, "PARSE receiver #%d: time_pps_kcbind failed: %m",
+                               CLK_UNIT(parse->peer));
+               } else {
+                       NLOG(NLOG_CLOCKINFO)
+                               msyslog(LOG_INFO, "PARSE receiver #%d: HARDPPS %sabled",
+                                       CLK_UNIT(parse->peer), (mode == PARSE_HARDPPS_ENABLE) ? "en" : "dis");
+                       /*
+                        * tell the rest, that we have a kernel PPS source, iff we ever enable HARDPPS
+                        */
+                       if (mode == PARSE_HARDPPS_ENABLE)
+                               pps_enable = 1;
+               }
+       }
+
+       parse->hardppsstate = mode;
+}
+
 /*----------------------------------------
  * set up PPS via PPSAPI
  */
 static int
 parse_ppsapi(
-       struct parseunit *parse
+            struct parseunit *parse
        )
 {
        int cap, mode, mode1;
@@ -2617,13 +2661,13 @@ parse_ppsapi(
                msyslog(LOG_ERR, "PARSE receiver #%d: parse_ppsapi: time_pps_getcap failed: %m",
                        CLK_UNIT(parse->peer));
                
-               return (0);
+               return 0;
        }
 
        if (time_pps_getparams(parse->ppshandle, &parse->ppsparams) < 0) {
                msyslog(LOG_ERR, "PARSE receiver #%d: parse_ppsapi: time_pps_getparams failed: %m",
                        CLK_UNIT(parse->peer));
-               return (0);
+               return 0;
        }
 
        /* nb. only turn things on, if someone else has turned something
@@ -2647,15 +2691,27 @@ parse_ppsapi(
          msyslog(LOG_ERR, "PARSE receiver #%d: FAILED to initialize PPS to %s",
                  CLK_UNIT(parse->peer), cp);
        
-               return(0);
+               return 0;
        }
 
        if (!(mode1 & cap)) {
          msyslog(LOG_WARNING, "PARSE receiver #%d: Cannot set PPS_%sCLEAR, this will increase jitter",
                  CLK_UNIT(parse->peer), cp);
                mode1 = 0;
+       } else {
+               if (mode1 == PPS_OFFSETCLEAR) 
+                       {
+                               parse->ppsparams.clear_offset.tv_sec = parse->ppsphaseadjust;
+                               parse->ppsparams.clear_offset.tv_nsec = 1e9*(parse->ppsphaseadjust - (long)parse->ppsphaseadjust);
+                       }
+         
+               if (mode1 == PPS_OFFSETASSERT)
+                       {
+                               parse->ppsparams.assert_offset.tv_sec = parse->ppsphaseadjust;
+                               parse->ppsparams.assert_offset.tv_nsec = 1e9*(parse->ppsphaseadjust - (long)parse->ppsphaseadjust);
+                       }
        }
-
+       
        /* only set what is legal */
 
        parse->ppsparams.mode = (mode | mode1 | PPS_TSFMT_TSPEC) & cap;
@@ -2666,35 +2722,11 @@ parse_ppsapi(
                return 0;
        }
 
-       /* If HARDPPS is on, we tell kernel */
-
-       if (parse->flags & PARSE_PPSKERNEL) {
-               int     i;
-
-               if (parse->flags & PARSE_CLEAR)
-                       i = PPS_CAPTURECLEAR;
-               else
-                       i = PPS_CAPTUREASSERT;
-
-               /* we know that 'i' is legal from above */
-
-               if (time_pps_kcbind(parse->ppshandle, PPS_KC_HARDPPS, i,
-                   PPS_TSFMT_TSPEC) < 0) {
-                       msyslog(LOG_ERR, "PARSE receiver #%d: time_pps_kcbind failed: %m",
-                               CLK_UNIT(parse->peer));
-                       return (0);
-               } else {
-                       msyslog(LOG_INFO, "PARSE receiver #%d: HARDPPS enabled",
-                               CLK_UNIT(parse->peer));
-                       /*
-                        * tell the rest, that we have a kernel PPS source
-                        */
-                       pps_enable = 1;
-               }
-       }
        parse->flags |= PARSE_PPSCLOCK;
-       return(1);
+       return 1;
 }
+#else
+#define parse_hardpps(_PARSE_, _MODE_) /* empty */
 #endif
 
 /*--------------------------------------------------
@@ -2719,6 +2751,16 @@ parse_start(
        parsectl_t tmp_ctl;
        u_int type;
 
+       /*
+        * get out Copyright information once
+        */
+       if (!notice)
+        {
+               NLOG(NLOG_CLOCKINFO) /* conditional if clause for conditional syslog */
+                       msyslog(LOG_INFO, "NTP PARSE support: Copyright (c) 1989-2005, Frank Kardel");
+               notice = 1;
+       }
+
        type = CLK_TYPE(peer);
        unit = CLK_UNIT(peer);
 
@@ -2910,6 +2952,7 @@ parse_start(
  * PPS via PPSAPI
  */
 #if defined(HAVE_PPSAPI)
+               parse->hardppsstate = PARSE_HARDPPS_DISABLE;
                if (CLK_PPS(parse->peer))
                {
                  if (time_pps_create(fd232, &parse->ppshandle) < 0) 
@@ -3030,16 +3073,6 @@ parse_start(
                                }
                }
        
-       /*
-        * get out Copyright information once
-        */
-       if (!notice)
-        {
-               NLOG(NLOG_CLOCKINFO) /* conditional if clause for conditional syslog */
-                       msyslog(LOG_INFO, "NTP PARSE support: Copyright (c) 1989-2005, Frank Kardel");
-               notice = 1;
-       }
-
        /*
         * print out configuration
         */
@@ -3165,7 +3198,6 @@ parse_poll(
                 * start worrying when exceeding a poll inteval
                 * bad news - didn't get a response last time
                 */
-               parse->generic->noreply++;
                parse->lastmissed = current_time;
                parse_event(parse, CEVNT_TIMEOUT);
                
@@ -3306,7 +3338,6 @@ parse_control(
                            mkascii(outstatus+strlen(outstatus), (int)(sizeof(outstatus)- strlen(outstatus) - 1),
                                    tmpctl.parsegettc.parse_buffer, (unsigned)(tmpctl.parsegettc.parse_count - 1));
 
-                       parse->generic->badformat += tmpctl.parsegettc.parse_badformat;
                }
        
                tmpctl.parseformat.parse_format = tmpctl.parsegettc.parse_format;
@@ -3405,9 +3436,7 @@ parse_control(
 
 /*--------------------------------------------------
  * event handling - note that nominal events will also be posted
- * mimics refclock_report() but take into account that bad status
- * counters are managed in the parser and keeps track of accumulated state
- * times
+ * keep track of state dwelling times
  */
 static void
 parse_event(
@@ -3423,35 +3452,14 @@ parse_event(
                if (parse->parse_type->cl_event)
                    parse->parse_type->cl_event(parse, event);
       
-               parse->generic->currentstatus = (u_char)event;
-
-               if (event != CEVNT_NOMINAL)
-               {
-                       parse->generic->lastevent = parse->generic->currentstatus;
-               }
-               else
+               if (event == CEVNT_NOMINAL)
                {
                        NLOG(NLOG_CLOCKSTATUS)
                                msyslog(LOG_INFO, "PARSE receiver #%d: SYNCHRONIZED",
                                        CLK_UNIT(parse->peer));
                }
 
-               if (event == CEVNT_FAULT)
-               {
-                       NLOG(NLOG_CLOCKEVENT) /* conditional if clause for conditional syslog */
-                               ERR(ERR_BADEVENT)
-                                     msyslog(LOG_ERR,
-                                             "clock %s fault '%s' (0x%02x)", refnumtoa(&parse->peer->srcadr), ceventstr(event),
-                                             (u_int)event);
-               }
-               else
-               {
-                 NLOG(NLOG_CLOCKEVENT) /* conditional if clause for conditional syslog */
-                         if (event == CEVNT_NOMINAL || list_err(parse, ERR_BADEVENT))
-                                   msyslog(LOG_INFO,
-                                           "clock %s event '%s' (0x%02x)", refnumtoa(&parse->peer->srcadr), ceventstr(event),
-                                           (u_int)event);
-               }
+               refclock_report(parse->peer, event);
        }
 }
 
@@ -3466,7 +3474,6 @@ parse_process(
 {
        l_fp off, rectime, reftime;
        double fudge;
-       int event_code = CEVNT_FAULT;
        
        /*
         * check for changes in conversion status
@@ -3501,7 +3508,6 @@ parse_process(
                                ERR(ERR_BADDATA)
                                        msyslog(LOG_WARNING, "PARSE receiver #%d: FAILED TIMECODE: \"%s\" (check receiver configuration / cableling)",
                                                CLK_UNIT(parse->peer), mkascii(buffer, sizeof buffer, tmpctl.parsegettc.parse_buffer, (unsigned)(tmpctl.parsegettc.parse_count - 1)));
-                               parse->generic->badformat += tmpctl.parsegettc.parse_badformat;
                        }
                }
        }
@@ -3531,7 +3537,6 @@ parse_process(
                        break;          /* well, still waiting - timeout is handled at higher levels */
                            
                case CVT_FAIL:
-                       parse->generic->badformat++;
                        if (parsetime->parse_status & CVT_BADFMT)
                        {
                                parse_event(parse, CEVNT_BADREPLY);
@@ -3643,6 +3648,7 @@ parse_process(
                 * seconds and the receiver is at least 2 minutes in the
                 * POWERUP or NOSYNC state before switching to SYNC
                 */
+               parse_event(parse, CEVNT_FAULT);
                NLOG(NLOG_CLOCKSTATUS)
                        ERR(ERR_BADSTATUS)
                        msyslog(LOG_ERR,"PARSE receiver #%d: NOT SYNCHRONIZED",
@@ -3682,7 +3688,7 @@ parse_process(
                        /*
                         * we have had some problems receiving the time code
                         */
-                       event_code = CEVNT_PROP;
+                       parse_event(parse, CEVNT_PROP);
                        NLOG(NLOG_CLOCKSTATUS)
                                ERR(ERR_BADSTATUS)
                                msyslog(LOG_ERR,"PARSE receiver #%d: TIMECODE NOT CONFIRMED",
@@ -3712,6 +3718,17 @@ parse_process(
        if (PARSE_PPS(parsetime->parse_state) && CLK_PPS(parse->peer))
        {
                l_fp offset;
+               double ppsphaseadjust = parse->ppsphaseadjust;
+
+#ifdef HAVE_PPSAPI
+               /*
+                * set fudge = 0.0 if already included in PPS time stamps
+                */
+               if (parse->ppsparams.mode & (PPS_OFFSETCLEAR|PPS_OFFSETASSERT))
+                       {
+                               ppsphaseadjust = 0.0;
+                       }
+#endif
 
                /*
                 * we have a PPS signal - much better than the RS232 stuff (we hope)
@@ -3729,7 +3746,7 @@ parse_process(
                        if (M_ISGEQ(off.l_i, off.l_f, -1, 0x80000000) &&
                            M_ISGEQ(0, 0x7fffffff, off.l_i, off.l_f))
                        {
-                               fudge = parse->ppsphaseadjust; /* pick PPS fudge factor */
+                               fudge = ppsphaseadjust; /* pick PPS fudge factor */
                        
                                /*
                                 * RS232 offsets within [-0.5..0.5[ - take PPS offsets
@@ -3765,7 +3782,7 @@ parse_process(
                }
                else
                {
-                       fudge = parse->ppsphaseadjust; /* pick PPS fudge factor */
+                       fudge = ppsphaseadjust; /* pick PPS fudge factor */
                        /*
                         * Well, no time code to guide us - assume on second pulse
                         * and pray, that we are within [-0.5..0.5[
@@ -3826,7 +3843,7 @@ parse_process(
                /*
                 * log OK status
                 */
-               event_code = CEVNT_NOMINAL;
+               parse_event(parse, CEVNT_NOMINAL);
        }
 
        clear_err(parse, ERR_BADIO);
@@ -3834,29 +3851,22 @@ parse_process(
        clear_err(parse, ERR_NODATA);
        clear_err(parse, ERR_INTERNAL);
   
-#ifdef DEBUG
-       if (debug > 2) 
-               {
-                       printf("PARSE receiver #%d: refclock_process_offset(reftime=%s, rectime=%s, Fudge=%f)\n",
-                               CLK_UNIT(parse->peer),
-                               prettydate(&reftime),
-                               prettydate(&rectime),
-                               fudge);
-               }
-#endif
-
-
        /*
         * and now stick it into the clock machine
         * samples are only valid iff lastsync is not too old and
         * we have seen the clock in sync at least once
         * after the last time we didn't see an expected data telegram
+        * at startup being not in sync is also bad just like
+        * POWERUP state
         * see the clock states section above for more reasoning
         */
        if (((current_time - parse->lastsync) > parse->maxunsync) ||
-           (parse->lastsync < parse->lastmissed))
+           (parse->lastsync < parse->lastmissed) ||
+           ((parse->lastsync == 0) && !PARSE_SYNC(parsetime->parse_state)) ||
+           PARSE_POWERUP(parsetime->parse_state))
        {
                parse->generic->leap = LEAP_NOTINSYNC;
+               parse->lastsync = 0;    /* wait for full sync again */
        }
        else
        {
@@ -3879,14 +3889,38 @@ parse_process(
                            parse->generic->leap = LEAP_NOWARNING;
                    }
        }
-  
-       refclock_process_offset(parse->generic, reftime, rectime, fudge);
-       if (PARSE_PPS(parsetime->parse_state) && CLK_PPS(parse->peer) &&
-           (parse->generic->leap != LEAP_NOTINSYNC))
+
+       if (parse->generic->leap != LEAP_NOTINSYNC)
        {
-               (void) pps_sample(&parse->timedata.parse_ptime.fp);
+               /*
+                * only good/trusted samples are interesting
+                */
+#ifdef DEBUG
+               if (debug > 2) 
+                       {
+                               printf("PARSE receiver #%d: refclock_process_offset(reftime=%s, rectime=%s, Fudge=%f)\n",
+                                      CLK_UNIT(parse->peer),
+                                      prettydate(&reftime),
+                                      prettydate(&rectime),
+                                      fudge);
+                       }
+#endif
+               parse->generic->lastref = reftime;
+               
+               refclock_process_offset(parse->generic, reftime, rectime, fudge);
+
+               /*
+                * pass PPS information on to PPS clock
+                */
+               if (PARSE_PPS(parsetime->parse_state) && CLK_PPS(parse->peer))
+                       {
+                               (void) pps_sample(&parse->timedata.parse_ptime.fp);
+                               parse_hardpps(parse, PARSE_HARDPPS_ENABLE);
+                       }
+       } else {
+               parse_hardpps(parse, PARSE_HARDPPS_DISABLE);
        }
-       
+
        /*
         * ready, unless the machine wants a sample or 
         * we are in fast startup mode (peer->dist > MAXDISTANCE)
@@ -3899,8 +3933,6 @@ parse_process(
        parse->timedata.parse_state &= ~(unsigned)(PARSEB_PPS|PARSEB_S_PPS);
 
        refclock_receive(parse->peer);
-
-       parse_event(parse, event_code); /* post event AFTER processing - refclock_receive likes to report a CEVNT_FAULT at startup */
 }
 \f
 /**===========================================================================
@@ -5613,6 +5645,23 @@ int refclock_parse_bs;
  * History:
  *
  * refclock_parse.c,v
+ * Revision 4.57  2005/06/25 09:25:19  kardel
+ * sort out log output sequence
+ *
+ * Revision 4.56  2005/06/14 21:47:27  kardel
+ * collect samples only if samples are ok (sync or trusted flywheel)
+ * propagate pps phase adjustment value to kernel via PPSAPI to help HARDPPS
+ * en- and dis-able HARDPPS in correlation to receiver sync state
+ *
+ * Revision 4.55  2005/06/02 21:28:31  kardel
+ * clarify trust logic
+ *
+ * Revision 4.54  2005/06/02 17:06:49  kardel
+ * change status reporting to use fixed refclock_report()
+ *
+ * Revision 4.53  2005/06/02 16:33:31  kardel
+ * fix acceptance of clocks unsync clocks right at start
+ *
  * Revision 4.52  2005/05/26 21:55:06  kardel
  * cleanup status reporting
  *