refclock_pst.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_refclock.h"
#include "ntp_stdlib.h"
/*
* Receivers. No specific claim of accuracy is made for these receiver,
* but actual experience suggests that 10 ms would be a conservative
* assumption.
*
* The DIPswitches should be set for 9600 bps line speed, 24-hour day-
* of-year format and UTC time zone. Automatic correction for DST should
* be disabled. It is very important that the year be set correctly in
* the DIPswitches; otherwise, the day of year will be incorrect after
* 28 April of a normal or leap year. The propagation delay DIPswitches
* should be set according to the distance from the transmitter for both
* WWV and WWVH, as described in the instructions. While the delay can
* be set only to within 11 ms, the fudge time1 parameter can be used
* for vernier corrections.
*
* Using the poll sequence QTQDQM, the response timecode is in three
* sections totalling 50 ASCII printing characters, as concatenated by
* the driver, in the following format:
*
*
* on-time = first <cr>
* hh:mm:ss.fff = hours, minutes, seconds, milliseconds
* yy = year (from internal switches)
* s = daylight-saving indicator (' ' for 24-hour mode)
* f = frequency enable (O = all frequencies enabled)
* r = baud rate (3 = 1200, 6 = 9600)
* z = time zone (0 = UTC)
* y = year (5 = 91)
* cc = WWV propagation delay (52 = 22 ms)
* hh = WWVH propagation delay (81 = 33 ms)
* SS = status (80 or 82 = operating correctly)
* F = current receive frequency (4 = 15 MHz)
* T = transmitter (C = WWV, H = WWVH)
* tttt = time since last update (0000 = minutes)
* uu = flush character (03 = ^c)
* xx = 94 (unknown)
*
* The alarm condition is indicated by other than '8' at A, which occurs
* during initial synchronization and when received signal is lost for
* an extended period; unlock condition is indicated by other than
* "0000" in the tttt subfield at Q.
*
* Fudge Factors
*
* There are no special fudge factors other than the generic.
*/
/*
* Interface definitions
*/
/*
* Imported from ntp_timer module
*/
/*
* Imported from ntpd module
*/
extern int debug; /* global debug flag */
/*
* Unit control structure
*/
struct pstunit {
int pollcnt; /* poll message counter */
char *lastptr; /* pointer to timecode data */
};
/*
* Function prototypes
*/
static void pst_shutdown P((int, struct peer *));
static void pst_receive P((struct recvbuf *));
/*
* Transfer vector
*/
struct refclock refclock_pst = {
pst_start, /* start up driver */
pst_shutdown, /* shut down driver */
pst_poll, /* transmit poll message */
noentry, /* not used (old pst_control) */
noentry, /* initialize driver */
noentry, /* not used (old pst_buginfo) */
NOFLAGS /* not used */
};
/*
* pst_start - open the devices and initialize data for processing
*/
static int
int unit;
{
struct refclockproc *pp;
int fd;
char device[20];
/*
* Open serial port. Use CLK line discipline, if available.
*/
return (0);
/*
* Allocate and initialize unit structure
*/
return (0);
}
return (0);
}
/*
* Initialize miscellaneous variables
*/
return (1);
}
/*
* pst_shutdown - shut down the clock
*/
static void
int unit;
{
struct refclockproc *pp;
}
/*
* pst_receive - receive data from the serial interface
*/
static void
{
struct refclockproc *pp;
/*
* Initialize pointers and read the timecode and timestamp
*/
/*
* Note we get a buffer and timestamp for each <cr>, but only
* the first timestamp is retained.
*/
return;
#ifdef DEBUG
if (debug)
pp->a_lastcode);
#endif
/*
* We get down to business, check the timecode format and decode
* its contents. If the timecode has invalid length or is not in
* proper format, we declare bad format and exit.
*/
return;
}
/*
* Timecode format:
*/
return;
}
/*
* Decode synchronization, quality and last update. If
* unsynchronized, set the leap bits accordingly and exit. Once
* synchronized, the dispersion depends only on when the clock
* was last heard, which depends on the time since last update,
* as reported by the clock.
*/
} else {
else
}
/*
* 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.
*/
return;
}
}
/*
* pst_poll - called by the transmit procedure
*/
static void
int unit;
{
struct refclockproc *pp;
/*
* "QTQDQMT" by returning a timecode in the format specified
* above. If nothing is heard from the clock for two polls,
* declare a timeout and keep going.
*/
else
} else
}
#else /* not (REFCLOCK && PST) */
int refclock_pst_bs;
#endif /* not (REFCLOCK && PST) */