[Aggregator] Fix autocalibration scheduler
The list of knowns APs is now handled as a double-linked token ring instead of a double-linked list. The scheduler for autocalibration transmissions is now operational! Delete the now-useless function move_ap_front(), which was not used before anyway.
This commit is contained in:
parent
97a1e7c72a
commit
8319ca112a
|
@ -108,7 +108,6 @@ void delete_old_aps(void) ;
|
||||||
void delete_ap(ap_list *ap) ;
|
void delete_ap(ap_list *ap) ;
|
||||||
void unlink_ap(ap_list *ap) ;
|
void unlink_ap(ap_list *ap) ;
|
||||||
void order_send(ap_list *ap) ;
|
void order_send(ap_list *ap) ;
|
||||||
void move_ap_front(ap_list *ap) ;
|
|
||||||
void free_ap_list(void) ;
|
void free_ap_list(void) ;
|
||||||
|
|
||||||
char* ip_bytes_to_string(unsigned char *ip_binary) ;
|
char* ip_bytes_to_string(unsigned char *ip_binary) ;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
char *program_name = NULL ;
|
char *program_name = NULL ;
|
||||||
cfg_t *cfg = NULL ; // Configuration structure
|
cfg_t *cfg = NULL ; // Configuration structure
|
||||||
couple_list *couples = NULL ; // Computed data list
|
couple_list *couples = NULL ; // Computed data list
|
||||||
ap_list *aps = NULL ;
|
ap_list *token_aps = NULL ; // Token ring of the APs
|
||||||
unsigned int nb_aps = 0 ;
|
unsigned int nb_aps = 0 ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -733,14 +733,19 @@ void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16])
|
||||||
*/
|
*/
|
||||||
ap_list* find_ap(unsigned char mac_addr_bytes[6])
|
ap_list* find_ap(unsigned char mac_addr_bytes[6])
|
||||||
{
|
{
|
||||||
ap_list *found = aps ;
|
ap_list *found ;
|
||||||
|
|
||||||
while (found != NULL)
|
if (token_aps == NULL)
|
||||||
|
return NULL ;
|
||||||
|
|
||||||
|
found = token_aps ;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
if (mac_cmp(found->mac_addr_bytes, mac_addr_bytes))
|
if (mac_cmp(found->mac_addr_bytes, mac_addr_bytes))
|
||||||
return found ;
|
return found ;
|
||||||
found = found->next ;
|
found = found->next ;
|
||||||
}
|
}
|
||||||
|
while (found != token_aps) ;
|
||||||
|
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
@ -786,11 +791,20 @@ void update_ap_seen(ap_list *ap)
|
||||||
void push_ap(ap_list *ap)
|
void push_ap(ap_list *ap)
|
||||||
{
|
{
|
||||||
assert(ap) ;
|
assert(ap) ;
|
||||||
ap->previous = NULL ;
|
|
||||||
ap->next = aps ;
|
if (token_aps == NULL) // List does not exist yet
|
||||||
if (aps != NULL)
|
{
|
||||||
aps->previous = ap ;
|
token_aps = ap ;
|
||||||
aps = ap ;
|
ap->next = ap ;
|
||||||
|
ap->previous = ap ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
ap->previous = token_aps->previous ;
|
||||||
|
ap->previous->next = ap ;
|
||||||
|
ap->next = token_aps ;
|
||||||
|
token_aps->previous = ap ;
|
||||||
|
token_aps = ap ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -810,7 +824,10 @@ void monitor_aps()
|
||||||
delete_old_aps() ;
|
delete_old_aps() ;
|
||||||
|
|
||||||
if (nb_aps > 1)
|
if (nb_aps > 1)
|
||||||
order_send(aps) ;
|
{
|
||||||
|
order_send(token_aps) ;
|
||||||
|
token_aps = token_aps->next ;
|
||||||
|
}
|
||||||
|
|
||||||
usleep(cfg_getint(cfg, "ap_check_interval") * 1000) ;
|
usleep(cfg_getint(cfg, "ap_check_interval") * 1000) ;
|
||||||
}
|
}
|
||||||
|
@ -824,12 +841,16 @@ void monitor_aps()
|
||||||
void delete_old_aps()
|
void delete_old_aps()
|
||||||
{
|
{
|
||||||
struct timeval now ;
|
struct timeval now ;
|
||||||
|
|
||||||
|
if (token_aps == NULL)
|
||||||
|
return ;
|
||||||
|
|
||||||
gettimeofday(&now, NULL) ;
|
gettimeofday(&now, NULL) ;
|
||||||
|
|
||||||
while (aps != NULL)
|
while (token_aps != token_aps->next)
|
||||||
if (sub_date(aps->last_seen, now) >
|
if (sub_date(token_aps->last_seen, now) >
|
||||||
(unsigned long) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
(unsigned long) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
||||||
delete_ap(aps) ;
|
delete_ap(token_aps) ;
|
||||||
else
|
else
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
@ -857,14 +878,14 @@ void unlink_ap(ap_list *ap)
|
||||||
*ap_previous = ap->previous,
|
*ap_previous = ap->previous,
|
||||||
*ap_next = ap->next ;
|
*ap_next = ap->next ;
|
||||||
|
|
||||||
if (ap_previous != NULL)
|
assert(ap_previous) ;
|
||||||
ap_previous->next = ap_next ;
|
assert(ap_next) ;
|
||||||
|
|
||||||
if (ap_next != NULL)
|
ap_previous->next = ap_next ;
|
||||||
ap_next->previous = ap_previous ;
|
ap_next->previous = ap_previous ;
|
||||||
|
|
||||||
if (ap == aps)
|
if (ap == token_aps)
|
||||||
aps = ap_next ;
|
token_aps = ap_next ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -902,29 +923,28 @@ void order_send(ap_list *ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Moves the given AP, existing in the AP list, in front of the list.
|
|
||||||
*/
|
|
||||||
void move_ap_front(ap_list *ap)
|
|
||||||
{
|
|
||||||
unlink_ap(ap) ;
|
|
||||||
push_ap(ap) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Empties the AP list.
|
* Empties the AP list.
|
||||||
*/
|
*/
|
||||||
void free_ap_list()
|
void free_ap_list()
|
||||||
{
|
{
|
||||||
ap_list *ap_ptr = aps ;
|
ap_list *ap_ptr ;
|
||||||
|
|
||||||
while (ap_ptr != NULL)
|
if (token_aps == NULL)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
ap_ptr = token_aps->next ;
|
||||||
|
assert(ap_ptr) ;
|
||||||
|
|
||||||
|
while (ap_ptr != token_aps)
|
||||||
{
|
{
|
||||||
|
ap_list *ap_tmp = ap_ptr ;
|
||||||
ap_ptr = ap_ptr->next ;
|
ap_ptr = ap_ptr->next ;
|
||||||
free(aps) ;
|
free(ap_tmp) ;
|
||||||
aps = ap_ptr ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(token_aps) ;
|
||||||
|
token_aps = NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue