FreeBSD/contrib/ntp/ntpd/refclock_wwv.c
/*
 * timecode - assemble timecode string and length
 *
 * Prettytime format - similar to Spectracom
 *
 * sq yy ddd hh:mm:ss ld dut lset agc iden sig errs freq avgt
 *
 * s	sync indicator ('?' or ' ')
 * q	error bits (hex 0-F)
 * yyyy	year of century
 * ddd	day of year
 * hh	hour of day
 * mm	minute of hour
 * ss	second of minute)
 * l	leap second warning (' ' or 'L')
 * d	DST state ('S', 'D', 'I', or 'O')
 * dut	DUT sign and magnitude (0.1 s)
 * lset	minutes since last clock update
 * agc	audio gain (0-255)
 * iden	reference identifier (station and frequency)
 * sig	signal quality (0-100)
 * errs	bit errors in last minute
 * freq	frequency offset (PPM)
 * avgt	averaging time (s)
 */
assemble timecode string and length
Prettytime format - similar to Spectracom

sq yy ddd hh:mm:ss ld dut lset agc iden sig errs freq avgt


assemble timecode string and length Prettytime format - similar to Spectracom sq yy ddd hh : mm : ss ld dut lset agc iden sig errs freq avgt
static int
timecode(
	struct wwvunit *up,	
	char *		tc,	
	size_t		tcsiz	
	)
{
	struct sync *sp;
	int year, day, hour, minute, second, dut;
	char synchar, leapchar, dst;
	char cptr[50];
	synchar = (up->status & INSYNC) ? ' ' : '?';
	year = up->decvec[YR].digit + up->decvec[YR + 1].digit * 10 +
	    2000;
	day = up->decvec[DA].digit + up->decvec[DA + 1].digit * 10 +
	    up->decvec[DA + 2].digit * 100;
	hour = up->decvec[HR].digit + up->decvec[HR + 1].digit * 10;
	minute = up->decvec[MN].digit + up->decvec[MN + 1].digit * 10;
	second = 0;
	leapchar = (up->misc & SECWAR) ? 'L' : ' ';
	dst = dstcod[(up->misc >> 4) & 0x3];
	dut = up->misc & 0x7;
	if (!(up->misc & DUTS))
		dut = -dut;
	snprintf(tc, tcsiz, "%c%1X", synchar, up->alarm);
	snprintf(cptr, sizeof(cptr),
		 " %4d %03d %02d:%02d:%02d %c%c %+d",
		 year, day, hour, minute, second, leapchar, dst, dut);
	strlcat(tc, cptr, tcsiz);
	sp = up->sptr;
	snprintf(cptr, sizeof(cptr), " %d %d %s %.0f %d %.1f %d",
		 up->watch, up->mitig[up->dchan].gain, sp->refid,
		 sp->metric, up->errcnt, up->freq / WWV_SEC * 1e6,
		 up->avgint);
	strlcat(tc, cptr, tcsiz);
	return strlen(tc);
}
static int timecode ( struct wwvunit * up , char * tc , size_t tcsiz ) { struct sync * sp ; int year , day , hour , minute , second , dut ; char synchar , leapchar , dst ; char cptr [ 50 ] ; synchar = ( up -> status & INSYNC ) ? ' ' : ' ' ; year = up -> decvec [ YR ] . digit + up -> decvec [ YR + 1 ] . digit * 10 + 2000 ; day = up -> decvec [ DA ] . digit + up -> decvec [ DA + 1 ] . digit * 10 + up -> decvec [ DA + 2 ] . digit * 100 ; hour = up -> decvec [ HR ] . digit + up -> decvec [ HR + 1 ] . digit * 10 ; minute = up -> decvec [ MN ] . digit + up -> decvec [ MN + 1 ] . digit * 10 ; second = 0 ; leapchar = ( up -> misc & SECWAR ) ? ' ' : ' ' ; dst = dstcod [ ( up -> misc >> 4 ) & 0x3 ] ; dut = up -> misc & 0x7 ; if ( ! ( up -> misc & DUTS ) ) dut = - dut ; snprintf ( tc , tcsiz , " " , synchar , up -> alarm ) ; snprintf ( cptr , sizeof ( cptr ) , " " , year , day , hour , minute , second , leapchar , dst , dut ) ; strlcat ( tc , cptr , tcsiz ) ; sp = up -> sptr ; snprintf ( cptr , sizeof ( cptr ) , " " , up -> watch , up -> mitig [ up -> dchan ] . gain , sp -> refid , sp -> metric , up -> errcnt , up -> freq / WWV_SEC * 1e6 , up -> avgint ) ; strlcat ( tc , cptr , tcsiz ) ; return strlen ( tc ) ; }
timecode - assemble timecode string and length
 Prettytime format - similar to Spectracom
timecode - assemble timecode string and length Prettytime format - similar to Spectracom
/* driver structure pointer */ /* target string */ /* target max chars */ /*
	 * Common fixed-format fields
	 */ /*
	 * Specific variable-format fields
	 */