diff options
Diffstat (limited to 'contrib/ntp/ntpd/refclock_true.c')
-rw-r--r-- | contrib/ntp/ntpd/refclock_true.c | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/contrib/ntp/ntpd/refclock_true.c b/contrib/ntp/ntpd/refclock_true.c index b841f72..dcc362d 100644 --- a/contrib/ntp/ntpd/refclock_true.c +++ b/contrib/ntp/ntpd/refclock_true.c @@ -12,16 +12,15 @@ #if defined(REFCLOCK) && defined(CLOCK_TRUETIME) -#include <stdio.h> -#include <ctype.h> -#include <sys/time.h> - #include "ntpd.h" #include "ntp_io.h" #include "ntp_refclock.h" #include "ntp_unixtime.h" #include "ntp_stdlib.h" +#include <stdio.h> +#include <ctype.h> + /* This should be an atom clock but those are very hard to build. * * The PCL720 from P C Labs has an Intel 8253 lookalike, as well as a bunch @@ -62,11 +61,12 @@ * * Quality codes indicate possible error of * 468-DC GOES Receiver: - * GPS-TM/TMD Receiver: - * ? +/- 500 milliseconds # +/- 50 milliseconds - * * +/- 5 milliseconds . +/- 1 millisecond - * space less than 1 millisecond - * OM-DC OMEGA Receiver: + * GPS-TM/TMD Receiver: (default quality codes for XL-DC) + * ? +/- 1 milliseconds # +/- 100 microseconds + * * +/- 10 microseconds . +/- 1 microsecond + * space less than 1 microsecond + * OM-DC OMEGA Receiver: (default quality codes for OMEGA) + * WARNING OMEGA navigation system is no longer existent * > >+- 5 seconds * ? >+/- 500 milliseconds # >+/- 50 milliseconds * * >+/- 5 milliseconds . >+/- 1 millisecond @@ -109,6 +109,7 @@ * flag4 - use the PCL-720 (BSD/OS only) */ + /* * Definitions */ @@ -211,11 +212,12 @@ true_debug(struct peer *peer, const char *fmt, ...) if (want_debugging != now_debugging) { if (want_debugging) { - char filename[20]; + char filename[40]; + int fd; - sprintf(filename, "/tmp/true%d.debug", up->unit); - up->debug = fopen(filename, "w"); - if (up->debug) { + snprintf(filename, sizeof(filename), "/tmp/true%d.debug", up->unit); + fd = open(filename, O_CREAT | O_WRONLY | O_EXCL, 0600); + if (fd >= 0 && (up->debug = fdopen(fd, "r+"))) { #ifdef HAVE_SETVBUF static char buf[BUFSIZ]; setvbuf(up->debug, buf, _IOLBF, BUFSIZ); @@ -247,13 +249,13 @@ true_start( { register struct true_unit *up; struct refclockproc *pp; - char device[20]; + char device[40]; int fd; /* * Open serial port */ - (void)sprintf(device, DEVICE, unit); + (void)snprintf(device, sizeof(device), DEVICE, unit); if (!(fd = refclock_open(device, SPEED232, LDISC_CLK))) return (0); @@ -325,6 +327,10 @@ true_receive( char synced; int i; int lat, lon, off; /* GOES Satellite position */ + /* Use these variable to hold data until we decide its worth keeping */ + char rd_lastcode[BMAX]; + l_fp rd_tmp; + u_short rd_lencode; /* * Get the clock this applies to and pointers to the data. @@ -336,14 +342,17 @@ true_receive( /* * Read clock output. Automatically handles STREAMS, CLKLDISC. */ - pp->lencode = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &pp->lastrec); + rd_lencode = refclock_gtlin(rbufp, rd_lastcode, BMAX, &rd_tmp); + rd_lastcode[rd_lencode] = '\0'; /* * There is a case where <cr><lf> generates 2 timestamps. */ - if (pp->lencode == 0) - return; - pp->a_lastcode[pp->lencode] = '\0'; + if (rd_lencode == 0) + return; + pp->lencode = rd_lencode; + strcpy(pp->a_lastcode, rd_lastcode); + pp->lastrec = rd_tmp; true_debug(peer, "receive(%s) [%d]\n", pp->a_lastcode, pp->lencode); up->pollcnt = 2; @@ -360,7 +369,8 @@ true_receive( /* * Clock misunderstood our last command? */ - if (pp->a_lastcode[0] == '?') { + if (pp->a_lastcode[0] == '?' || + strcmp(pp->a_lastcode, "ERROR 05 NO SUCH FUNCTION") == 0) { true_doevent(peer, e_Huh); return; } @@ -428,13 +438,14 @@ true_receive( } /* - * Timecode: " TRUETIME Mk III" - * (from a TM/TMD clock during initialization.) + * Timecode: " TRUETIME Mk III" or " TRUETIME XL" + * (from a TM/TMD/XL clock during initialization.) */ - if (strcmp(pp->a_lastcode, " TRUETIME Mk III") == 0) { + if (strcmp(pp->a_lastcode, " TRUETIME Mk III") == 0 || + strncmp(pp->a_lastcode, " TRUETIME XL", 12) == 0) { true_doevent(peer, e_F18); NLOG(NLOG_CLOCKSTATUS) { - msyslog(LOG_INFO, "TM/TMD: %s", pp->a_lastcode); + msyslog(LOG_INFO, "TM/TMD/XL: %s", pp->a_lastcode); } return; } @@ -467,9 +478,12 @@ true_receive( /* * Adjust the synchronize indicator according to timecode + * say were OK, and then say not if we really are not OK */ - if (synced != ' ' && synced != '.' && synced != '*') + if (synced == '>' || synced == '#' || synced == '?') pp->leap = LEAP_NOTINSYNC; + else + pp->leap = LEAP_NOWARNING; true_doevent(peer, e_TS); @@ -527,6 +541,11 @@ true_receive( refclock_report(peer, CEVNT_BADTIME); return; } + /* + * If clock is good we send a NOMINAL message so that + * any previous BAD messages are nullified + */ + refclock_report(peer, CEVNT_NOMINAL); refclock_receive(peer); /* |