[Aggregator] Rename *couple* -> *request*

Get rid of this old name 'couple' in variables, function names & types.
This commit is contained in:
Matteo Cypriani 2011-03-18 16:31:06 +01:00
parent 0a4625c5fc
commit 58795d03d5
2 changed files with 147 additions and 144 deletions

View File

@ -34,21 +34,21 @@
#define ERR_SENDING_INFO 5 // Error sending a message on a socket
/* Linked list storing data of couples MAC / sequence number */
typedef struct _couple_info_list
/* Linked list storing data of each request */
typedef struct _request_info_list
{
// MAC address of the data sender (in bytes):
uint8_t ap_mac_addr_bytes[6] ;
// Signal strength received by the AP from the mobile:
uint8_t antenna_signal_dbm ;
struct _couple_info_list *next ;
} couple_info_list ;
struct _request_info_list *next ;
} request_info_list ;
/* Linked list of the couples MAC / sequence number */
typedef struct _couple_list
/* Linked list of the requests */
typedef struct _request_list
{
/* Numéro de séquence de la demande de localisation du mobile */
/* Request identifier */
uint8_t mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
owl_timestamp request_time ; // Request time on the mobile
@ -59,12 +59,12 @@ typedef struct _couple_list
owl_direction direction ; // Request orientation
/* Other data */
// Arrival time of the first packet of the couple on the aggregator:
// Arrival time of the first packet of the request on the aggregator:
owl_timestamp start_time ;
couple_info_list *info ; // Data for this couple
request_info_list *info ; // Data for this request
struct _couple_list *next ;
} couple_list ;
struct _request_list *next ;
} request_list ;
/* Linked list of the known APs */
@ -87,13 +87,13 @@ void parse_command_line(int argc, char **argv) ;
void check_configuration(void) ;
int read_loop(int sockfd) ;
void got_couple_info(owl_captured_request request) ;
void got_request(owl_captured_request request) ;
void* monitor_couples(void) ;
void free_couple_list(void) ;
void* monitor_requests(void) ;
void free_request_list(void) ;
#ifdef DEBUG
void print_couple_list(void) ;
void print_couple_info(couple_info_list *info) ;
void print_request_list(void) ;
void print_request_info(request_info_list *info) ;
#endif // DEBUG
void listen_for_aps(void) ;

View File

@ -11,7 +11,7 @@
char *program_name = NULL ;
cfg_t *cfg = NULL ; // Configuration structure
couple_list *couples = NULL ; // Computed data list
request_list *requests = NULL ; // Computed data list
ap_list *token_aps = NULL ; // Token ring of the APs
uint_fast16_t nb_aps = 0 ; // Number of APs in the AP ring
@ -50,7 +50,7 @@ int main(int argc, char **argv)
/* Set up threads */
pthread_create(&monitor_thread, NULL,
(void *) &monitor_couples, NULL) ;
(void *) &monitor_requests, NULL) ;
if (cfg_getbool(cfg, "autocalibration"))
{
pthread_create(&autocalibration_hello_thread, NULL,
@ -63,7 +63,7 @@ int main(int argc, char **argv)
ret = read_loop(sockfd) ;
(void) close(sockfd) ; // Close socket
free_couple_list() ;
free_request_list() ;
free_ap_list() ;
cfg_free(cfg) ; // Clean configuration
@ -404,7 +404,7 @@ int read_loop(int sockfd)
}
#endif // DEBUG
got_couple_info(request) ;
got_request(request) ;
}
return ret ;
@ -416,10 +416,10 @@ int read_loop(int sockfd)
* Thread function. Monitors the list and sends information to the
* localisation server when the timeout is reached.
*/
void* monitor_couples()
void* monitor_requests()
{
couple_list *couple_ptr, *couple_prev ;
couple_info_list *couple_info_ptr ;
request_list *request_ptr, *request_prev ;
request_info_list *request_info_ptr ;
owl_timestamp current_time ;
FILE *fd = NULL ;
char *mac_str ;
@ -440,7 +440,7 @@ void* monitor_couples()
int sockfd;
#ifdef DEBUG
fprintf(stderr, "Monitor couples thread launched.\n") ;
fprintf(stderr, "Monitor requests thread launched.\n") ;
#endif // DEBUG
sockfd =
@ -459,18 +459,18 @@ void* monitor_couples()
while (run)
{
couple_ptr = couples ;
couple_prev = NULL ;
couple_info_ptr = NULL ;
request_ptr = requests ;
request_prev = NULL ;
request_info_ptr = NULL ;
owl_timestamp_now(&current_time) ;
while (couple_ptr != NULL) // Parsing list
while (request_ptr != NULL) // Parsing list
{
sub = owl_time_elapsed_ms(couple_ptr->start_time,
sub = owl_time_elapsed_ms(request_ptr->start_time,
current_time) ;
// If the couple was not treated already
if (couple_ptr->info != NULL)
// If the request was not treated already
if (request_ptr->info != NULL)
{
// If the timeout is reached
if (sub > aggregate_timeout)
@ -486,7 +486,7 @@ void* monitor_couples()
// Print mobile MAC address to the output file
mac_str =
owl_mac_bytes_to_string(couple_ptr
owl_mac_bytes_to_string(request_ptr
->mobile_mac_addr_bytes) ;
fprintf(fd, "%s;", mac_str) ;
free(mac_str) ;
@ -494,26 +494,28 @@ void* monitor_couples()
#ifdef USE_TIMESTAMP
// Print request mobile timestamp to the output file
owl_timestamp_to_string(request_time_str,
couple_ptr->request_time) ;
request_ptr->request_time) ;
fprintf(fd, "%s;", request_time_str) ;
#endif // USE_TIMESTAMP
// Print couple info to the output file
// Print request info to the output file
fprintf(fd, "%0.2f;%0.2f;%0.2f;%hhd",
couple_ptr->x_position, couple_ptr->y_position,
couple_ptr->z_position, couple_ptr->direction) ;
request_ptr->x_position,
request_ptr->y_position,
request_ptr->z_position,
request_ptr->direction) ;
memcpy(request.mobile_mac_addr_bytes,
couple_ptr->mobile_mac_addr_bytes, 6) ;
request.request_time = couple_ptr->request_time ;
request_ptr->mobile_mac_addr_bytes, 6) ;
request.request_time = request_ptr->request_time ;
request.nb_info = 0 ;
// Count the couples:
couple_info_ptr = couple_ptr->info ;
while (couple_info_ptr != NULL)
// Count the requests:
request_info_ptr = request_ptr->info ;
while (request_info_ptr != NULL)
{
request.nb_info++;
couple_info_ptr = couple_info_ptr->next ;
request_info_ptr = request_info_ptr->next ;
}
// Endianess conversions:
request.nb_info = htons(request.nb_info) ;
@ -523,40 +525,41 @@ void* monitor_couples()
sendto(sockfd, &request, sizeof(request), 0,
(struct sockaddr *)&serv, serv_len) ;
// Send couples to the server and empty the list
couple_info_ptr = couple_ptr->info ;
while (couple_info_ptr != NULL)
// Send requests to the server and empty the list
request_info_ptr = request_ptr->info ;
while (request_info_ptr != NULL)
{
// Send AP info to the localisation server
memcpy(info.ap_mac_addr_bytes,
couple_info_ptr->ap_mac_addr_bytes, 6) ;
request_info_ptr->ap_mac_addr_bytes, 6) ;
info.antenna_signal_dbm =
couple_info_ptr->antenna_signal_dbm - 0x100 ;
request_info_ptr->antenna_signal_dbm - 0x100 ;
sendto(sockfd, &info, sizeof(info),
0, (struct sockaddr *)&serv, serv_len) ;
// Print AP info to the output file
mac_str =
owl_mac_bytes_to_string(couple_info_ptr
owl_mac_bytes_to_string(request_info_ptr
->ap_mac_addr_bytes) ;
fprintf(fd, ";%s;%d", mac_str,
couple_info_ptr->antenna_signal_dbm - 0x100) ;
request_info_ptr->antenna_signal_dbm
- 0x100) ;
free(mac_str) ;
// Delete couple
couple_info_ptr = couple_info_ptr->next ;
free(couple_ptr->info) ;
couple_ptr->info = couple_info_ptr ;
// Delete request
request_info_ptr = request_info_ptr->next ;
free(request_ptr->info) ;
request_ptr->info = request_info_ptr ;
}
fprintf(fd, "\n") ;
}
}
// If the couple was treated and keep timeout is reached
// If the request was treated and keep timeout is reached
else if (sub > keep_timeout)
{
couple_list *couple_tmp = couple_ptr ;
request_list *request_tmp = request_ptr ;
printf("* Keep timeout reached.") ;
#ifdef DEBUG
@ -567,22 +570,22 @@ void* monitor_couples()
putchar('\n') ;
#endif // DEBUG
couple_ptr = couple_ptr->next ;
request_ptr = request_ptr->next ;
// If it is the first couple of the list
if (couple_prev == NULL)
couples = couple_ptr ; // we shift the head
// If it is the first request of the list
if (request_prev == NULL)
requests = request_ptr ; // we shift the head
else // else we put the next of the previous on the next
couple_prev->next = couple_ptr ;
request_prev->next = request_ptr ;
free(couple_tmp) ;
free(request_tmp) ;
continue ;
}
// Next couple
couple_prev = couple_ptr ;
couple_ptr = couple_ptr->next ;
// Next request
request_prev = request_ptr ;
request_ptr = request_ptr->next ;
}
fflush(NULL) ;
@ -602,116 +605,116 @@ void* monitor_couples()
/*
* Treats a received packet.
*/
void got_couple_info(owl_captured_request request)
void got_request(owl_captured_request request)
{
couple_list *tmp_couple = NULL ;
couple_info_list *tmp_info = NULL ;
request_list *tmp_request = NULL ;
request_info_list *tmp_info = NULL ;
owl_timestamp start_time ; // Reception time on the aggregator
owl_timestamp_now(&start_time) ;
/* Create a new couple */
tmp_info = malloc(sizeof(couple_info_list)) ;
/* Create a new request */
tmp_info = malloc(sizeof(request_info_list)) ;
memcpy(tmp_info->ap_mac_addr_bytes, request.ap_mac_addr_bytes, 6) ;
tmp_info->antenna_signal_dbm = request.antenna_signal_dbm ;
tmp_info->next = NULL ;
/* Add it in the list */
tmp_couple = couples ;
if (couples == NULL) // If the couple list does not exist,
tmp_request = requests ;
if (requests == NULL) // If the request list does not exist,
{
printf("Creating couple list.\n") ;
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
memcpy(tmp_couple->mobile_mac_addr_bytes,
printf("Creating request list.\n") ;
tmp_request = malloc(sizeof(request_list)) ; // create it.
memcpy(tmp_request->mobile_mac_addr_bytes,
request.mobile_mac_addr_bytes, 6) ;
// Explicit packet:
if (owl_timestamp_to_ms(request.request_time) != 0)
// Transmission time on the mobile:
tmp_couple->request_time = request.request_time ;
tmp_request->request_time = request.request_time ;
// Implicit packet:
else
// Reception time on the AP:
tmp_couple->request_time = request.start_time ;
tmp_request->request_time = request.start_time ;
// Save locale time on the aggregator (not the reception time
// on the AP):
tmp_couple->start_time = start_time ;
tmp_couple->x_position = request.x_position ;
tmp_couple->y_position = request.y_position ;
tmp_couple->z_position = request.z_position ;
tmp_couple->direction = request.direction ;
tmp_couple->next = NULL ;
tmp_couple->info = tmp_info ;
couples = tmp_couple ;
tmp_request->start_time = start_time ;
tmp_request->x_position = request.x_position ;
tmp_request->y_position = request.y_position ;
tmp_request->z_position = request.z_position ;
tmp_request->direction = request.direction ;
tmp_request->next = NULL ;
tmp_request->info = tmp_info ;
requests = tmp_request ;
}
else // If the couple list exists already
{ // we search the list for the couple
else // If the request list exists already
{ // we search the list for the request
// Explicit packet:
if (owl_timestamp_to_ms(request.request_time) != 0)
{
while (tmp_couple != NULL)
while (tmp_request != NULL)
{ // Research criterion: MAC and transmission time
if (owl_mac_equals(request.mobile_mac_addr_bytes,
tmp_couple->mobile_mac_addr_bytes) == 1
tmp_request->mobile_mac_addr_bytes) == 1
&& owl_time_elapsed_ms(request.request_time,
tmp_couple->request_time) == 0)
break ; // If the couple exists, we stop on it
tmp_couple = tmp_couple->next ;
tmp_request->request_time) == 0)
break ; // If the request exists, we stop on it
tmp_request = tmp_request->next ;
}
}
// Implicit packet:
else
{
while (tmp_couple != NULL)
while (tmp_request != NULL)
{ // Research criterion: MAC addresses equals and reception
// times on the APs less than 10 ms
// TODO : define an option for the maximal difference time.
if (owl_mac_equals(request.mobile_mac_addr_bytes,
tmp_couple->mobile_mac_addr_bytes) == 1
tmp_request->mobile_mac_addr_bytes) == 1
&& owl_time_elapsed_ms(request.start_time,
tmp_couple->request_time) <= 10)
break ; // If the couple exists, we stop on it
tmp_couple = tmp_couple->next ;
tmp_request->request_time) <= 10)
break ; // If the request exists, we stop on it
tmp_request = tmp_request->next ;
}
}
if (tmp_couple == NULL) // If the couple does not exist in the list,
if (tmp_request == NULL) // The request does not exist in the list
{
printf("Create new couple.\n") ;
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
memcpy(tmp_couple->mobile_mac_addr_bytes,
printf("Create new request.\n") ;
tmp_request = malloc(sizeof(request_list)) ; // create it
memcpy(tmp_request->mobile_mac_addr_bytes,
request.mobile_mac_addr_bytes, 6) ;
// Explicit packet:
if (owl_timestamp_to_ms(request.request_time) != 0)
// Transmission time on the mobile:
tmp_couple->request_time = request.request_time ;
tmp_request->request_time = request.request_time ;
// Implicit packet:
else
// Reception time on the AP:
tmp_couple->request_time = request.start_time ;
tmp_request->request_time = request.start_time ;
// Save locale time on the aggregator (not the reception time
// on the AP):
tmp_couple->start_time = start_time ;
tmp_couple->x_position = request.x_position ;
tmp_couple->y_position = request.y_position ;
tmp_couple->z_position = request.z_position ;
tmp_couple->direction = request.direction ;
tmp_couple->next = couples ;
tmp_couple->info = tmp_info ;
couples = tmp_couple ;
tmp_request->start_time = start_time ;
tmp_request->x_position = request.x_position ;
tmp_request->y_position = request.y_position ;
tmp_request->z_position = request.z_position ;
tmp_request->direction = request.direction ;
tmp_request->next = requests ;
tmp_request->info = tmp_info ;
requests = tmp_request ;
}
else // If the couple was found in the list
else // If the request was found in the list
{
if (tmp_couple->info == NULL)
{ // We already sent to the server data for this couple
if (tmp_request->info == NULL)
{ // We already sent to the server data for this request
printf("Request already treated.\n") ;
free(tmp_info) ;
}
else
{
printf("Add information to the couple.\n") ;
tmp_info->next = tmp_couple->info ; // Add data
tmp_couple->info = tmp_info ;
printf("Add information to the request.\n") ;
tmp_info->next = tmp_request->info ; // Add data
tmp_request->info = tmp_info ;
}
}
}
@ -720,24 +723,24 @@ void got_couple_info(owl_captured_request request)
/*
* Empties the couple list.
* Empties the request list.
*/
void free_couple_list()
void free_request_list()
{
couple_list *next_couple ;
couple_info_list *next_couple_info ;
request_list *next_request ;
request_info_list *next_request_info ;
while (couples != NULL)
while (requests != NULL)
{
while (couples->info != NULL)
while (requests->info != NULL)
{
next_couple_info = couples->info->next ;
free(couples->info) ;
couples->info = next_couple_info ;
next_request_info = requests->info->next ;
free(requests->info) ;
requests->info = next_request_info ;
}
next_couple = couples->next ;
free(couples) ;
couples = next_couple ;
next_request = requests->next ;
free(requests) ;
requests = next_request ;
}
}
@ -1058,33 +1061,33 @@ void free_ap_list()
#ifdef DEBUG
/*
* Prints the couple list.
* Prints the request list.
*/
void print_couple_list()
void print_request_list()
{
couple_list *couple_ptr = couples ;
couple_info_list *info_ptr = NULL ;
request_list *request_ptr = requests ;
request_info_list *info_ptr = NULL ;
char *mobile_mac_str ;
char
request_time_str[OWL_TIMESTAMP_STR_LEN],
start_time_str[OWL_TIMESTAMP_STR_LEN] ;
if (couples == NULL) // Empty list
if (requests == NULL) // Empty list
{
printf("Aucun couple.\n") ;
printf("No request.\n") ;
return ;
}
while (couple_ptr != NULL)
while (request_ptr != NULL)
{
info_ptr = couple_ptr->info ; // Get the sub-list pointer
info_ptr = request_ptr->info ; // Get the sub-list pointer
mobile_mac_str =
owl_mac_bytes_to_string(couple_ptr->mobile_mac_addr_bytes) ;
owl_mac_bytes_to_string(request_ptr->mobile_mac_addr_bytes) ;
owl_timestamp_to_string(request_time_str,
couple_ptr->request_time) ;
request_ptr->request_time) ;
owl_timestamp_to_string(start_time_str,
couple_ptr->start_time) ;
request_ptr->start_time) ;
printf("Mobile MAC: %s\n"
"Sequence number: %s\n"
"Reception timestamp: %s\n"
@ -1095,26 +1098,26 @@ void print_couple_list()
) ;
free(mobile_mac_str) ;
// Parse information relative to the current couple
// Parse information relative to the current request
while (info_ptr != NULL)
{
print_couple_info(info_ptr) ;
print_request_info(info_ptr) ;
putchar('\n') ;
info_ptr = info_ptr->next ;
}
printf("\n\n") ;
couple_ptr = couple_ptr->next ;
request_ptr = request_ptr->next ;
}
}
/*
* Prints an element of a couple_info_list.
* Prints an element of a request_info_list.
*/
void print_couple_info(couple_info_list *info)
void print_request_info(request_info_list *info)
{
char *ap_mac_str ;
if (info == NULL)