From 795ac9061463c0edf71f4b4f8fbd3612fbfe5061 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 15 Mar 2011 17:55:29 +0100 Subject: [PATCH] [Aggregator] Use timestamp_to_string() Use owl_timestamp_to_string() instead of owl_timestamp_to_ms() to display the timestamps. --- .../owlps-aggregator/owlps-aggregatord.c | 108 ++++++++++-------- 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c index 22d7de1..e50e474 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c @@ -328,9 +328,11 @@ int read_loop(int sockfd) socklen_t client_len = sizeof(client) ; // Size of clients couple_message message ; // Message read on the socket char - *ap_mac_string, // Return pointers for mac_bytes_to_string() - *mobile_mac_string, - *mobile_ip_string ; // and ip_bytes_to_string() + *ap_mac_str, // Return pointers for owl_mac_bytes_to_string(), + *mobile_mac_str, + *mobile_ip_str, // ip_bytes_to_string(), + request_time_str[TIMESTAMP_STR_LEN], // and owl_timestamp_to_string() + start_time_str[TIMESTAMP_STR_LEN] ; while (run) { @@ -349,48 +351,51 @@ int read_loop(int sockfd) if (cfg_getbool(cfg, "verbose")) { - ap_mac_string = + ap_mac_str = owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ; - mobile_mac_string = + mobile_mac_str = owl_mac_bytes_to_string(message.mobile_mac_addr_bytes) ; - mobile_ip_string = + mobile_ip_str = ip_bytes_to_string(message.mobile_ip_addr_bytes) ; + owl_timestamp_to_string(request_time_str, + message.request_time) ; + owl_timestamp_to_string(start_time_str, message.start_time) ; printf("\n" "*** Request received from AP ***\n" "\tAP MAC: %s\n" "\tMobile MAC: %s\n" "\tMobile IP: %s\n" - "\tSequence number (request timestamp): %"PRIu64"\n" - "\tRequest arrival time on the AP: %"PRIu64"\n" + "\tSequence number (request timestamp): %s\n" + "\tRequest arrival time on the AP: %s\n" "\tSignal: %d dBm\n" "\tPosition X: %f\n" "\tPosition Y: %f\n" "\tPosition Z: %f\n" "\tDirection: %hhd\n" , - ap_mac_string, - mobile_mac_string, - mobile_ip_string, - owl_timestamp_to_ms(message.request_time), - owl_timestamp_to_ms(message.start_time), + ap_mac_str, + mobile_mac_str, + mobile_ip_str, + request_time_str, + start_time_str, message.antenna_signal_dbm - 0x100, message.x_position, message.y_position, message.z_position, message.direction ) ; - free(ap_mac_string) ; - free(mobile_mac_string) ; - free(mobile_ip_string) ; + free(ap_mac_str) ; + free(mobile_mac_str) ; + free(mobile_ip_str) ; } #ifdef DEBUG else { - ap_mac_string = + ap_mac_str = owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ; fprintf(stderr, "Request received from AP « %s ».\n", - ap_mac_string) ; - free(ap_mac_string) ; + ap_mac_str) ; + free(ap_mac_str) ; } #endif // DEBUG @@ -412,8 +417,11 @@ void* monitor_couples() couple_info_list *couple_info_ptr ; TIMESTAMP current_time ; FILE *fd = NULL ; - char *mac_string ; + char *mac_str ; uint_fast32_t sub ; // owl_time_elapsed_ms() result +#ifdef USE_TIMESTAMP + char request_time_str[TIMESTAMP_STR_LEN] ; +#endif // USE_TIMESTAMP uint_fast32_t aggregate_timeout = cfg_getint(cfg, "aggregate_timeout") ; @@ -472,16 +480,17 @@ void* monitor_couples() #endif // DEBUG // Print mobile MAC address to the output file - mac_string = + mac_str = owl_mac_bytes_to_string(couple_ptr ->mobile_mac_addr_bytes) ; - fprintf(fd, "%s;", mac_string) ; - free(mac_string) ; + fprintf(fd, "%s;", mac_str) ; + free(mac_str) ; #ifdef USE_TIMESTAMP // Print request mobile timestamp to the output file - fprintf(fd, "%"PRIu64";", - owl_timestamp_to_ms(couple_ptr->request_time)) ; + owl_timestamp_to_string(request_time_str, + couple_ptr->request_time) ; + fprintf(fd, "%s;", request_time_str) ; #endif // USE_TIMESTAMP // Print couple info to the output file @@ -516,12 +525,12 @@ void* monitor_couples() 0, (struct sockaddr *)&serv, serv_len) ; // Print AP info to the output file - mac_string = + mac_str = owl_mac_bytes_to_string(couple_info_ptr ->ap_mac_addr_bytes) ; - fprintf(fd, ";%s;%d", mac_string, + fprintf(fd, ";%s;%d", mac_str, couple_info_ptr->antenna_signal_dbm - 0x100) ; - free(mac_string) ; + free(mac_str) ; // Delete couple couple_info_ptr = couple_info_ptr->next ; @@ -825,9 +834,9 @@ ap_list* find_ap(uint8_t mac_addr_bytes[6]) ap_list* add_ap_front(uint8_t mac_addr_bytes[6]) { #ifdef DEBUG - char *mac = owl_mac_bytes_to_string(mac_addr_bytes) ; - fprintf(stderr, "Creating AP with MAC address « %s »...\n", mac) ; - free(mac) ; + char *mac_str = owl_mac_bytes_to_string(mac_addr_bytes) ; + fprintf(stderr, "Creating AP with MAC address « %s »...\n", mac_str) ; + free(mac_str) ; #endif // DEBUG ap_list *ap = malloc(sizeof(ap_list)) ; @@ -935,9 +944,9 @@ void delete_ap(ap_list *ap) { #ifdef DEBUG assert(ap) ; - char *mac = owl_mac_bytes_to_string(token_aps->mac_addr_bytes) ; - fprintf(stderr, "Deleting AP « %s »...\n", mac) ; - free(mac) ; + char *mac_str = owl_mac_bytes_to_string(token_aps->mac_addr_bytes) ; + fprintf(stderr, "Deleting AP « %s »...\n", mac_str) ; + free(mac_str) ; #endif // DEBUG unlink_ap(ap) ; @@ -1044,7 +1053,10 @@ void print_couple_list() { couple_list *couple_ptr = couples ; couple_info_list *info_ptr = NULL ; - char *mobile_mac_string ; + char *mobile_mac_str ; + char + request_time_str[TIMESTAMP_STR_LEN], + start_time_str[TIMESTAMP_STR_LEN] ; if (couples == NULL) // Empty list { @@ -1056,17 +1068,21 @@ void print_couple_list() { info_ptr = couple_ptr->info ; // Get the sub-list pointer - mobile_mac_string = + mobile_mac_str = owl_mac_bytes_to_string(couple_ptr->mobile_mac_addr_bytes) ; + owl_timestamp_to_string(request_time_str, + couple_ptr->request_time) ; + owl_timestamp_to_string(start_time_str, + couple_ptr->start_time) ; printf("Mobile MAC: %s\n" - "Sequence number: %"PRIu64"\n" - "Reception timestamp: %"PRIu64"\n" + "Sequence number: %s\n" + "Reception timestamp: %s\n" "\n", - mobile_mac_string, - owl_timestamp_to_ms(couple_ptr->request_time), - owl_timestamp_to_ms(couple_ptr->start_time) + mobile_mac_str, + request_time_str, + start_time_str ) ; - free(mobile_mac_string) ; + free(mobile_mac_str) ; // Parse information relative to the current couple while (info_ptr != NULL) @@ -1089,17 +1105,17 @@ void print_couple_list() */ void print_couple_info(couple_info_list *info) { - char *ap_mac_string ; + char *ap_mac_str ; if (info == NULL) return ; - ap_mac_string = owl_mac_bytes_to_string(info->ap_mac_addr_bytes) ; + ap_mac_str = owl_mac_bytes_to_string(info->ap_mac_addr_bytes) ; printf("\tAP MAC: %s\n" "\tSignal strength: %d dBm\n", - ap_mac_string, + ap_mac_str, info->antenna_signal_dbm - 0x100 ) ; - free(ap_mac_string) ; + free(ap_mac_str) ; } #endif // DEBUG