FreeBSD/contrib/ntp/ntpd/refclock_leitch.c
/*
 * leitch_receive - receive data from the serial interface on a leitch
 * clock
 */
receive data from the serial interface on a leitch
clock
receive data from the serial interface on a leitch clock
static void
leitch_receive(
	struct recvbuf *rbufp
	)
{
	struct leitchunit *leitch = rbufp->recv_peer->procptr->unitptr;
#ifdef DEBUG
	if (debug)
	    fprintf(stderr, "leitch_recieve(%*.*s)\n", 
		    rbufp->recv_length, rbufp->recv_length,
		    rbufp->recv_buffer);
#endif
	if (rbufp->recv_length != 7)
	    return; 
	switch (leitch->state) {
	    case STATE_IDLE:	
		return;
	    case STATE_DATE:
		if (!leitch_get_date(rbufp,leitch)) {
			leitch->state = STATE_IDLE;
			break;
		}
		leitch_send(leitch,"T\r");
#ifdef DEBUG
		if (debug)
		    fprintf(stderr, "%u\n",leitch->yearday);
#endif
		leitch->state = STATE_TIME1;
		break;
	    case STATE_TIME1:
		if (!leitch_get_time(rbufp,leitch,1)) {
		}
		if (!clocktime(leitch->yearday,leitch->hour,leitch->minute,
			       leitch->second, 1, rbufp->recv_time.l_ui,
			       &leitch->yearstart, &leitch->reftime1.l_ui)) {
			leitch->state = STATE_IDLE;
			break;
		}
		leitch->reftime1.l_uf = 0;
#ifdef DEBUG
		if (debug)
		    fprintf(stderr, "%lu\n", (u_long)leitch->reftime1.l_ui);
#endif
		MSUTOTSF(leitch->fudge1, leitch->reftime1.l_uf);
		leitch->codetime1 = rbufp->recv_time;
		leitch->state = STATE_TIME2;
		break;
	    case STATE_TIME2:
		if (!leitch_get_time(rbufp,leitch,2)) {
		}
		if (!clocktime(leitch->yearday,leitch->hour,leitch->minute,
			       leitch->second, 1, rbufp->recv_time.l_ui,
			       &leitch->yearstart, &leitch->reftime2.l_ui)) {
			leitch->state = STATE_IDLE;
			break;
		}
#ifdef DEBUG
		if (debug)
		    fprintf(stderr, "%lu\n", (u_long)leitch->reftime2.l_ui);
#endif
		MSUTOTSF(leitch->fudge1, leitch->reftime2.l_uf);
		leitch->codetime2 = rbufp->recv_time;
		leitch->state = STATE_TIME3;
		break;
	    case STATE_TIME3:
		if (!leitch_get_time(rbufp,leitch,3)) {
		}
		if (!clocktime(leitch->yearday,leitch->hour,leitch->minute,
			       leitch->second, GMT, rbufp->recv_time.l_ui,
			       &leitch->yearstart, &leitch->reftime3.l_ui)) {
			leitch->state = STATE_IDLE;
			break;
		}
#ifdef DEBUG
		if (debug)
		    fprintf(stderr, "%lu\n", (u_long)leitch->reftime3.l_ui);
#endif
		MSUTOTSF(leitch->fudge1, leitch->reftime3.l_uf);
		leitch->codetime3 = rbufp->recv_time;
		leitch_process(leitch);
		leitch->state = STATE_IDLE;
		break;
	    default:
		msyslog(LOG_ERR,
			"leitech_receive: invalid state %d unit %d",
			leitch->state, leitch->unit);
	}
}
static void leitch_receive ( struct recvbuf * rbufp ) { struct leitchunit * leitch = rbufp -> recv_peer -> procptr -> unitptr ; #ifdef DEBUG if ( debug ) fprintf ( stderr , " \n " , rbufp -> recv_length , rbufp -> recv_length , rbufp -> recv_buffer ) ; #endif if ( rbufp -> recv_length != 7 ) return ; switch ( leitch -> state ) { case STATE_IDLE : return ; case STATE_DATE : if ( ! leitch_get_date ( rbufp , leitch ) ) { leitch -> state = STATE_IDLE ; break ; } leitch_send ( leitch , " \r " ) ; #ifdef DEBUG if ( debug ) fprintf ( stderr , " \n " , leitch -> yearday ) ; #endif leitch -> state = STATE_TIME1 ; break ; case STATE_TIME1 : if ( ! leitch_get_time ( rbufp , leitch , 1 ) ) { } if ( ! clocktime ( leitch -> yearday , leitch -> hour , leitch -> minute , leitch -> second , 1 , rbufp -> recv_time . l_ui , & leitch -> yearstart , & leitch -> reftime1 . l_ui ) ) { leitch -> state = STATE_IDLE ; break ; } leitch -> reftime1 . l_uf = 0 ; #ifdef DEBUG if ( debug ) fprintf ( stderr , " \n " , ( u_long ) leitch -> reftime1 . l_ui ) ; #endif MSUTOTSF ( leitch -> fudge1 , leitch -> reftime1 . l_uf ) ; leitch -> codetime1 = rbufp -> recv_time ; leitch -> state = STATE_TIME2 ; break ; case STATE_TIME2 : if ( ! leitch_get_time ( rbufp , leitch , 2 ) ) { } if ( ! clocktime ( leitch -> yearday , leitch -> hour , leitch -> minute , leitch -> second , 1 , rbufp -> recv_time . l_ui , & leitch -> yearstart , & leitch -> reftime2 . l_ui ) ) { leitch -> state = STATE_IDLE ; break ; } #ifdef DEBUG if ( debug ) fprintf ( stderr , " \n " , ( u_long ) leitch -> reftime2 . l_ui ) ; #endif MSUTOTSF ( leitch -> fudge1 , leitch -> reftime2 . l_uf ) ; leitch -> codetime2 = rbufp -> recv_time ; leitch -> state = STATE_TIME3 ; break ; case STATE_TIME3 : if ( ! leitch_get_time ( rbufp , leitch , 3 ) ) { } if ( ! clocktime ( leitch -> yearday , leitch -> hour , leitch -> minute , leitch -> second , GMT , rbufp -> recv_time . l_ui , & leitch -> yearstart , & leitch -> reftime3 . l_ui ) ) { leitch -> state = STATE_IDLE ; break ; } #ifdef DEBUG if ( debug ) fprintf ( stderr , " \n " , ( u_long ) leitch -> reftime3 . l_ui ) ; #endif MSUTOTSF ( leitch -> fudge1 , leitch -> reftime3 . l_uf ) ; leitch -> codetime3 = rbufp -> recv_time ; leitch_process ( leitch ) ; leitch -> state = STATE_IDLE ; break ; default : msyslog ( LOG_ERR , " " , leitch -> state , leitch -> unit ) ; } }
leitch_receive - receive data from the serial interface on a leitch
 clock
leitch_receive - receive data from the serial interface on a leitch clock
/* The date is return with a trailing newline,
		       discard it. */ /* unexpected, discard and resync */