rsunicast/rsunicast.h
//Called on new incoming message on the data channel
Called on new incoming message on the data channel
Called on new incoming message on the data channel
void rsu_on_new_message(struct unicast_conn* c, const linkaddr_t *from)
{
	uint16_t id = ((uint16_t)from->u8[0])<<8 | from->u8[1]; 
	void* msg = packetbuf_dataptr();
	uint16_t size = packetbuf_datalen();
	uint8_t seqno = *(uint8_t*)msg;	
	char ack = 'A';
	packetbuf_copyfrom(&ack, 1);
	static linkaddr_t recv;
	recv.u8[0] = id>>8;
	recv.u8[1] = id&0xFF;
	unicast_send(&rsu_ack_channel, &recv);
#ifdef ROOT
	if(rsu_on_new_message_for_root_cb!=0){
		if(rsu_check_history(id, seqno)==0){ 
			(*rsu_on_new_message_for_root_cb)(msg+1, size-sizeof(uint8_t));
		}
	}
#else
	if(rsu_check_history(id, seqno)!=0){
#ifdef DEBUG
		printf("Received duplicate message from %d\n",id);
#endif
		return;
	} else {
#ifdef DEBUG
		printf("Received message from %d\n",id);
#endif
		rsu_add_history(id, seqno);
		rsunicast_send(msg+1, size-sizeof(uint8_t));
	}
#endif
}
void rsu_on_new_message ( struct unicast_conn * c , const linkaddr_t * from ) { uint16_t id = ( ( uint16_t ) from -> u8 [ 0 ] ) << 8 | from -> u8 [ 1 ] ; void * msg = packetbuf_dataptr ( ) ; uint16_t size = packetbuf_datalen ( ) ; uint8_t seqno = * ( uint8_t * ) msg ; char ack = ' ' ; packetbuf_copyfrom ( & ack , 1 ) ; static linkaddr_t recv ; recv . u8 [ 0 ] = id >> 8 ; recv . u8 [ 1 ] = id & 0xFF ; unicast_send ( & rsu_ack_channel , & recv ) ; #ifdef ROOT if ( rsu_on_new_message_for_root_cb != 0 ) { if ( rsu_check_history ( id , seqno ) == 0 ) { ( * rsu_on_new_message_for_root_cb ) ( msg + 1 , size - sizeof ( uint8_t ) ) ; } } #else if ( rsu_check_history ( id , seqno ) != 0 ) { #ifdef DEBUG printf ( " \n " , id ) ; #endif return ; } else { #ifdef DEBUG printf ( " \n " , id ) ; #endif rsu_add_history ( id , seqno ) ; rsunicast_send ( msg + 1 , size - sizeof ( uint8_t ) ) ; } #endif }
Called on new incoming message on the data channel
Called on new incoming message on the data channel
//decode id //send ACK //Inform root about new message for it //no duplicate //Check for duplicate //Duplicate //Add to history //Add to queue