[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 #define ERR_SENDING_INFO 5 // Error sending a message on a socket
/* Linked list storing data of couples MAC / sequence number */ /* Linked list storing data of each request */
typedef struct _couple_info_list typedef struct _request_info_list
{ {
// MAC address of the data sender (in bytes): // MAC address of the data sender (in bytes):
uint8_t ap_mac_addr_bytes[6] ; uint8_t ap_mac_addr_bytes[6] ;
// Signal strength received by the AP from the mobile: // Signal strength received by the AP from the mobile:
uint8_t antenna_signal_dbm ; uint8_t antenna_signal_dbm ;
struct _couple_info_list *next ; struct _request_info_list *next ;
} couple_info_list ; } request_info_list ;
/* Linked list of the couples MAC / sequence number */ /* Linked list of the requests */
typedef struct _couple_list 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) uint8_t mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
owl_timestamp request_time ; // Request time on the mobile owl_timestamp request_time ; // Request time on the mobile
@ -59,12 +59,12 @@ typedef struct _couple_list
owl_direction direction ; // Request orientation owl_direction direction ; // Request orientation
/* Other data */ /* 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 ; owl_timestamp start_time ;
couple_info_list *info ; // Data for this couple request_info_list *info ; // Data for this request
struct _couple_list *next ; struct _request_list *next ;
} couple_list ; } request_list ;
/* Linked list of the known APs */ /* Linked list of the known APs */
@ -87,13 +87,13 @@ void parse_command_line(int argc, char **argv) ;
void check_configuration(void) ; void check_configuration(void) ;
int read_loop(int sockfd) ; 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* monitor_requests(void) ;
void free_couple_list(void) ; void free_request_list(void) ;
#ifdef DEBUG #ifdef DEBUG
void print_couple_list(void) ; void print_request_list(void) ;
void print_couple_info(couple_info_list *info) ; void print_request_info(request_info_list *info) ;
#endif // DEBUG #endif // DEBUG
void listen_for_aps(void) ; void listen_for_aps(void) ;

View File

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