FreeBSD/contrib/ntp/ntpd/refclock_ripencc.c
/*
 * Parse primary utc time packet
 * and fill refclock structure 
 * from results. 
 *
 * 0 = success
 * -1 = errors
 */
Parse primary utc time packet
and fill refclock structure
from results.

0 = success
-1 = errors
Parse primary utc time packet and fill refclock structure from results . 0 = success - 1 = errors
static int
parse0x8FAD(
	    TSIPPKT *rpt,
	    struct peer *peer
	    )
{
	register struct refclockproc *pp;	
	register struct ripencc_unit *up;
	unsigned day, month, year;	
	unsigned hour, minute, second;
	unsigned char trackstat, utcflags;
   	static char logbuf[1024];	
	int i;
	unsigned char *buf;
	buf = rpt->buf;
	pp = peer->procptr;
	if (rpt->len != 22) 
		return (-1);
	if (bGetShort(&buf[1]) != 0) {
#ifdef DEBUG_NCC
		if (debug) 
			printf("parse0x8FAD: event count != 0\n");
#endif 
		return(-1);
	}
	if (bGetDouble(&buf[3]) != 0.0) {
#ifdef DEBUG_NCC
		if (debug) 
			printf("parse0x8FAD: fracsecs != 0\n");
#endif 
		return(-1);
	}
	hour =		(unsigned int) buf[11];
	minute =	(unsigned int) buf[12];
	second =	(unsigned int) buf[13];
	day =		(unsigned int) buf[14];
	month =		(unsigned int) buf[15];
	year =		bGetShort(&buf[16]);
	trackstat =	buf[18];
	utcflags =	buf[19];
	sprintf(logbuf, "U1 %d.%d.%d %02d:%02d:%02d %d %02x",
		day, month, year, hour, minute, second, trackstat, utcflags);
#ifdef DEBUG_NCC
	if (debug) 
   		puts(logbuf);
#endif 
	record_clock_stats(&peer->srcadr, logbuf);
	if (!utcflags & UTCF_UTC_AVAIL)
		return(-1);
	up = (struct ripencc_unit *) pp->unitptr;
	if (utcflags != up->utcflags) {
		TSIPPKT spt;	
		cmd_0x2F (&spt); 
		ripencc_send(peer,spt);
		up->utcflags = utcflags;
	}
	if (second == 60)
		return(-1);
	pp->year = year;
	if (month < 1 || month > 12 || day < 1 || day > 31) 
		return(-1);
	if (pp->year % 4) {	
		if (day > day1tab[month - 1]) 
			return(-1);
		for (i = 0; i < month - 1; i++)
			day += day1tab[i];
	} else {
		if (day > day2tab[month - 1]) 
			return(-1);
		for (i = 0; i < month - 1; i++)
			day += day2tab[i];
	}
	pp->day = day;
	pp->hour = hour;
	pp->minute = minute;
	pp-> second = second;
	pp->nsec = 0;
	if ((utcflags&UTCF_LEAP_PNDG) && up->leapdelta != 0) 
		pp-> leap = (up->leapdelta > 0)
		    ? LEAP_ADDSECOND
		    : LEAP_DELSECOND; 
	else
		pp-> leap = LEAP_NOWARNING;  
	return (0);
}
static int parse0x8FAD ( TSIPPKT * rpt , struct peer * peer ) { register struct refclockproc * pp ; register struct ripencc_unit * up ; unsigned day , month , year ; unsigned hour , minute , second ; unsigned char trackstat , utcflags ; static char logbuf [ 1024 ] ; int i ; unsigned char * buf ; buf = rpt -> buf ; pp = peer -> procptr ; if ( rpt -> len != 22 ) return ( -1 ) ; if ( bGetShort ( & buf [ 1 ] ) != 0 ) { #ifdef DEBUG_NCC if ( debug ) printf ( " \n " ) ; #endif return ( -1 ) ; } if ( bGetDouble ( & buf [ 3 ] ) != 0.0 ) { #ifdef DEBUG_NCC if ( debug ) printf ( " \n " ) ; #endif return ( -1 ) ; } hour = ( unsigned int ) buf [ 11 ] ; minute = ( unsigned int ) buf [ 12 ] ; second = ( unsigned int ) buf [ 13 ] ; day = ( unsigned int ) buf [ 14 ] ; month = ( unsigned int ) buf [ 15 ] ; year = bGetShort ( & buf [ 16 ] ) ; trackstat = buf [ 18 ] ; utcflags = buf [ 19 ] ; sprintf ( logbuf , " " , day , month , year , hour , minute , second , trackstat , utcflags ) ; #ifdef DEBUG_NCC if ( debug ) puts ( logbuf ) ; #endif record_clock_stats ( & peer -> srcadr , logbuf ) ; if ( ! utcflags & UTCF_UTC_AVAIL ) return ( -1 ) ; up = ( struct ripencc_unit * ) pp -> unitptr ; if ( utcflags != up -> utcflags ) { TSIPPKT spt ; cmd_0x2F ( & spt ) ; ripencc_send ( peer , spt ) ; up -> utcflags = utcflags ; } if ( second == 60 ) return ( -1 ) ; pp -> year = year ; if ( month < 1 || month > 12 || day < 1 || day > 31 ) return ( -1 ) ; if ( pp -> year % 4 ) { if ( day > day1tab [ month - 1 ] ) return ( -1 ) ; for ( i = 0 ; i < month - 1 ; i ++ ) day += day1tab [ i ] ; } else { if ( day > day2tab [ month - 1 ] ) return ( -1 ) ; for ( i = 0 ; i < month - 1 ; i ++ ) day += day2tab [ i ] ; } pp -> day = day ; pp -> hour = hour ; pp -> minute = minute ; pp -> second = second ; pp -> nsec = 0 ; if ( ( utcflags & UTCF_LEAP_PNDG ) && up -> leapdelta != 0 ) pp -> leap = ( up -> leapdelta > 0 ) ? LEAP_ADDSECOND : LEAP_DELSECOND ; else pp -> leap = LEAP_NOWARNING ; return ( 0 ) ; }
Parse primary utc time packet
 and fill refclock structure
 from results.
Parse primary utc time packet and fill refclock structure from results .
/* data derived from received timecode */ /* logging string buffer */ /* DEBUG_NCC */ /* DEBUG_NCC */ /* DEBUG_NCC */ /* poll for UTC parameters once and then if UTC flag changed */ /* local structure for send packet */ /* request UTC params */ /*
	 * If we hit the leap second, we choose to skip this sample
	 * rather than rely on other code to be perfectly correct.
	 * No offense, just defense ;-).
	 */ /* now check and convert the time we received */ /* XXX: use is_leapyear() ? */