FreeBSD/contrib/ntp/ntpd/refclock_ripencc.c
/*
 * reads bytes until serial buffer is empty or a complete report
 * has been received; end of report is signified by DLE ETX.
 */
reads bytes until serial buffer is empty or a complete report
has been received; end of report is signified by DLE ETX.
reads bytes until serial buffer is empty or a complete report has been received ; end of report is signified by DLE ETX .
static void
tsip_input_proc(
		TSIPPKT *rpt,
		int inbyte
		)
{
	unsigned char newbyte;
	if (inbyte < 0 || inbyte > 0xFF) return;
	newbyte = (unsigned char)(inbyte);
	switch (rpt->status)
	{
	    case TSIP_PARSED_DLE_1:
		switch (newbyte)
		{
		    case 0:
		    case ETX:
			rpt->len = 0;
			rpt->status = TSIP_PARSED_EMPTY;
			break;
		    case DLE:
			rpt->len = 0;
			rpt->status = TSIP_PARSED_DLE_1;
			break;
		    default:
			rpt->code = newbyte;
			rpt->len = 0;
			rpt->status = TSIP_PARSED_DATA;
			break;
		}
		break;
	    case TSIP_PARSED_DATA:
		switch (newbyte) {
		    case DLE:
			rpt->status = TSIP_PARSED_DLE_2;
			break;
		    default:
			rpt->buf[rpt->len] = newbyte;
			rpt->len++;
			break;
		}
		break;
	    case TSIP_PARSED_DLE_2:
		switch (newbyte) {
		    case DLE:
			rpt->buf[rpt->len] = newbyte;
			rpt->len++;
			rpt->status = TSIP_PARSED_DATA;
			break;
		    case ETX:
			rpt->status = TSIP_PARSED_FULL;
			break;
		    default:
			rpt->code = newbyte;
			rpt->len = 0;
			rpt->status = TSIP_PARSED_DATA;
		}
		break;
	    case TSIP_PARSED_FULL:
	    case TSIP_PARSED_EMPTY:
	    default:
		switch (newbyte) {
		    case DLE:
			rpt->len = 0;
			rpt->status = TSIP_PARSED_DLE_1;
			break;
		    default:
			rpt->len = 0;
			rpt->status = TSIP_PARSED_EMPTY;
		}
		break;
	}
	if (rpt->len > MAX_RPTBUF) {
		rpt->status = TSIP_PARSED_EMPTY;
		rpt->len = 0;
	}
}
static void tsip_input_proc ( TSIPPKT * rpt , int inbyte ) { unsigned char newbyte ; if ( inbyte < 0 || inbyte > 0xFF ) return ; newbyte = ( unsigned char ) ( inbyte ) ; switch ( rpt -> status ) { case TSIP_PARSED_DLE_1 : switch ( newbyte ) { case 0 : case ETX : rpt -> len = 0 ; rpt -> status = TSIP_PARSED_EMPTY ; break ; case DLE : rpt -> len = 0 ; rpt -> status = TSIP_PARSED_DLE_1 ; break ; default : rpt -> code = newbyte ; rpt -> len = 0 ; rpt -> status = TSIP_PARSED_DATA ; break ; } break ; case TSIP_PARSED_DATA : switch ( newbyte ) { case DLE : rpt -> status = TSIP_PARSED_DLE_2 ; break ; default : rpt -> buf [ rpt -> len ] = newbyte ; rpt -> len ++ ; break ; } break ; case TSIP_PARSED_DLE_2 : switch ( newbyte ) { case DLE : rpt -> buf [ rpt -> len ] = newbyte ; rpt -> len ++ ; rpt -> status = TSIP_PARSED_DATA ; break ; case ETX : rpt -> status = TSIP_PARSED_FULL ; break ; default : rpt -> code = newbyte ; rpt -> len = 0 ; rpt -> status = TSIP_PARSED_DATA ; } break ; case TSIP_PARSED_FULL : case TSIP_PARSED_EMPTY : default : switch ( newbyte ) { case DLE : rpt -> len = 0 ; rpt -> status = TSIP_PARSED_DLE_1 ; break ; default : rpt -> len = 0 ; rpt -> status = TSIP_PARSED_EMPTY ; } break ; } if ( rpt -> len > MAX_RPTBUF ) { rpt -> status = TSIP_PARSED_EMPTY ; rpt -> len = 0 ; } }
reads bytes until serial buffer is empty or a complete report
 has been received; end of report is signified by DLE ETX.
reads bytes until serial buffer is empty or a complete report has been received ; end of report is signified by DLE ETX .
/* illegal TSIP IDs */ /* try normal message start again */ /* legal TSIP ID; start message */ /* expect DLE or ETX next */ /* normal data byte  */ /* no change in rpt->status */ /* normal data byte */ /* end of message; return TRUE here. */ /* error: treat as TSIP_PARSED_DLE_1; start new report packet */ /* normal message start */ /* error: ignore newbyte */ /* error: start new report packet */