rsunicast/rsunicast_history.h
/**
 * Adds an entry to the history. 
 * For each robot only the last seqno is saved
 */
Adds an entry to the history.
For each robot only the last seqno is saved
Adds an entry to the history . For each robot only the last seqno is saved
void rsu_add_history(uint16_t from, uint8_t seqno){
	struct rsu_history_element* tmp = rsu_history_list;
	while(rsu_history_list != 0 && rsu_history_list->id == from){
		rsu_history_list = rsu_history_list->next;
		free(tmp);
		rsu_history_size--;
		tmp = rsu_history_list;
	}
	if(rsu_history_list==0){
		rsu_history_list = (struct rsu_history_element*) calloc(1, sizeof(struct rsu_history_element));
		CHECK_ALLOCATION( rsu_history_list );
		rsu_history_list->id = from;
		rsu_history_list->seqno = seqno;
		rsu_history_list->next = 0;
		rsu_history_size++;
	} else {
		for(;tmp!=0; tmp = tmp->next){
			if(tmp->next == 0){
				tmp->next = (struct rsu_history_element*) calloc(1, sizeof(struct rsu_history_element));
				CHECK_ALLOCATION( tmp->next );
				tmp->next->id = from;
				tmp->next->seqno = seqno;
				tmp->next->next = 0;
				rsu_history_size++;
				break;
			} else if(tmp->next->id == from) { 
				struct rsu_history_element* tmp2 = tmp->next;
				tmp->next = tmp2->next;
				free(tmp2);
			}
		}
	}
	while(rsu_history_size>MAX_HISTORY_SIZE){
		tmp = rsu_history_list;
		rsu_history_list = rsu_history_list->next;
		free(tmp);
		rsu_history_size--;
	}
}
void rsu_add_history ( uint16_t from , uint8_t seqno ) { struct rsu_history_element * tmp = rsu_history_list ; while ( rsu_history_list != 0 && rsu_history_list -> id == from ) { rsu_history_list = rsu_history_list -> next ; free ( tmp ) ; rsu_history_size -- ; tmp = rsu_history_list ; } if ( rsu_history_list == 0 ) { rsu_history_list = ( struct rsu_history_element * ) calloc ( 1 , sizeof ( struct rsu_history_element ) ) ; CHECK_ALLOCATION ( rsu_history_list ) ; rsu_history_list -> id = from ; rsu_history_list -> seqno = seqno ; rsu_history_list -> next = 0 ; rsu_history_size ++ ; } else { for ( ; tmp != 0 ; tmp = tmp -> next ) { if ( tmp -> next == 0 ) { tmp -> next = ( struct rsu_history_element * ) calloc ( 1 , sizeof ( struct rsu_history_element ) ) ; CHECK_ALLOCATION ( tmp -> next ) ; tmp -> next -> id = from ; tmp -> next -> seqno = seqno ; tmp -> next -> next = 0 ; rsu_history_size ++ ; break ; } else if ( tmp -> next -> id == from ) { struct rsu_history_element * tmp2 = tmp -> next ; tmp -> next = tmp2 -> next ; free ( tmp2 ) ; } } } while ( rsu_history_size > MAX_HISTORY_SIZE ) { tmp = rsu_history_list ; rsu_history_list = rsu_history_list -> next ; free ( tmp ) ; rsu_history_size -- ; } }
Adds an entry to the history.
Adds an entry to the history .
//Remove old entries of this neighbor at the beginning of the list //if list is empty, set this element the first //Append to end of list //Reached end, insert //Old entry of this neighbor found -> delete it //If history has to many elements, clean the oldest