FreeBSD/contrib/ntp/ntpd/refclock_wwv.c
/*
 * wwv_newchan - change to new data channel
 *
 * The radio actually appears to have ten channels, one channel for each
 * of five frequencies and each of two stations (WWV and WWVH), although
 * if not tunable only the DCHAN channel appears live. While the radio
 * is tuned to the working data channel frequency and station for most
 * of the minute, during seconds 59, 0 and 1 the radio is tuned to a
 * probe frequency in order to search for minute sync pulse and data
 * subcarrier from other transmitters.
 *
 * The search for WWV and WWVH operates simultaneously, with WWV minute
 * sync pulse at 1000 Hz and WWVH at 1200 Hz. The probe frequency
 * rotates each minute over 2.5, 5, 10, 15 and 20 MHz in order and yes,
 * we all know WWVH is dark on 20 MHz, but few remember when WWV was lit
 * on 25 MHz.
 *
 * This routine selects the best channel using a metric computed from
 * the reachability register and minute pulse amplitude. Normally, the
 * award goes to the the channel with the highest metric; but, in case
 * of ties, the award goes to the channel with the highest minute sync
 * pulse amplitude and then to the highest frequency.
 *
 * The routine performs an important squelch function to keep dirty data
 * from polluting the integrators. In order to consider a station valid,
 * the metric must be at least MTHR (13); otherwise, the station select
 * bits are cleared so the second sync is disabled and the data bit
 * integrators averaged to a miss. 
 */
change to new data channel
The radio actually appears to have ten channels, one channel for each
of five frequencies and each of two stations (WWV and WWVH), although
if not tunable only the DCHAN channel appears live. While the radio
is tuned to the working data channel frequency and station for most
of the minute, during seconds 59, 0 and 1 the radio is tuned to a
probe frequency in order to search for minute sync pulse and data
subcarrier from other transmitters.

The search for WWV and WWVH operates simultaneously, with WWV minute
sync pulse at 1000 Hz and WWVH at 1200 Hz. The probe frequency
rotates each minute over 2.5, 5, 10, 15 and 20 MHz in order and yes,
we all know WWVH is dark on 20 MHz, but few remember when WWV was lit
on 25 MHz.

This routine selects the best channel using a metric computed from
the reachability register and minute pulse amplitude. Normally, the
award goes to the the channel with the highest metric; but, in case
of ties, the award goes to the channel with the highest minute sync
pulse amplitude and then to the highest frequency.

The routine performs an important squelch function to keep dirty data
from polluting the integrators. In order to consider a station valid,
the metric must be at least MTHR (13); otherwise, the station select
bits are cleared so the second sync is disabled and the data bit
integrators averaged to a miss.
change to new data channel The radio actually appears to have ten channels one channel for each of five frequencies and each of two stations ( WWV and WWVH ) although if not tunable only the DCHAN channel appears live . While the radio is tuned to the working data channel frequency and station for most of the minute during seconds 59 0 and 1 the radio is tuned to a probe frequency in order to search for minute sync pulse and data subcarrier from other transmitters . The search for WWV and WWVH operates simultaneously with WWV minute sync pulse at 1000 Hz and WWVH at 1200 Hz . The probe frequency rotates each minute over 2 . 5 5 10 15 and 20 MHz in order and yes we all know WWVH is dark on 20 MHz but few remember when WWV was lit on 25 MHz . This routine selects the best channel using a metric computed from the reachability register and minute pulse amplitude . Normally the award goes to the the channel with the highest metric ; but in case of ties the award goes to the channel with the highest minute sync pulse amplitude and then to the highest frequency . The routine performs an important squelch function to keep dirty data from polluting the integrators . In order to consider a station valid the metric must be at least MTHR ( 13 ) ; otherwise the station select bits are cleared so the second sync is disabled and the data bit integrators averaged to a miss .
static int
wwv_newchan(
	struct peer *peer	
	)
{
	struct refclockproc *pp;
	struct wwvunit *up;
	struct sync *sp, *rp;
	double rank, dtemp;
	int i, j, rval;
	pp = peer->procptr;
	up = pp->unitptr;
	sp = NULL;
	j = 0;
	rank = 0;
	for (i = 0; i < NCHAN; i++) {
		rp = &up->mitig[i].wwvh;
		dtemp = rp->metric;
		if (dtemp >= rank) {
			rank = dtemp;
			sp = rp;
			j = i;
		}
		rp = &up->mitig[i].wwv;
		dtemp = rp->metric;
		if (dtemp >= rank) {
			rank = dtemp;
			sp = rp;
			j = i;
		}
	}
	up->status &= ~(SELV | SELH);
	if (rank < MTHR) {
		up->dchan = (up->dchan + 1) % NCHAN;
		if (up->status & METRIC) {
			up->status &= ~METRIC;
			refclock_report(peer, CEVNT_PROP);
		}
		rval = FALSE;
	} else {
		up->dchan = j;
		up->sptr = sp;
		memcpy(&pp->refid, sp->refid, 4);
		peer->refid = pp->refid;
		up->status |= METRIC;
		if (sp->select & SELV) {
			up->status |= SELV;
			up->pdelay = pp->fudgetime1;
		} else if (sp->select & SELH) {
			up->status |= SELH;
			up->pdelay = pp->fudgetime2;
		} else {
			up->pdelay = 0;
		}
		rval = TRUE;
	}
#ifdef ICOM
	if (up->fd_icom > 0)
		wwv_qsy(peer, up->dchan);
#endif 
	return (rval);
}
static int wwv_newchan ( struct peer * peer ) { struct refclockproc * pp ; struct wwvunit * up ; struct sync * sp , * rp ; double rank , dtemp ; int i , j , rval ; pp = peer -> procptr ; up = pp -> unitptr ; sp = NULL ; j = 0 ; rank = 0 ; for ( i = 0 ; i < NCHAN ; i ++ ) { rp = & up -> mitig [ i ] . wwvh ; dtemp = rp -> metric ; if ( dtemp >= rank ) { rank = dtemp ; sp = rp ; j = i ; } rp = & up -> mitig [ i ] . wwv ; dtemp = rp -> metric ; if ( dtemp >= rank ) { rank = dtemp ; sp = rp ; j = i ; } } up -> status &= ~ ( SELV | SELH ) ; if ( rank < MTHR ) { up -> dchan = ( up -> dchan + 1 ) % NCHAN ; if ( up -> status & METRIC ) { up -> status &= ~ METRIC ; refclock_report ( peer , CEVNT_PROP ) ; } rval = FALSE ; } else { up -> dchan = j ; up -> sptr = sp ; memcpy ( & pp -> refid , sp -> refid , 4 ) ; peer -> refid = pp -> refid ; up -> status |= METRIC ; if ( sp -> select & SELV ) { up -> status |= SELV ; up -> pdelay = pp -> fudgetime1 ; } else if ( sp -> select & SELH ) { up -> status |= SELH ; up -> pdelay = pp -> fudgetime2 ; } else { up -> pdelay = 0 ; } rval = TRUE ; } #ifdef ICOM if ( up -> fd_icom > 0 ) wwv_qsy ( peer , up -> dchan ) ; #endif return ( rval ) ; }
wwv_newchan - change to new data channel
 The radio actually appears to have ten channels, one channel for each
 of five frequencies and each of two stations (WWV and WWVH), although
 if not tunable only the DCHAN channel appears live.
wwv_newchan - change to new data channel The radio actually appears to have ten channels one channel for each of five frequencies and each of two stations ( WWV and WWVH ) although if not tunable only the DCHAN channel appears live .
/* peer structure pointer */ /*
	 * Search all five station pairs looking for the channel with
	 * maximum metric.
	 */ /*
	 * If the strongest signal is less than the MTHR threshold (13),
	 * we are beneath the waves, so squelch the second sync and
	 * advance to the next station. This makes sure all stations are
	 * scanned when the ions grow dim. If the strongest signal is
	 * greater than the threshold, tune to that frequency and
	 * transmitter QTH.
	 */ /* ICOM */