[Aggregator] Use timestamp_to_string()

Use owl_timestamp_to_string() instead of owl_timestamp_to_ms() to
display the timestamps.
This commit is contained in:
Matteo Cypriani 2011-03-15 17:55:29 +01:00
parent 0b5ebc524f
commit 795ac90614
1 changed files with 62 additions and 46 deletions

View File

@ -328,9 +328,11 @@ int read_loop(int sockfd)
socklen_t client_len = sizeof(client) ; // Size of clients socklen_t client_len = sizeof(client) ; // Size of clients
couple_message message ; // Message read on the socket couple_message message ; // Message read on the socket
char char
*ap_mac_string, // Return pointers for mac_bytes_to_string() *ap_mac_str, // Return pointers for owl_mac_bytes_to_string(),
*mobile_mac_string, *mobile_mac_str,
*mobile_ip_string ; // and ip_bytes_to_string() *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) while (run)
{ {
@ -349,48 +351,51 @@ int read_loop(int sockfd)
if (cfg_getbool(cfg, "verbose")) if (cfg_getbool(cfg, "verbose"))
{ {
ap_mac_string = ap_mac_str =
owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ; 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) ; 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) ; 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" printf("\n"
"*** Request received from AP ***\n" "*** Request received from AP ***\n"
"\tAP MAC: %s\n" "\tAP MAC: %s\n"
"\tMobile MAC: %s\n" "\tMobile MAC: %s\n"
"\tMobile IP: %s\n" "\tMobile IP: %s\n"
"\tSequence number (request timestamp): %"PRIu64"\n" "\tSequence number (request timestamp): %s\n"
"\tRequest arrival time on the AP: %"PRIu64"\n" "\tRequest arrival time on the AP: %s\n"
"\tSignal: %d dBm\n" "\tSignal: %d dBm\n"
"\tPosition X: %f\n" "\tPosition X: %f\n"
"\tPosition Y: %f\n" "\tPosition Y: %f\n"
"\tPosition Z: %f\n" "\tPosition Z: %f\n"
"\tDirection: %hhd\n" "\tDirection: %hhd\n"
, ,
ap_mac_string, ap_mac_str,
mobile_mac_string, mobile_mac_str,
mobile_ip_string, mobile_ip_str,
owl_timestamp_to_ms(message.request_time), request_time_str,
owl_timestamp_to_ms(message.start_time), start_time_str,
message.antenna_signal_dbm - 0x100, message.antenna_signal_dbm - 0x100,
message.x_position, message.x_position,
message.y_position, message.y_position,
message.z_position, message.z_position,
message.direction message.direction
) ; ) ;
free(ap_mac_string) ; free(ap_mac_str) ;
free(mobile_mac_string) ; free(mobile_mac_str) ;
free(mobile_ip_string) ; free(mobile_ip_str) ;
} }
#ifdef DEBUG #ifdef DEBUG
else else
{ {
ap_mac_string = ap_mac_str =
owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ; owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ;
fprintf(stderr, "Request received from AP « %s ».\n", fprintf(stderr, "Request received from AP « %s ».\n",
ap_mac_string) ; ap_mac_str) ;
free(ap_mac_string) ; free(ap_mac_str) ;
} }
#endif // DEBUG #endif // DEBUG
@ -412,8 +417,11 @@ void* monitor_couples()
couple_info_list *couple_info_ptr ; couple_info_list *couple_info_ptr ;
TIMESTAMP current_time ; TIMESTAMP current_time ;
FILE *fd = NULL ; FILE *fd = NULL ;
char *mac_string ; char *mac_str ;
uint_fast32_t sub ; // owl_time_elapsed_ms() result 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 = uint_fast32_t aggregate_timeout =
cfg_getint(cfg, "aggregate_timeout") ; cfg_getint(cfg, "aggregate_timeout") ;
@ -472,16 +480,17 @@ void* monitor_couples()
#endif // DEBUG #endif // DEBUG
// Print mobile MAC address to the output file // Print mobile MAC address to the output file
mac_string = mac_str =
owl_mac_bytes_to_string(couple_ptr owl_mac_bytes_to_string(couple_ptr
->mobile_mac_addr_bytes) ; ->mobile_mac_addr_bytes) ;
fprintf(fd, "%s;", mac_string) ; fprintf(fd, "%s;", mac_str) ;
free(mac_string) ; free(mac_str) ;
#ifdef USE_TIMESTAMP #ifdef USE_TIMESTAMP
// Print request mobile timestamp to the output file // Print request mobile timestamp to the output file
fprintf(fd, "%"PRIu64";", owl_timestamp_to_string(request_time_str,
owl_timestamp_to_ms(couple_ptr->request_time)) ; couple_ptr->request_time) ;
fprintf(fd, "%s;", request_time_str) ;
#endif // USE_TIMESTAMP #endif // USE_TIMESTAMP
// Print couple info to the output file // Print couple info to the output file
@ -516,12 +525,12 @@ void* monitor_couples()
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_string = mac_str =
owl_mac_bytes_to_string(couple_info_ptr owl_mac_bytes_to_string(couple_info_ptr
->ap_mac_addr_bytes) ; ->ap_mac_addr_bytes) ;
fprintf(fd, ";%s;%d", mac_string, fprintf(fd, ";%s;%d", mac_str,
couple_info_ptr->antenna_signal_dbm - 0x100) ; couple_info_ptr->antenna_signal_dbm - 0x100) ;
free(mac_string) ; free(mac_str) ;
// Delete couple // Delete couple
couple_info_ptr = couple_info_ptr->next ; 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]) ap_list* add_ap_front(uint8_t mac_addr_bytes[6])
{ {
#ifdef DEBUG #ifdef DEBUG
char *mac = owl_mac_bytes_to_string(mac_addr_bytes) ; char *mac_str = owl_mac_bytes_to_string(mac_addr_bytes) ;
fprintf(stderr, "Creating AP with MAC address « %s »...\n", mac) ; fprintf(stderr, "Creating AP with MAC address « %s »...\n", mac_str) ;
free(mac) ; free(mac_str) ;
#endif // DEBUG #endif // DEBUG
ap_list *ap = malloc(sizeof(ap_list)) ; ap_list *ap = malloc(sizeof(ap_list)) ;
@ -935,9 +944,9 @@ void delete_ap(ap_list *ap)
{ {
#ifdef DEBUG #ifdef DEBUG
assert(ap) ; assert(ap) ;
char *mac = owl_mac_bytes_to_string(token_aps->mac_addr_bytes) ; char *mac_str = owl_mac_bytes_to_string(token_aps->mac_addr_bytes) ;
fprintf(stderr, "Deleting AP « %s »...\n", mac) ; fprintf(stderr, "Deleting AP « %s »...\n", mac_str) ;
free(mac) ; free(mac_str) ;
#endif // DEBUG #endif // DEBUG
unlink_ap(ap) ; unlink_ap(ap) ;
@ -1044,7 +1053,10 @@ void print_couple_list()
{ {
couple_list *couple_ptr = couples ; couple_list *couple_ptr = couples ;
couple_info_list *info_ptr = NULL ; 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 if (couples == NULL) // Empty list
{ {
@ -1056,17 +1068,21 @@ void print_couple_list()
{ {
info_ptr = couple_ptr->info ; // Get the sub-list pointer 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_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" printf("Mobile MAC: %s\n"
"Sequence number: %"PRIu64"\n" "Sequence number: %s\n"
"Reception timestamp: %"PRIu64"\n" "Reception timestamp: %s\n"
"\n", "\n",
mobile_mac_string, mobile_mac_str,
owl_timestamp_to_ms(couple_ptr->request_time), request_time_str,
owl_timestamp_to_ms(couple_ptr->start_time) start_time_str
) ; ) ;
free(mobile_mac_string) ; free(mobile_mac_str) ;
// Parse information relative to the current couple // Parse information relative to the current couple
while (info_ptr != NULL) while (info_ptr != NULL)
@ -1089,17 +1105,17 @@ void print_couple_list()
*/ */
void print_couple_info(couple_info_list *info) void print_couple_info(couple_info_list *info)
{ {
char *ap_mac_string ; char *ap_mac_str ;
if (info == NULL) if (info == NULL)
return ; 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" printf("\tAP MAC: %s\n"
"\tSignal strength: %d dBm\n", "\tSignal strength: %d dBm\n",
ap_mac_string, ap_mac_str,
info->antenna_signal_dbm - 0x100 info->antenna_signal_dbm - 0x100
) ; ) ;
free(ap_mac_string) ; free(ap_mac_str) ;
} }
#endif // DEBUG #endif // DEBUG