refclock_arc.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* refclock_arc - clock driver for ARCRON MSF receivers
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(REFCLOCK) && defined(ARCRON_MSF)
static const char arc_version[] = { "V1.1 1997/06/23" };
#ifndef ARCRON_NOT_KEEN
#endif
#ifndef ARCRON_NOT_OWN_FILTER
#ifndef ARCRON_OWN_FILTER
#endif
#endif
#ifndef ARCRON_NOT_MULTIPLE_SAMPLES
#endif
#ifndef ARCRON_NOT_LEAPSECOND_KEEN
#ifndef ARCRON_LEAPSECOND_KEEN
#endif
#endif
/*
Code by Derek Mulcahy, <derek@toybox.demon.co.uk>, 1997.
Modifications by Damon Hart-Davis, <d@hd.org>, 1997.
THIS CODE IS SUPPLIED AS IS, WITH NO WARRANTY OF ANY KIND. USE AT
YOUR OWN RISK.
Orginally developed and used with xntp3-5.85 by Derek Mulcahy.
Built against xntp3-5.90 on Solaris 2.5 using gcc 2.7.2.
This code may be freely copied and used and incorporated in other
systems providing the disclaimer and notice of authorship are
reproduced.
-------------------------------------------------------------------------------
Author's original note:
I enclose my xntp driver for the Galleon Systems Arc MSF receiver.
It works (after a fashion) on both Solaris-1 and Solaris-2.
I am currently using xntp3-5.85. I have been running the code for
about 7 months without any problems. Even coped with the change to BST!
I had to do some funky things to read from the clock because it uses the
power from the receive lines to drive the transmit lines. This makes the
code look a bit stupid but it works. I also had to put in some delays to
allow for the turnaround time from receive to transmit. These delays
are between characters when requesting a time stamp so that shouldn't affect
the results too drastically.
...
The bottom line is that it works but could easily be improved. You are
free to do what you will with the code. I haven't been able to determine
how good the clock is. I think that this requires a known good clock
to compare it against.
-------------------------------------------------------------------------------
Damon's notes for adjustments:
MAJOR CHANGES SINCE V1.0
========================
1) Removal of pollcnt variable that made the clock go permanently
off-line once two time polls failed to gain responses.
2) Avoiding (at least on Solaris-2) terminal becoming the controlling
terminal of the process when we do a low-level open().
3) Additional logic (conditional on ARCRON_LEAPSECOND_KEEN being
defined) to try to resync quickly after a potential leap-second
insertion or deletion.
4) Code significantly slimmer at run-time than V1.0.
GENERAL
=======
1) The C preprocessor symbol to have the clock built has been changed
from ARC to ARCRON_MSF to minimise the possiblity of clashes with
other symbols in the future.
2) PRECISION should be -4/-5 (63ms/31ms) for the following reasons:
a) The ARC documentation claims the internal clock is (only)
accurate to about 20ms relative to Rugby (plus there must be
noticable drift and delay in the ms range due to transmission
delays and changing atmospheric effects). This clock is not
designed for ms accuracy as NTP has spoilt us all to expect.
b) The clock oscillator looks like a simple uncompensated quartz
crystal of the sort used in digital watches (ie 32768Hz) which
can have large temperature coefficients and drifts; it is not
clear if this oscillator is properly disciplined to the MSF
transmission, but as the default is to resync only once per
*day*, we can imagine that it is not, and is free-running. We
can minimise drift by resyncing more often (at the cost of
significant.
c) Note that the bit time of 3.3ms adds to the potential error in
the the clock timestamp, since the bit clock of the serial link
may effectively be free-running with respect to the host clock
and the MSF clock. Actually, the error is probably 1/16th of
the above, since the input data is probably sampled at at least
16x the bit rate.
By keeping the clock marked as not very precise, it will have a
fairly large dispersion, and thus will tend to be used as a
`backup' time source and sanity checker, which this clock is
probably ideal for. For an isolated network without other time
sources, this clock can probably be expected to provide *much*
better than 1s accuracy, which will be fine.
By default, PRECISION is set to -4, but experience, especially at a
particular geographic location with a particular clock, may allow
this to be altered to -5. (Note that skews of +/- 10ms are to be
expected from the clock from time-to-time.) This improvement of
reported precision can be instigated by setting flag3 to 1, though
the PRECISION will revert to the normal value while the clock
signal quality is unknown whatever the flag3 setting.
IN ANY CASE, BE SURE TO SET AN APPROPRIATE FUDGE FACTOR TO REMOVE
ANY RESIDUAL SKEW, eg:
server 127.127.27.0 # ARCRON MSF radio clock unit 0.
# Fudge timestamps by about 20ms.
fudge 127.127.27.0 time1 0.020
You will need to observe your system's behaviour, assuming you have
some other NTP source to compare it with, to work out what the
fudge factor should be. For my Sun SS1 running SunOS 4.1.3_U1 with
my MSF clock with my distance from the MSF transmitter, +20ms
seemed about right, after some observation.
3) REFID has been made "MSFa" to reflect the MSF time source and the
ARCRON receiver.
4) DEFAULT_RESYNC_TIME is the time in seconds (by default) before
forcing a resync since the last attempt. This is picked to give a
little less than an hour between resyncs and to try to avoid
clashing with any regular event at a regular time-past-the-hour
which might cause systematic errors.
The INITIAL_RESYNC_DELAY is to avoid bothering the clock and
running down its batteries unnecesarily if xntpd is going to crash
or be killed or reconfigured quickly. If ARCRON_KEEN is defined
then this period is long enough for (with normal polling rates)
enough time samples to have been taken to allow xntpd to sync to
the clock before the interruption for the clock to resync to MSF.
This avoids xntpd syncing to another peer first and then
almost immediately hopping to the MSF clock.
The RETRY_RESYNC_TIME is used before rescheduling a resync after a
resync failed to reveal a statisfatory signal quality (too low or
unknown).
5) The clock seems quite jittery, so I have increased the
median-filter size from the typical (previous) value of 3. I
discard up to half the results in the filter. It looks like maybe
1 sample in 10 or so (maybe less) is a spike, so allow the median
filter to discard at least 10% of its entries or 1 entry, whichever
is greater.
6) Sleeping *before* each character sent to the unit to allow required
inter-character time but without introducting jitter and delay in
handling the response if possible.
7) If the flag ARCRON_KEEN is defined, take time samples whenever
possible, even while resyncing, etc. We rely, in this case, on the
clock always giving us a reasonable time or else telling us in the
status byte at the end of the timestamp that it failed to sync to
MSF---thus we should never end up syncing to completely the wrong
time.
8) If the flag ARCRON_OWN_FILTER is defined, use own versions of
refclock median-filter routines to get round small bug in 3-5.90
code which does not return the median offset.
9) We would appear to have a year-2000 problem with this clock since
it returns only the two least-significant digits of the year. But
xntpd ignores the year and uses the local-system year instead, so
this is in fact not a problem. Nevertheless, we attempt to do a
sensible thing with the dates, wrapping them into a 100-year
window.
to show the status of the clock.
11)The clock documentation insists that the number of bits per
character to be sent to the clock, and sent by it, is 11, including
one start bit and two stop bits. The data format is either 7+even
or 8+none.
TO-DO LIST
==========
* Eliminate use of scanf(), and maybe sprintf().
* Allow user setting of resync interval to trade battery life for
accuracy; maybe could be done via fudge factor or unit number.
* Possibly note the time since the last resync of the MSF clock to
MSF as the age of the last reference timestamp, ie trust the
clock's oscillator not very much...
* Add very slow auto-adjustment up to a value of +/- time2 to correct
for long-term errors in the clock value (time2 defaults to 0 so the
correction would be disabled by default).
* Possibly use average or maximum signal quality reported during
resync, rather than just the last one, which may be atypical.
*/
/* Notes for HKW Elektronik GmBH Radio clock driver */
/* Author Lyndon David, Sentinet Ltd, Feb 1997 */
/* These notes seem also to apply usefully to the ARCRON clock. */
/* The HKW clock module is a radio receiver tuned into the Rugby */
/* MSF time signal tranmitted on 60 kHz. The clock module connects */
/* to the computer via a serial line and transmits the time encoded */
/* in 15 bytes at 300 baud 7 bits two stop bits even parity */
/* Clock communications, from the datasheet */
/* All characters sent to the clock are echoed back to the controlling */
/* device. */
/* syntax ASCII o<cr> */
/* Character o may be replaced if neccesary by a character whose code */
/* contains the lowest four bits f(hex) eg */
/* syntax binary: xxxx1111 00001101 */
/* DHD note:
You have to wait for character echo + 10ms before sending next character.
*/
/* The clock replies to this command with a sequence of 15 characters */
/* which contain the complete time and a final <cr> making 16 characters */
/* in total. */
/* The RC computer clock will not reply immediately to this command because */
/* the start bit edge of the first reply character marks the beginning of */
/* the second. So the RC Computer Clock will reply to this command at the */
/* start of the next second */
/* The characters have the following meaning */
/* 1. hours tens */
/* 2. hours units */
/* 3. minutes tens */
/* 4. minutes units */
/* 5. seconds tens */
/* 6. seconds units */
/* 7. day of week 1-monday 7-sunday */
/* 8. day of month tens */
/* 9. day of month units */
/* 10. month tens */
/* 11. month units */
/* 12. year tens */
/* 13. year units */
/* bit 7 parity */
/* bit 6 always 0 */
/* bit 5 always 1 */
/* bit 4 always 1 */
/* bit 3 always 0 */
/* bit 2 =1 if UTC is in effect, complementary to the BST bit */
/* bit 1 =1 if BST is in effect, according to the BST bit */
/* 15. status */
/* bit 7 parity */
/* bit 6 always 0 */
/* bit 5 always 1 */
/* bit 4 always 1 */
/* bit 3 =1 if low battery is detected */
/* bit 2 =1 if the very last reception attempt failed and a valid */
/* time information already exists (bit0=1) */
/* =0 if the last reception attempt was successful */
/* bit 1 =1 if at least one reception since 2:30 am was successful */
/* =0 if no reception attempt since 2:30 am was successful */
/* bit 0 =1 if the RC Computer Clock contains valid time information */
/* This bit is zero after reset and one after the first */
/* successful reception attempt */
/* DHD note:
Also note g<cr> command which confirms that a resync is in progress, and
if so what signal quality (0--5) is available.
Also note h<cr> command which starts a resync to MSF signal.
*/
#include <stdio.h>
#include <ctype.h>
#if defined(HAVE_BSD_TTYS)
#include <sgtty.h>
#endif /* HAVE_BSD_TTYS */
#if defined(HAVE_SYSV_TTYS)
#include <termio.h>
#endif /* HAVE_SYSV_TTYS */
#if defined(HAVE_TERMIOS)
#include <termios.h>
#endif
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_refclock.h"
#include "ntp_stdlib.h"
/*
* This driver supports the ARCRON MSF Radio Controlled Clock
*/
/*
* Interface definitions
*/
#define DESCRIPTION "ARCRON MSF Receiver"
#define CHARTIME /* Time for char at 300bps. */ \
(BITSPERCHAR * BITTIME) ) )
/* Allow for UART to accept char half-way through final stop bit. */
/*
charoffsets[x] is the time after the start of the second that byte
x (with the first byte being byte 1) is received by the UART,
assuming that the initial edge of the start bit of the first byte
is on-time. The values are represented as the fractional part of
an l_fp.
We store enough values to have the offset of each byte including
the trailing \r, on the assumption that the bytes follow one
another without gaps.
*/
/* Offsets computed as accurately as possible... */
0,
#else
/* Offsets computed with a small rounding error... */
0,
#endif
};
/* Chose filter length dependent on fudge flag 4. */
#define CHOSENSAMPLES(pp) \
/*
Chose how many filter samples to keep. Several factors are in play.
1) Discard at least one sample to allow a spike value to be
discarded.
2) Discard about 1-in-8 to 1-in-30 samples to handle spikes.
3) Keep an odd number of samples to avoid median value being biased
high or low.
*/
#ifdef ARCRON_KEEN
#else
#endif
static const int moff[12] =
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
/* Flags for a raw open() of the clock serial device. */
#ifdef O_NOCTTY /* Good, we can avoid tty becoming controlling tty. */
#else /* Oh well, it may not matter... */
#define OPEN_FLAGS (O_RDWR)
#endif
/*
* Imported from ntp_timer module
*/
/*
* Imported from ntpd module
*/
extern int debug; /* Global debug flag. */
/* Length of queue of command bytes to be sent. */
/* Queue tick time; interval in seconds between chars taken off queue. */
/* Must be >= 2 to allow o\r response to come back uninterrupted. */
/*
* ARC unit control structure
*/
struct arcunit {
int status; /* Clock status. */
int quality; /* Quality of reception 0--5 for unit. */
/* We may also use the values -1 or 6 internally. */
int resyncing; /* Resync in progress if true. */
/* In the outgoing queue, cmdqueue[0] is next to be sent. */
};
#ifdef ARCRON_LEAPSECOND_KEEN
/* The flag `possible_leap' is set non-zero when any MSF unit
thinks a leap-second may have happened.
Set whenever we receive a valid time sample in the first hour of
Outside the special hour this value is unconditionally set
to zero by the receive routine.
On finding itself in this timeslot, as long as the value is
non-negative, the receive routine sets it to a positive value to
indicate a resync to MSF should be performed.
In the poll routine, if this value is positive and we are not
already resyncing (eg from a sync that started just before
midnight), start resyncing and set this value negative to
indicate that a leap-triggered resync has been started. Having
set this negative prevents the receive routine setting it
positive and thus prevents multiple resyncs during the witching
hour.
*/
static int possible_leap = 0; /* No resync required by default. */
#endif
static void dummy_event_handler P((struct peer *));
static void arc_event_handler P((struct peer *));
static int space_left P((struct arcunit *));
#define MIN_CLOCK_QUALITY 0 /* Min quality clock will return. */
/*
* Function prototypes
*/
static void arc_shutdown P((int, struct peer *));
static void arc_receive P((struct recvbuf *));
/*
* Transfer vector
*/
struct refclock refclock_arc = {
arc_start, /* start up driver */
arc_shutdown, /* shut down driver */
arc_poll, /* transmit poll message */
noentry, /* not used (old arc_control) */
noentry, /* initialize driver (not used) */
noentry, /* not used (old arc_buginfo) */
NOFLAGS /* not used */
};
/* Queue us up for the next tick. */
do { \
} while(0)
/* Placeholder event handler---does nothing safely---soaks up lose tick. */
static void dummy_event_handler(peer)
{
#ifdef ARCRON_DEBUG
#endif
}
/*
Normal event handler.
Take first character off queue and send to clock if not a null.
Shift characters down and put a null on the end.
We assume that there is no parallelism so no race condition, but even
if there is nothing bad will happen except that we might send some bad
data to the clock once in a while.
*/
static void arc_event_handler(peer)
{
int i;
char c;
#ifdef ARCRON_DEBUG
#endif
/* Shift down characters, shifting trailing \0 in at end. */
for(i = 0; i < CMDQUEUELEN; ++i)
/* Don't send '\0' characters. */
if(c != '\0') {
}
#ifdef ARCRON_DEBUG
#endif
}
}
/*
* arc_start - open the devices and initialize data for processing
*/
static int
int unit;
{
struct refclockproc *pp;
int fd;
char device[20];
#ifdef HAVE_TERMIOS
#endif
#ifdef ARCRON_DEBUG
if(debug) {
}
#endif
/* Prevent a ridiculous device number causing overflow of device[]. */
/*
* Open serial port. Use CLK line discipline, if available.
*/
#ifdef TTYCLK
#ifdef ARCRON_DEBUG
#endif
#ifdef DEBUG
#endif
return(0);
}
#else
#ifdef ARCRON_DEBUG
#endif
if(fd < 0) {
#ifdef DEBUG
#endif
return(0);
}
#ifdef ARCRON_DEBUG
if(debug)
#endif
#ifdef HAVE_TERMIOS
#else
return 0;
#endif
#endif /* TTYCLK */
/* Set structure to all zeros... */
/*
* Initialize miscellaneous variables
*/
/* Spread out resyncs so that they should remain separated. */
#if 0 /* Not needed because of zeroing of arcunit structure... */
/* Clear send buffer out... */
{
int i;
}
#endif
#ifdef ARCRON_KEEN
#else
#endif
/* Set up event structure. */
return(1);
}
/*
* arc_shutdown - shut down the clock
*/
static void
int unit;
{
struct refclockproc *pp;
}
/*
Compute space left in output buffer.
*/
static int space_left(up)
{
int spaceleft;
/* Compute space left in buffer after any pending output. */
return(spaceleft);
}
/*
Send command by copying into command buffer as far forward as possible,
after any pending output.
Indicate an error by returning 0 if there is not space for the command.
*/
static int
int fd;
char *s;
{
#ifdef ARCRON_DEBUG
#endif
#ifdef ARCRON_DEBUG
#endif
return(0); /* FAILED! */
}
/* Copy in the command to be sent. */
return(1);
}
#ifdef ARCRON_OWN_FILTER
static int arc_refclock_process P((struct refclockproc *, int, int));
static int arc_refclock_cmpl_fp P((const void *, const void *));
#endif
/* Macro indicating action we will take for different quality values. */
#define quality_action(q) \
(((q) == QUALITY_UNKNOWN) ? "UNKNOWN, will use clock anyway" : \
(((q) < MIN_CLOCK_QUALITY_OK) ? "TOO POOR, will not use clock" : \
"OK, will use clock"))
/*
* arc_receive - receive data from the serial interface
*/
static void
{
struct refclockproc *pp;
char c;
int last_offset;
/*
* Initialize pointers and read the timecode and timestamp
*/
/*
If the command buffer is empty, and we are resyncing, insert a
g\r quality request into it to poll for signal quality again.
*/
#ifdef DEBUG
#endif
}
/*
The `last_offset' is the offset in lastcode[] of the last byte
received, and which we assume actually received the input
timestamp.
(When we get round to using tty_clk and it is available, we
assume that we will receive the whole timecode with the
trailing \r, and that that \r will be timestamped. But this
assumption also works if receive the characters one-by-one.)
*/
/*
We catch a timestamp iff:
* The command code is `o' for a timestamp.
* If ARCRON_MULTIPLE_SAMPLES is undefined then we must have
exactly char in the buffer (the command code) so that we
only sample the first character of the timecode as our
`on-time' character.
* The first character in the buffer is not the echoed `\r'
from the `o` command (so if we are to timestamp an `\r' it
must not be first in the receive buffer with lencode==1.
(Even if we had other characters following it, we probably
would have a premature timestamp on the '\r'.)
* We have received at least one character (I cannot imagine
how it could be otherwise, but anyway...).
*/
c = rbufp->recv_buffer[0];
#ifndef ARCRON_MULTIPLE_SAMPLES
#endif
(last_offset >= 1)) {
/* Note that the timestamp should be corrected if >1 char rcvd. */
#ifdef DEBUG
if(debug) { /* Show \r as `R', other non-printing char as `?'. */
printf("arc: stamp -->%c<-- (%d chars rcvd)\n",
rbufp->recv_length);
}
#endif
/*
Now correct timestamp by offset of last byte received---we
subtract from the receive time the delay implied by the
extra characters received.
Reject the input if the resulting code is too long, but
allow for the trailing \r, normally not used but a good
handle for tty_clk or somesuch kernel timestamper.
*/
if(last_offset > LENARC) {
#ifdef ARCRON_DEBUG
if(debug) {
printf("arc: input code too long (%d cf %d); rejected.\n",
}
#endif
return;
}
#ifdef ARCRON_DEBUG
if(debug > 1) {
"arc: %s%d char(s) rcvd, the last for lastcode[%d]; -%sms offset applied.\n",
mfptoms((unsigned long)0,
1));
}
#endif
#ifdef ARCRON_MULTIPLE_SAMPLES
/*
If taking multiple samples, capture the current adjusted
sample iff:
* No timestamp has yet been captured (it is zero), OR
* This adjusted timestamp is earlier than the one already
captured, on the grounds that this one suffered less
delay in being delivered to us and is more accurate.
*/
#endif
{
#ifdef ARCRON_DEBUG
if(debug > 1) {
printf("arc: system timestamp captured.\n");
#ifdef ARCRON_MULTIPLE_SAMPLES
printf("arc: adjusted timestamp by -%sms.\n",
}
#endif
}
#endif
}
}
/* Just in case we still have lots of rubbish in the buffer... */
/* ...and to avoid the same timestamp being reused by mistake, */
/* eg on receipt of the \r coming in on its own after the */
/* timecode. */
#ifdef ARCRON_DEBUG
{ printf("arc: rubbish in pp->a_lastcode[].\n"); }
#endif
return;
}
/* Append input to code buffer, avoiding overflow. */
for(i = 0; i < rbufp->recv_length; i++) {
c = rbufp->recv_buffer[i];
/* Drop trailing '\r's and drop `h' command echo totally. */
/*
If we've just put an `o' in the lastcode[0], clear the
timestamp in anticipation of a timecode arriving soon.
We would expect to get to process this before any of the
timecode arrives.
*/
#ifdef ARCRON_DEBUG
#endif
}
}
/* Handle a quality message. */
int r, q;
((r & 0x70) != 0x30)) {
/* Badly formatted response. */
#ifdef ARCRON_DEBUG
#endif
return;
}
if(r == '3') { /* Only use quality value whilst sync in progress. */
#ifdef DEBUG
#endif
#ifdef DEBUG
if(debug)
{
printf("arc: sync finished, signal quality %d: %s\n",
}
#endif
"ARCRON: sync finished, signal quality %d: %s",
#ifdef ARCRON_KEEN
/* Clock quality dubious; resync earlier than usual. */
#endif
}
return;
}
/* Stop now if this is not a timecode message. */
return;
}
/* If we don't have enough data, wait for more... */
/* WE HAVE NOW COLLECTED ONE TIMESTAMP (phew)... */
#ifdef ARCRON_DEBUG
#endif
/* But check that we actually captured a system timestamp on it. */
#ifdef ARCRON_DEBUG
#endif
return;
}
/*
Append a mark of the clock's received signal quality for the
quality value to `6' for his s/w) and terminate the string for
sure. This should not go off the buffer end.
*/
/* Validate format and numbers. */
if(n != 9) {
#ifdef ARCRON_DEBUG
/* Would expect to have caught major problems already... */
#endif
return;
}
/*
Validate received values at least enough to prevent internal
array-bounds problems, etc.
*/
/* Data out of range. */
return;
}
return;
}
/* Year-2000 alert! */
/* Attempt to wrap 2-digit date into sensible window. */
/* This code was written in 1997, so that is the window start. */
/*
Attempt to do the right thing by screaming that the code will
soon break when we get to the end of its useful life. What a
hero I am... PLEASE FIX LEAP-YEAR AND WRAP CODE IN 209X!
*/
"ARCRON: fix me! EITHER YOUR DATE IS BADLY WRONG or else I will break soon!");
}
#ifdef DEBUG
if(debug) {
printf("arc: n=%d %02d:%02d:%02d %02d/%02d/%04d %1d %1d\n",
n,
}
#endif
/*
The status value tested for is not strictly supported by the
clock spec since the value of bit 2 (0x4) is claimed to be
undefined for MSF, yet does seem to indicate if the last resync
was successful or not.
*/
status &= 0x7;
if(status == 0x3) {
} else {
return;
}
}
/* Good 'til 1st March 2100 */
/* Convert to UTC if required */
if(bst & 2) {
/* If we try to wrap round the year (BST on 1st Jan), reject.*/
return;
}
}
}
/* If clock signal quality is unknown, revert to default PRECISION...*/
/* ...else improve precision if flag3 is set... */
else {
}
/* Notice and log any change (eg from initial defaults) for flags. */
#ifdef ARCRON_DEBUG
/* Note effects of flags changing... */
if(debug) {
}
#endif
}
/* Note time of last believable timestamp. */
#ifdef ARCRON_LEAPSECOND_KEEN
/* Find out if a leap-second might just have happened...
(ie is this the first hour of the first day of Jan or Jul?)
*/
if(possible_leap >= 0) {
/* A leap may have happened, and no resync has started yet...*/
possible_leap = 1;
}
} else {
/* Definitely not leap-second territory... */
possible_leap = 0;
}
#endif
/*
* Process the new sample in the median filter and determine the
* reference clock offset and dispersion. We use lastrec as both
* the reference time and receive time in order to avoid being
* cute, like setting the reference time later than the receive
* time, which may cause a paranoid protocol module to chuck out
* the data.
*/
#ifdef ARCRON_OWN_FILTER
#else
#endif
{
return;
}
}
/* request_time() sends a time request to the clock with given peer. */
/* This automatically reports a fault if necessary. */
/* No data should be sent after this until arc_poll() returns. */
static void request_time P((int, struct peer *));
static void
int unit;
{
#ifdef DEBUG
#endif
#ifdef ARCRON_DEBUG
#endif
return;
}
}
/*
* arc_poll - called by the transmit procedure
*/
static void
int unit;
{
struct refclockproc *pp;
int resync_needed; /* Should we start a resync? */
#if 0
/* Flush input. */
#endif
/* Resync if our next scheduled resync time is here or has passed. */
#ifdef ARCRON_LEAPSECOND_KEEN
/*
Try to catch a potential leap-second insertion or deletion quickly.
In addition to the normal NTP fun of clocks that don't report
leap-seconds spooking their hosts, this clock does not even
sample the radio sugnal the whole time, so may miss a
leap-second insertion or deletion for up to a whole sample
time.
To try to minimise this effect, if in the first few minutes of
the day immediately following a leap-second-insertion point
(ie in the first hour of the first day of the first and sixth
months), and if the last resync was in the previous day, and a
resync is not already in progress, resync the clock
immediately.
*/
if((possible_leap > 0) && /* Must be 00:XX 01/0{1,7}/XXXX. */
resync_needed = 1;
}
#endif
/* Do a resync if required... */
if(resync_needed) {
/* First, reset quality value to `unknown' so we can detect */
/* when a quality message has been responded to by this */
/* being set to some other value. */
/* Note that we are resyncing... */
/* Now actually send the resync command and an immediate poll. */
#ifdef DEBUG
#endif
/* Schedule our next resync... */
/* Drop through to request time if appropriate. */
}
/* If clock quality is too poor to trust, indicate a fault. */
/* If quality is QUALITY_UNKNOWN and ARCRON_KEEN is defined,*/
/* we'll cross our fingers and just hope that the thing */
/* synced so quickly we did not catch it---we'll */
/* double-check the clock is OK elsewhere. */
if(
#ifdef ARCRON_KEEN
#else
#endif
#ifdef DEBUG
if(debug) {
}
#endif
return;
}
/* This is the normal case: request a timestamp. */
}
#ifdef ARCRON_OWN_FILTER
/* Very small fixes to the 3-5.90 ntp_refclock.c code. */
#include "ntp_unixtime.h" /* For TVUTOTSF, etc. */
/*
* Compare two l_fp's - used with qsort()
*/
static int
{
return (-1);
return (0);
return (1);
}
/*
* refclock_process - process a pile of samples from the clock
*
* This routine converts the timecode in the form days, hours, minutes,
* seconds, milliseconds/microseconds to internal timestamp format.
* Further processing is then delegated to refclock sample
*/
static int
int nstart; /* stages of median filter */
int nskeep; /* stages after outlyer trim */
{
/*
* Compute the timecode timestamp from the days, hours, minutes,
* seconds and milliseconds/microseconds of the timecode. Use
* the fraction, when present. Note that this code relies on the
* filesystem time for the years and does not use the years of
* the timecode.
*/
return (0);
} else {
}
/*
* Include the configured fudgetime1 adjustment.
*/
#ifdef ARCRON_DEBUG
printf("arc: raw offset %sms.\n",
}
#endif
}
/*
* refclock_sample - process a pile of samples from the clock
*
* This routine converts the timecode in the form days, hours, miinutes,
* seconds, milliseconds/microseconds to internal timestamp format. It
* then calculates the difference from the receive timestamp and
* assembles the samples in a shift register. It implements a recursive
* median filter to suppress spikes in the data, as well as determine a
* rough dispersion estimate. A configuration constant time adjustment
* fudgetime1 can be added to the final offset to compensate for various
* systematic errors. The routine returns one if success and zero if
* failure due to invalid timecode data or very noisy offsets.
*
* This interface is needed to allow for clocks (e. g. parse) that can
* provide the correct offset including year information (though NTP
* usually gives up on offsets greater than 1000 seconds).
*/
static int
for filter machine */
int nstart; /* stages of median filter */
int nskeep; /* stages after outlyer trim */
{
int i, n;
/*
* Subtract the receive timestamp from the timecode timestamp
* to form the raw offset. Insert in the median filter shift
* register.
*/
offset = *sample_offset;
/*
* Copy the raw offsets and sort into ascending order
*/
/*
* Reject the furthest from the median of nstages samples until
* nskeep samples remain.
*/
i = 0;
while ((n - i) > nskeep) {
/* reject low end */
i++;
} else {
/* reject high end */
n--;
}
}
/*
* Compute the dispersion based on the difference between the
* extremes of the remaining offsets. Add to this the time since
* the last clock update, which represents the dispersion
* increase with time. We know that NTP_MAXSKEW is 16. If the
* sum is greater than the allowed sample dispersion, bail out.
* If the loop is unlocked, return the most recent offset;
* otherwise, return the median offset.
*/
if (disp > REFCLOCKMAXDISPERSE)
return (0);
return (1);
}
#endif /* ARCRON_OWN_FILTER */
#else /* not (REFCLOCK && ARCRON_MSF) */
int refclock_arc_bs;
#endif /* not (REFCLOCK && ARCRON_MSF) */