refclock_irig.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* refclock_irig - clock driver for the IRIG audio decoder
*/
#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_unixtime.h"
#include <sys/bsd_audioirig.h>
#include "ntp_stdlib.h"
/*
* This driver supports the IRIG audio decoder. This clever gadget uses
* a modified BSD audio driver for the Sun SPARCstation which provides
* a timestamp, raw binary timecode, status byte and decoded ASCII
* timecode. The data are represented in the structure in the
* sys/bsd_audioirig.h header file:
*
* struct irig_time {
* struct timeval stamp; timestamp
* u_char bits[13]; 100 IRIG data bits
* u_char status; status byte
* char time[14]; time string (null terminated)
*
* where stamp represents a timestamp at the zero crossing of the index
* marker at the second's epoch, bits is a 13-octet, zero-padded binary-
* coded string representing code elements 1 through 100 in the IRIG-B
* code format, and status is a status bute, The decoded timestamp is a
* 13-octet, null-terminated ASCII string "ddd hh:mm:ss*", where ddd is
* the day of year, hh:mm:ss the time of day and * is a status
* indicator, with " " indicating valid time and "?" indicating
* something wrong.
*
* The timestamp is in Unix timeval format, consisting of two 32-bit
* words, the first of which is the seconds since 1970 and the second is
* the fraction of the second in microseconds. The status byte is zero
* if (a) the input signal is within amplitude tolerances, (b) the raw
* binary timecode contains only valid code elements, (c) 11 position
* identifiers have been found at the expected element positions, (d)
* the clock status byte contained in the timecode is valid, and (e) a
* time determination has been made since the last read() system call.
*
* The 100 elements of the IRIG-B timecode are numbered from 0 through
* 99. Position identifiers occur at elements 0, 9, 19 and every ten
* thereafter to 99. The control function (CF) elements begin at element
* 50 (CF 1) and extend to element 78 (CF 27). The straight-binary-
* seconds (SBS) field, which encodes the seconds of the UTC day, begins
* at element 80 (CF 28) and extends to element 97 (CF 44). The encoding
* of elements 50 (CF 1) through 78 (CF 27) is device dependent. This
* driver presently does not use the CF elements.
*
* Where feasible, the interface should be operated with signature
* control, so that, if the IRIG signal is lost or malformed, the
* interface produces an unmodulated signal, rather than possibly random
* digits. The driver will declare "unsynchronized" in this case.
*
* Spectracom Netclock/2 WWVB Synchronized Clock
*
* Element CF Function
* -------------------------------------
* 55 6 time sync status
* 60-63 10-13 bcd year units
* 65-68 15-18 bcd year tens
*
*/
/*
* IRIG interface definitions
*/
/*
* Imported from ntp_timer module
*/
/*
* Imported from ntpd module
*/
extern int debug; /* global debug flag */
/*
* Function prototypes
*/
static int irig_start P((int, struct peer *));
static void irig_shutdown P((int, struct peer *));
/*
* Transfer vector
*/
struct refclock refclock_irig = {
irig_start, /* start up driver */
irig_shutdown, /* shut down driver */
irig_poll, /* transmit poll message */
noentry, /* not used (old irig_control) */
noentry, /* initialize driver (not used) */
noentry, /* not used (old irig_buginfo) */
NOFLAGS /* not used */
};
/*
* irig_start - open the device and initialize data for processing
*/
static int
int unit;
{
register struct refclockproc *pp;
char device[20];
int fd;
int format = IRIG_FORMAT;
/*
* Open audio device and set format
*/
if (fd == -1) {
return (0);
}
return (0);
}
DEVICE);
return (0);
}
/*
* Initialize miscellaneous variables
*/
return (1);
}
/*
* irig_shutdown - shut down the clock
*/
static void
int unit;
{
struct refclockproc *pp;
}
/*
* irig_poll - called by the transmit procedure
*/
static void
int unit;
{
struct refclockproc *pp;
int i;
return;
}
#ifdef DEBUG
if (debug) {
printf("irig: ");
for (i = 0; i < sizeof(buf); i++)
printf("\n");
}
#endif
*--dp = '\0';
#ifdef DEBUG
if (debug)
printf("irig: time %s timecode %d %s\n",
pp->a_lastcode);
#endif
/*
* Get IRIG time and convert to timestamp format
*/
return;
}
} 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;
}
}
#else /* not (REFCLOCK && IRIG) */
int refclock_irig_bs;
#endif /* not (REFCLOCK && IRIG) */