FreeBSD/contrib/ntp/ntpd/refclock_ripencc.c
/*
 * This function is called every 64 seconds from ripencc_receive
 * It will fetch the pps time 
 *
 * Return 0 on failure and 1 on success.
 */
This function is called every 64 seconds from ripencc_receive
It will fetch the pps time

Return 0 on failure and 1 on success.
This function is called every 64 seconds from ripencc_receive It will fetch the pps time Return 0 on failure and 1 on success .
static int
ripencc_get_pps_ts(
	struct ripencc_unit *up,
	l_fp *tsptr
	)
{
	pps_info_t pps_info;
	struct timespec timeout, ts;
	double dtemp;
	l_fp tstmp;
#ifdef DEBUG_PPS
	msyslog(LOG_INFO,"ripencc_get_pps_ts");
#endif 
	if (up->handle == 0)
		return (0);
	timeout.tv_sec = 0;
	timeout.tv_nsec = 0;
	memcpy(&pps_info, &up->pps_info, sizeof(pps_info_t));
	if (time_pps_fetch(up->handle, PPS_TSFMT_TSPEC, &up->pps_info,
			   &timeout) < 0)
		return (0);
	if (up->pps_params.mode & PPS_CAPTUREASSERT) {
		if (pps_info.assert_sequence ==
		    up->pps_info.assert_sequence)
			return (0);
		ts = up->pps_info.assert_timestamp;
	} else if (up->pps_params.mode & PPS_CAPTURECLEAR) {
		if (pps_info.clear_sequence ==
		    up->pps_info.clear_sequence)
			return (0);
		ts = up->pps_info.clear_timestamp;
	} else {
		return (0);
	}
	if ((up->ts.tv_sec == ts.tv_sec) && (up->ts.tv_nsec == ts.tv_nsec))
		return (0);
	up->ts = ts;
	tstmp.l_ui = ts.tv_sec + JAN_1970;
	dtemp = ts.tv_nsec * FRAC / 1e9;
	tstmp.l_uf = (u_int32)dtemp;
#ifdef DEBUG_PPS
	msyslog(LOG_INFO,"ts.tv_sec: %d",(int)ts.tv_sec);
	msyslog(LOG_INFO,"ts.tv_nsec: %ld",ts.tv_nsec);
#endif 
	*tsptr = tstmp;
	return (1);
}
static int ripencc_get_pps_ts ( struct ripencc_unit * up , l_fp * tsptr ) { pps_info_t pps_info ; struct timespec timeout , ts ; double dtemp ; l_fp tstmp ; #ifdef DEBUG_PPS msyslog ( LOG_INFO , " " ) ; #endif if ( up -> handle == 0 ) return ( 0 ) ; timeout . tv_sec = 0 ; timeout . tv_nsec = 0 ; memcpy ( & pps_info , & up -> pps_info , sizeof ( pps_info_t ) ) ; if ( time_pps_fetch ( up -> handle , PPS_TSFMT_TSPEC , & up -> pps_info , & timeout ) < 0 ) return ( 0 ) ; if ( up -> pps_params . mode & PPS_CAPTUREASSERT ) { if ( pps_info . assert_sequence == up -> pps_info . assert_sequence ) return ( 0 ) ; ts = up -> pps_info . assert_timestamp ; } else if ( up -> pps_params . mode & PPS_CAPTURECLEAR ) { if ( pps_info . clear_sequence == up -> pps_info . clear_sequence ) return ( 0 ) ; ts = up -> pps_info . clear_timestamp ; } else { return ( 0 ) ; } if ( ( up -> ts . tv_sec == ts . tv_sec ) && ( up -> ts . tv_nsec == ts . tv_nsec ) ) return ( 0 ) ; up -> ts = ts ; tstmp . l_ui = ts . tv_sec + JAN_1970 ; dtemp = ts . tv_nsec * FRAC / 1e9 ; tstmp . l_uf = ( u_int32 ) dtemp ; #ifdef DEBUG_PPS msyslog ( LOG_INFO , " " , ( int ) ts . tv_sec ) ; msyslog ( LOG_INFO , " " , ts . tv_nsec ) ; #endif * tsptr = tstmp ; return ( 1 ) ; }
This function is called every 64 seconds from ripencc_receive
 It will fetch the pps time
This function is called every 64 seconds from ripencc_receive It will fetch the pps time
/* DEBUG_PPS */ /*
	 * Convert the timespec nanoseconds field to ntp l_fp units.
	 */ /* DEBUG_PPS */