Ejemplo n.º 1
0
Archivo: udp.c Proyecto: sannyas/avrlib
uint8_t udp_send( uint16_t len ){
	DEBUG_FUNC_ENTER();

	uint16_t udp_check_sum;
	uint8_t ret;

	/* fill ip header */
	buff.ip.total_len = UDP_HEADER_OFFSET + buff.udp.len;
	buff.ip.identification = 0;
	buff.ip.protocal = IP_PROTOCAL_UDP;

	/* fill udp */
	len += 8;
	buff.udp.len = len;
	
	/* Checksum of UDP */
	buff.udp.checksum = 0;
	udp_check_sum = checksum( 0, buff.bytes+UDP_HEADER_OFFSET, len );
	udp_check_sum = checksum( 0, buff.ip.src_addr, 8 );
	udp_check_sum = checksum_add( udp_check_sum, len );
	udp_check_sum = checksum_add( udp_check_sum, IP_PROTOCAL_UDP );
	buff.udp.checksum = udp_check_sum;

	ret = sendIPPacket( );

	DEBUG_FUNC_EXIT();
	return ret;
}
Ejemplo n.º 2
0
static inline void decoder_newdata( uint16_t period )
{
	uint8_t sym;

	/* Check that the frequency reaches the minimum */
	if( period < (period_lut[0] - RANGE) ) {
		decoder_reset();
		return;
	}

	for( sym=0;
	     sym < NFREQ;
	     sym++ )
		if( period < (period_lut[sym] + RANGE) )
			break;

	if( sym == NFREQ ) {
		/* Invalid frequency - reset the decoder */
		decoder_reset();
		return;
	}

	/* Ignore repeated symbols */
	if( sym == last_sym )
		return;

	/*** Decode the symbol ***/

	if( sym == 0 ) {
		cb_pos = 0;
		curbyte = 0;

		last_sym = 0;
		return;
	}

	/* Remove the step over the last symbol */
	if( sym > last_sym ) {
		last_sym = sym;
		sym--;
	} else
		last_sym = sym;
	
	/* Start of the byte? */
	sym--;

	curbyte |= sym << (cb_pos * NBITS);
	cb_pos++;

	if( cb_pos == SYMBOLS_PER_BYTE ) {
		static uint8_t checksum;
		static bool escaped = FALSE;

		/* We now have a full byte */
		cb_pos = 0;

		if( curbyte == 0x7e ) {
			/* Start of frame */
			d_pos = 0;
			checksum = 0;
			data[0] = 0x7e;
			escaped = FALSE;
		} else if( data[0] == 0x7e ) {
			if( curbyte == 0x7d ) {
				escaped = TRUE;
				return;
			}
			else if( escaped ) {
				curbyte ^= 0x20;
				escaped = FALSE;
			}				

			data[d_pos] = curbyte;


			/* data[1] is the length if we've got that far */
			if( d_pos > 1 && d_pos == (data[1] + 2) ) {
				/* Frame reception complete -- check the checksum */
				if( checksum == curbyte )
					net_rx_proc_incoming( data+2, data[1] );
			}
			else
				checksum_add( checksum, curbyte );

		}

		if( data[0] == 0x7e )
			d_pos = (d_pos==(DATA_LEN-1))?0:(d_pos+1);

	}
}