FreeBSD/contrib/ntp/ntpd/refclock_zyfer.c
/*
 * zyfer_receive - receive data from the serial interface
 */
receive data from the serial interface
receive data from the serial interface
static void
zyfer_receive(
	struct recvbuf *rbufp
	)
{
	register struct zyferunit *up;
	struct refclockproc *pp;
	struct peer *peer;
	int tmode;		
	int tfom;		
	int omode;		
	u_char *p;
	peer = rbufp->recv_peer;
	pp = peer->procptr;
	up = pp->unitptr;
	p = (u_char *) &rbufp->recv_space;
	if (pp->lencode >= LENZYFER)
		pp->lencode = 0;
	if (!pp->lencode) {
		if (*p == '!')
			pp->lencode = refclock_gtlin(rbufp, pp->a_lastcode,
						     BMAX, &pp->lastrec);
		else
			return;
	} else {
		memcpy(pp->a_lastcode + pp->lencode, p, rbufp->recv_length);
		pp->lencode += rbufp->recv_length;
		pp->a_lastcode[pp->lencode] = '\0';
	}
	if (pp->lencode < LENZYFER)
		return;
	record_clock_stats(&peer->srcadr, pp->a_lastcode);
	if (pp->lencode != LENZYFER) {
		refclock_report(peer, CEVNT_BADTIME);
		return;
	}
	if (sscanf(pp->a_lastcode, "!TIME,%4d,%3d,%2d,%2d,%2d,%d,%d,%d",
		   &pp->year, &pp->day, &pp->hour, &pp->minute, &pp->second,
		   &tmode, &tfom, &omode) != 8) {
		refclock_report(peer, CEVNT_BADREPLY);
		return;
	}
	if (tmode != 2) {
		refclock_report(peer, CEVNT_BADTIME);
		return;
	}
	if (omode != 1) {
		pp->leap = LEAP_NOTINSYNC;
		return;
	}
	if (!refclock_process(pp)) {
		refclock_report(peer, CEVNT_BADTIME);
		return;
        }
	up->pollcnt = 2;
	if (up->polled) {
		up->polled = 0;
		refclock_receive(peer);
	}
}
static void zyfer_receive ( struct recvbuf * rbufp ) { register struct zyferunit * up ; struct refclockproc * pp ; struct peer * peer ; int tmode ; int tfom ; int omode ; u_char * p ; peer = rbufp -> recv_peer ; pp = peer -> procptr ; up = pp -> unitptr ; p = ( u_char * ) & rbufp -> recv_space ; if ( pp -> lencode >= LENZYFER ) pp -> lencode = 0 ; if ( ! pp -> lencode ) { if ( * p == ' ' ) pp -> lencode = refclock_gtlin ( rbufp , pp -> a_lastcode , BMAX , & pp -> lastrec ) ; else return ; } else { memcpy ( pp -> a_lastcode + pp -> lencode , p , rbufp -> recv_length ) ; pp -> lencode += rbufp -> recv_length ; pp -> a_lastcode [ pp -> lencode ] = ' \0 ' ; } if ( pp -> lencode < LENZYFER ) return ; record_clock_stats ( & peer -> srcadr , pp -> a_lastcode ) ; if ( pp -> lencode != LENZYFER ) { refclock_report ( peer , CEVNT_BADTIME ) ; return ; } if ( sscanf ( pp -> a_lastcode , " " , & pp -> year , & pp -> day , & pp -> hour , & pp -> minute , & pp -> second , & tmode , & tfom , & omode ) != 8 ) { refclock_report ( peer , CEVNT_BADREPLY ) ; return ; } if ( tmode != 2 ) { refclock_report ( peer , CEVNT_BADTIME ) ; return ; } if ( omode != 1 ) { pp -> leap = LEAP_NOTINSYNC ; return ; } if ( ! refclock_process ( pp ) ) { refclock_report ( peer , CEVNT_BADTIME ) ; return ; } up -> pollcnt = 2 ; if ( up -> polled ) { up -> polled = 0 ; refclock_receive ( peer ) ; } }
zyfer_receive - receive data from the serial interface
zyfer_receive - receive data from the serial interface
/* Time mode */ /* Time Figure Of Merit */ /* Operation mode */ /*
	 * If lencode is 0:
	 * - if *rbufp->recv_space is !
	 * - - call refclock_gtlin to get things going
	 * - else flush
	 * else stuff it on the end of lastcode
	 * If we don't have LENZYFER bytes
	 * - wait for more data
	 * Crack the beast, and if it's OK, process it.
	 *
	 * We use refclock_gtlin() because we might use LDISC_CLK.
	 *
	 * Under FreeBSD, we get the ! followed by two 14-byte packets.
	 */ /*
	 * We get down to business, check the timecode format and decode
	 * its contents. If the timecode has invalid length or is not in
	 * proper format, we declare bad format and exit.
	 */ /*
	 * Timecode sample: "!TIME,2002,017,07,59,32,2,4,1"
	 */ /* Should we make sure tfom is 4? */ /*
	 * Good place for record_clock_stats()
	 */