FreeBSD/contrib/ntp/ntpd/refclock_ripencc.c
/*
 * Parse comprehensive time packet 
 *
 *  0 = success
 * -1 = errors
 */
Parse comprehensive time packet
0 = success
-1 = errors
Parse comprehensive time packet 0 = success - 1 = errors
int
parse0x8F0B(
	    TSIPPKT *rpt,
	    struct peer *peer
	    )
{
	register struct refclockproc *pp;	
	unsigned day, month, year;	
	unsigned hour, minute, second;
	unsigned utcoff;
	unsigned char mode;
	double  bias, rate;
	float biasunc, rateunc;
	double lat, lon, alt;
	short lat_deg, lon_deg;
	float lat_min, lon_min;
	unsigned char north_south, east_west;
	char sv[9];
   	static char logbuf[1024];	
	unsigned char b;
	int i;
	unsigned char *buf;
	double tow;
	buf = rpt->buf;
	pp = peer->procptr;
	if (rpt->len != 74) 
		return (-1);
	if (bGetShort(&buf[1]) != 0)
		return(-1);;
	tow =  bGetDouble(&buf[3]);
	if (tow == -1.0) {
		return(-1);
	}
	else if ((tow >= 604800.0) || (tow < 0.0)) {
		return(-1);
	}
	else
	{
		if (tow < 604799.9) tow = tow + .00000001;
		second = (unsigned int) fmod(tow, 60.);
		minute =  (unsigned int) fmod(tow/60., 60.);
		hour = (unsigned int )fmod(tow / 3600., 24.);
	} 
	day =		(unsigned int) buf[11];
	month =		(unsigned int) buf[12];
	year =		bGetShort(&buf[13]);
	mode =		buf[15];
	utcoff =	bGetShort(&buf[16]);
	bias = 		bGetDouble(&buf[18]) / GPS_C * 1e9;	
	rate = 		bGetDouble(&buf[26]) / GPS_C * 1e9;	 
	biasunc = 	bGetSingle(&buf[34]) / GPS_C * 1e9;	
	rateunc = 	bGetSingle(&buf[38]) / GPS_C * 1e9;	
	lat = 		bGetDouble(&buf[42]) * R2D;
	lon = 		bGetDouble(&buf[50]) * R2D;
	alt = 		bGetDouble(&buf[58]);
	if (lat < 0.0) {
		north_south = 'S';
		lat = -lat;
	}
	else {
		north_south = 'N';
	}
	lat_deg = (short)lat;
	lat_min = (lat - lat_deg) * 60.0;
	if (lon < 0.0) {
		east_west = 'W';
		lon = -lon;
	}
	else {
		east_west = 'E';
	}
	lon_deg = (short)lon;
	lon_min = (lon - lon_deg) * 60.0;
	for (i=0; i<8; i++) {
		sv[i] = buf[i + 66];
		if (sv[i]) {
			TSIPPKT spt; 
			b = (unsigned char) (sv[i]<0 ? -sv[i] : sv[i]);
			cmd_0x3C  (&spt, b);
			ripencc_send(peer,spt);
		}
	}
	sprintf(logbuf, "C1 %02d%02d%04d %02d%02d%02d %d %7.0f %.1f %.0f %.1f %d %02d%09.6f %c %02d%09.6f %c %.0f  %d %d %d %d %d %d %d %d",
		day, month, year, hour, minute, second, mode, bias, biasunc,
		rate, rateunc, utcoff, lat_deg, lat_min, north_south, lon_deg,
		lon_min, east_west, alt, sv[0], sv[1], sv[2], sv[3], sv[4],
		sv[5], sv[6], sv[7]);
#ifdef DEBUG_NCC
	if (debug) 
   		puts(logbuf);
#endif 
	record_clock_stats(&peer->srcadr, logbuf);
	return (0);
}
int parse0x8F0B ( TSIPPKT * rpt , struct peer * peer ) { register struct refclockproc * pp ; unsigned day , month , year ; unsigned hour , minute , second ; unsigned utcoff ; unsigned char mode ; double bias , rate ; float biasunc , rateunc ; double lat , lon , alt ; short lat_deg , lon_deg ; float lat_min , lon_min ; unsigned char north_south , east_west ; char sv [ 9 ] ; static char logbuf [ 1024 ] ; unsigned char b ; int i ; unsigned char * buf ; double tow ; buf = rpt -> buf ; pp = peer -> procptr ; if ( rpt -> len != 74 ) return ( -1 ) ; if ( bGetShort ( & buf [ 1 ] ) != 0 ) return ( -1 ) ; ; tow = bGetDouble ( & buf [ 3 ] ) ; if ( tow == -1.0 ) { return ( -1 ) ; } else if ( ( tow >= 604800.0 ) || ( tow < 0.0 ) ) { return ( -1 ) ; } else { if ( tow < 604799.9 ) tow = tow + .00000001 ; second = ( unsigned int ) fmod ( tow , 60. ) ; minute = ( unsigned int ) fmod ( tow / 60. , 60. ) ; hour = ( unsigned int ) fmod ( tow / 3600. , 24. ) ; } day = ( unsigned int ) buf [ 11 ] ; month = ( unsigned int ) buf [ 12 ] ; year = bGetShort ( & buf [ 13 ] ) ; mode = buf [ 15 ] ; utcoff = bGetShort ( & buf [ 16 ] ) ; bias = bGetDouble ( & buf [ 18 ] ) / GPS_C * 1e9 ; rate = bGetDouble ( & buf [ 26 ] ) / GPS_C * 1e9 ; biasunc = bGetSingle ( & buf [ 34 ] ) / GPS_C * 1e9 ; rateunc = bGetSingle ( & buf [ 38 ] ) / GPS_C * 1e9 ; lat = bGetDouble ( & buf [ 42 ] ) * R2D ; lon = bGetDouble ( & buf [ 50 ] ) * R2D ; alt = bGetDouble ( & buf [ 58 ] ) ; if ( lat < 0.0 ) { north_south = ' ' ; lat = - lat ; } else { north_south = ' ' ; } lat_deg = ( short ) lat ; lat_min = ( lat - lat_deg ) * 60.0 ; if ( lon < 0.0 ) { east_west = ' ' ; lon = - lon ; } else { east_west = ' ' ; } lon_deg = ( short ) lon ; lon_min = ( lon - lon_deg ) * 60.0 ; for ( i = 0 ; i < 8 ; i ++ ) { sv [ i ] = buf [ i + 66 ] ; if ( sv [ i ] ) { TSIPPKT spt ; b = ( unsigned char ) ( sv [ i ] < 0 ? - sv [ i ] : sv [ i ] ) ; cmd_0x3C ( & spt , b ) ; ripencc_send ( peer , spt ) ; } } sprintf ( logbuf , " " , day , month , year , hour , minute , second , mode , bias , biasunc , rate , rateunc , utcoff , lat_deg , lat_min , north_south , lon_deg , lon_min , east_west , alt , sv [ 0 ] , sv [ 1 ] , sv [ 2 ] , sv [ 3 ] , sv [ 4 ] , sv [ 5 ] , sv [ 6 ] , sv [ 7 ] ) ; #ifdef DEBUG_NCC if ( debug ) puts ( logbuf ) ; #endif record_clock_stats ( & peer -> srcadr , logbuf ) ; return ( 0 ) ; }
Parse comprehensive time packet
  0 = success
 -1 = errors
Parse comprehensive time packet 0 = success - 1 = errors
/* data derived from received timecode */ /* logging string buffer */ /* ns */ /* ppb */ /* ns */ /* ppb */ /* local structure for sendpacket */ /* request tracking status */ /* DEBUG_NCC */