rsunicast/rsunicast.h
/**
 * Sends data of this node to the parent. If there are still outstanding message, it is appended to the end of the message 
 * queue.
 * @param msg The data to be sent. Will be copied, so you can free the memory afterwards
 * @param size The size of msg
 */
Sends data of this node to the parent. If there are still outstanding message, it is appended to the end of the message
queue.
@param msg The data to be sent. Will be copied, so you can free the memory afterwards
@param size The size of msg
Sends data of this node to the parent . If there are still outstanding message it is appended to the end of the message queue . @param msg The data to be sent . Will be copied so you can free the memory afterwards @param size The size of msg
void rsunicast_send(void* msg, uint16_t size)
{
	if(rsu_is_online == 0) {
		unicast_open(&rsu_data_channel, MESSAGING_PORT, &rsu_msg_callbacks);
		unicast_open(&rsu_ack_channel, ACKNOWLEDGEMENT_PORT, &rsu_ack_callbacks);
		rsu_is_online = 1;
	}
	struct RSUnicastQueueElement* queue_element = (struct RSUnicastQueueElement*) calloc(1, sizeof(struct RSUnicastQueueElement));
	CHECK_ALLOCATION( queue_element );
	queue_element->size = size + sizeof(uint8_t);
	queue_element->msg = calloc(1, queue_element->size);
	CHECK_ALLOCATION( queue_element->msg );
	*((uint8_t*)(queue_element->msg)) = rsu_seqno;
	memcpy(queue_element->msg+1, msg, size);
	queue_element->tries = 0;
	if(rsu_seqno == 0xff) rsu_seqno = 0;
	else rsu_seqno++;
	if(rsu_queue==0) {
		rsu_queue = queue_element;
		ctimer_set(&rsu_timer, CLOCK_SECOND*NEXT_MSG_DELAY*(0.5+(float)random_rand()/(2*RANDOM_RAND_MAX)), rsu_send_next_message, 0); 
	} else {
		struct RSUnicastQueueElement* tmp = rsu_queue;
		while(tmp->next!=0) tmp = tmp->next;
		tmp->next = queue_element;
	}	
	rsu_messages_in_queue++;
}
void rsunicast_send ( void * msg , uint16_t size ) { if ( rsu_is_online == 0 ) { unicast_open ( & rsu_data_channel , MESSAGING_PORT , & rsu_msg_callbacks ) ; unicast_open ( & rsu_ack_channel , ACKNOWLEDGEMENT_PORT , & rsu_ack_callbacks ) ; rsu_is_online = 1 ; } struct RSUnicastQueueElement * queue_element = ( struct RSUnicastQueueElement * ) calloc ( 1 , sizeof ( struct RSUnicastQueueElement ) ) ; CHECK_ALLOCATION ( queue_element ) ; queue_element -> size = size + sizeof ( uint8_t ) ; queue_element -> msg = calloc ( 1 , queue_element -> size ) ; CHECK_ALLOCATION ( queue_element -> msg ) ; * ( ( uint8_t * ) ( queue_element -> msg ) ) = rsu_seqno ; memcpy ( queue_element -> msg + 1 , msg , size ) ; queue_element -> tries = 0 ; if ( rsu_seqno == 0xff ) rsu_seqno = 0 ; else rsu_seqno ++ ; if ( rsu_queue == 0 ) { rsu_queue = queue_element ; ctimer_set ( & rsu_timer , CLOCK_SECOND * NEXT_MSG_DELAY * ( 0.5 + ( float ) random_rand ( ) / ( 2 * RANDOM_RAND_MAX ) ) , rsu_send_next_message , 0 ) ; } else { struct RSUnicastQueueElement * tmp = rsu_queue ; while ( tmp -> next != 0 ) tmp = tmp -> next ; tmp -> next = queue_element ; } rsu_messages_in_queue ++ ; }
Sends data of this node to the parent.
Sends data of this node to the parent .
//if is sleeping, wake up //Create Queue Entry //set seqno //increment sequence no //Add to queue //bump sending if idle //append at end