FreeBSD/contrib/ntp/ntpd/refclock_wwv.c
/*
 * The radio clock is set if the alarm bits are all zero. After that,
 * the time is considered valid if the second sync bit is lit. It should
 * not be a surprise, especially if the radio is not tunable, that
 * sometimes no stations are above the noise and the integrators
 * discharge below the thresholds. We assume that, after a day of signal
 * loss, the minute sync epoch will be in the same second. This requires
 * the codec frequency be accurate within 6 PPM. Practical experience
 * shows the frequency typically within 0.1 PPM, so after a day of
 * signal loss, the time should be within 8.6 ms.. 
 */
The radio clock is set if the alarm bits are all zero. After that,
the time is considered valid if the second sync bit is lit. It should
not be a surprise, especially if the radio is not tunable, that
sometimes no stations are above the noise and the integrators
discharge below the thresholds. We assume that, after a day of signal
loss, the minute sync epoch will be in the same second. This requires
the codec frequency be accurate within 6 PPM. Practical experience
shows the frequency typically within 0.1 PPM, so after a day of
signal loss, the time should be within 8.6 ms
The radio clock is set if the alarm bits are all zero . After that the time is considered valid if the second sync bit is lit . It should not be a surprise especially if the radio is not tunable that sometimes no stations are above the noise and the integrators discharge below the thresholds . We assume that after a day of signal loss the minute sync epoch will be in the same second . This requires the codec frequency be accurate within 6 PPM . Practical experience shows the frequency typically within 0 . 1 PPM so after a day of signal loss the time should be within 8 . 6 ms
static void
wwv_clock(
	struct peer *peer	
	)
{
	struct refclockproc *pp;
	struct wwvunit *up;
	l_fp	offset;		
	pp = peer->procptr;
	up = pp->unitptr;
	if (!(up->status & SSYNC))
		up->alarm |= SYNERR;
	if (up->digcnt < 9)
		up->alarm |= NINERR;
	if (!(up->alarm))
		up->status |= INSYNC;
	if (up->status & INSYNC && up->status & SSYNC) {
		if (up->misc & SECWAR)
			pp->leap = LEAP_ADDSECOND;
		else
			pp->leap = LEAP_NOWARNING;
		pp->second = up->rsec;
		pp->minute = up->decvec[MN].digit + up->decvec[MN +
		    1].digit * 10;
		pp->hour = up->decvec[HR].digit + up->decvec[HR +
		    1].digit * 10;
		pp->day = up->decvec[DA].digit + up->decvec[DA +
		    1].digit * 10 + up->decvec[DA + 2].digit * 100;
		pp->year = up->decvec[YR].digit + up->decvec[YR +
		    1].digit * 10;
		pp->year += 2000;
		L_CLR(&offset);
		if (!clocktime(pp->day, pp->hour, pp->minute,
		    pp->second, GMT, up->timestamp.l_ui,
		    &pp->yearstart, &offset.l_ui)) {
			up->errflg = CEVNT_BADTIME;
		} else {
			up->watch = 0;
			pp->disp = 0;
			pp->lastref = up->timestamp;
			refclock_process_offset(pp, offset,
			    up->timestamp, PDELAY + up->pdelay);
			refclock_receive(peer);
		}
	}
	pp->lencode = timecode(up, pp->a_lastcode,
			       sizeof(pp->a_lastcode));
	record_clock_stats(&peer->srcadr, pp->a_lastcode);
#ifdef DEBUG
	if (debug)
		printf("wwv: timecode %d %s\n", pp->lencode,
		    pp->a_lastcode);
#endif 
}
static void wwv_clock ( struct peer * peer ) { struct refclockproc * pp ; struct wwvunit * up ; l_fp offset ; pp = peer -> procptr ; up = pp -> unitptr ; if ( ! ( up -> status & SSYNC ) ) up -> alarm |= SYNERR ; if ( up -> digcnt < 9 ) up -> alarm |= NINERR ; if ( ! ( up -> alarm ) ) up -> status |= INSYNC ; if ( up -> status & INSYNC && up -> status & SSYNC ) { if ( up -> misc & SECWAR ) pp -> leap = LEAP_ADDSECOND ; else pp -> leap = LEAP_NOWARNING ; pp -> second = up -> rsec ; pp -> minute = up -> decvec [ MN ] . digit + up -> decvec [ MN + 1 ] . digit * 10 ; pp -> hour = up -> decvec [ HR ] . digit + up -> decvec [ HR + 1 ] . digit * 10 ; pp -> day = up -> decvec [ DA ] . digit + up -> decvec [ DA + 1 ] . digit * 10 + up -> decvec [ DA + 2 ] . digit * 100 ; pp -> year = up -> decvec [ YR ] . digit + up -> decvec [ YR + 1 ] . digit * 10 ; pp -> year += 2000 ; L_CLR ( & offset ) ; if ( ! clocktime ( pp -> day , pp -> hour , pp -> minute , pp -> second , GMT , up -> timestamp . l_ui , & pp -> yearstart , & offset . l_ui ) ) { up -> errflg = CEVNT_BADTIME ; } else { up -> watch = 0 ; pp -> disp = 0 ; pp -> lastref = up -> timestamp ; refclock_process_offset ( pp , offset , up -> timestamp , PDELAY + up -> pdelay ) ; refclock_receive ( peer ) ; } } pp -> lencode = timecode ( up , pp -> a_lastcode , sizeof ( pp -> a_lastcode ) ) ; record_clock_stats ( & peer -> srcadr , pp -> a_lastcode ) ; #ifdef DEBUG if ( debug ) printf ( " \n " , pp -> lencode , pp -> a_lastcode ) ; #endif }
The radio clock is set if the alarm bits are all zero.
The radio clock is set if the alarm bits are all zero .
/* peer unit pointer */ /* offset in NTP seconds */ /* DEBUG */