FreeBSD/contrib/ntp/ntpd/refclock_wwv.c
/*
 * wwv_start - open the devices and initialize data for processing
 */
open the devices and initialize data for processing
open the devices and initialize data for processing
static int
wwv_start(
	int	unit,		
	struct peer *peer	
	)
{
	struct refclockproc *pp;
	struct wwvunit *up;
#ifdef ICOM
	int	temp;
#endif 
	int	fd;		
	int	i;		
	double	step;		
	fd = audio_init(DEVICE_AUDIO, AUDIO_BUFSIZ, unit);
	if (fd < 0)
		return (0);
#ifdef DEBUG
	if (debug)
		audio_show();
#endif 
	up = emalloc_zero(sizeof(*up));
	pp = peer->procptr;
	pp->io.clock_recv = wwv_receive;
	pp->io.srcclock = peer;
	pp->io.datalen = 0;
	pp->io.fd = fd;
	if (!io_addclock(&pp->io)) {
		close(fd);
		free(up);
		return (0);
	}
	pp->unitptr = up;
	peer->precision = PRECISION;
	pp->clockdesc = DESCRIPTION;
	up->comp[0] = up->comp[OFFSET] = 0.;
	up->comp[1] = 1.; up->comp[OFFSET + 1] = -1.;
	up->comp[2] = 3.; up->comp[OFFSET + 2] = -3.;
	step = 2.;
	for (i = 3; i < OFFSET; i++) {
		up->comp[i] = up->comp[i - 1] + step;
		up->comp[OFFSET + i] = -up->comp[i];
		if (i % 16 == 0)
			step *= 2.;
	}
	DTOLFP(1. / WWV_SEC, &up->tick);
	up->decvec[MN].radix = 10;	
	up->decvec[MN + 1].radix = 6;
	up->decvec[HR].radix = 10;	
	up->decvec[HR + 1].radix = 3;
	up->decvec[DA].radix = 10;	
	up->decvec[DA + 1].radix = 10;
	up->decvec[DA + 2].radix = 4;
	up->decvec[YR].radix = 10;	
	up->decvec[YR + 1].radix = 10;
#ifdef ICOM
	temp = 0;
#ifdef DEBUG
	if (debug > 1)
		temp = P_TRACE;
#endif 
	if (peer->ttl != 0) {
		if (peer->ttl & 0x80)
			up->fd_icom = icom_init("/dev/icom", B1200,
			    temp);
		else
			up->fd_icom = icom_init("/dev/icom", B9600,
			    temp);
	}
	if (up->fd_icom > 0) {
		if (wwv_qsy(peer, DCHAN) != 0) {
			msyslog(LOG_NOTICE, "icom: radio not found");
			close(up->fd_icom);
			up->fd_icom = 0;
		} else {
			msyslog(LOG_NOTICE, "icom: autotune enabled");
		}
	}
#endif 
	wwv_newgame(peer);
	return (1);
}
static int wwv_start ( int unit , struct peer * peer ) { struct refclockproc * pp ; struct wwvunit * up ; #ifdef ICOM int temp ; #endif int fd ; int i ; double step ; fd = audio_init ( DEVICE_AUDIO , AUDIO_BUFSIZ , unit ) ; if ( fd < 0 ) return ( 0 ) ; #ifdef DEBUG if ( debug ) audio_show ( ) ; #endif up = emalloc_zero ( sizeof ( * up ) ) ; pp = peer -> procptr ; pp -> io . clock_recv = wwv_receive ; pp -> io . srcclock = peer ; pp -> io . datalen = 0 ; pp -> io . fd = fd ; if ( ! io_addclock ( & pp -> io ) ) { close ( fd ) ; free ( up ) ; return ( 0 ) ; } pp -> unitptr = up ; peer -> precision = PRECISION ; pp -> clockdesc = DESCRIPTION ; up -> comp [ 0 ] = up -> comp [ OFFSET ] = 0. ; up -> comp [ 1 ] = 1. ; up -> comp [ OFFSET + 1 ] = -1. ; up -> comp [ 2 ] = 3. ; up -> comp [ OFFSET + 2 ] = -3. ; step = 2. ; for ( i = 3 ; i < OFFSET ; i ++ ) { up -> comp [ i ] = up -> comp [ i - 1 ] + step ; up -> comp [ OFFSET + i ] = - up -> comp [ i ] ; if ( i % 16 == 0 ) step *= 2. ; } DTOLFP ( 1. / WWV_SEC , & up -> tick ) ; up -> decvec [ MN ] . radix = 10 ; up -> decvec [ MN + 1 ] . radix = 6 ; up -> decvec [ HR ] . radix = 10 ; up -> decvec [ HR + 1 ] . radix = 3 ; up -> decvec [ DA ] . radix = 10 ; up -> decvec [ DA + 1 ] . radix = 10 ; up -> decvec [ DA + 2 ] . radix = 4 ; up -> decvec [ YR ] . radix = 10 ; up -> decvec [ YR + 1 ] . radix = 10 ; #ifdef ICOM temp = 0 ; #ifdef DEBUG if ( debug > 1 ) temp = P_TRACE ; #endif if ( peer -> ttl != 0 ) { if ( peer -> ttl & 0x80 ) up -> fd_icom = icom_init ( " " , B1200 , temp ) ; else up -> fd_icom = icom_init ( " " , B9600 , temp ) ; } if ( up -> fd_icom > 0 ) { if ( wwv_qsy ( peer , DCHAN ) != 0 ) { msyslog ( LOG_NOTICE , " " ) ; close ( up -> fd_icom ) ; up -> fd_icom = 0 ; } else { msyslog ( LOG_NOTICE , " " ) ; } } #endif wwv_newgame ( peer ) ; return ( 1 ) ; }
wwv_start - open the devices and initialize data for processing
wwv_start - open the devices and initialize data for processing
/* instance number (used by PCM) */ /* peer structure pointer */ /* ICOM */ /*
	 * Local variables
	 */ /* file descriptor */ /* index */ /* codec adjustment */ /*
	 * Open audio device
	 */ /* DEBUG */ /*
	 * Allocate and initialize unit structure
	 */ /*
	 * Initialize miscellaneous variables
	 */ /*
	 * The companded samples are encoded sign-magnitude. The table
	 * contains all the 256 values in the interest of speed.
	 */ /*
	 * Initialize the decoding matrix with the radix for each digit
	 * position.
	 */ /* minutes */ /* hours */ /* days */ /* years */ /*
	 * Initialize autotune if available. Note that the ICOM select
	 * code must be less than 128, so the high order bit can be used
	 * to select the line speed 0 (9600 bps) or 1 (1200 bps). Note
	 * we don't complain if the ICOM device is not there; but, if it
	 * is, the radio better be working.
	 */ /* DEBUG */ /* ICOM */ /*
	 * Let the games begin.
	 */