diff --git a/TODO b/TODO index 1cf254e..e7e847d 100644 --- a/TODO +++ b/TODO @@ -1,4 +1 @@ -Abandonner gettimeofday() et struct timeval au profit de clock_gettime() -et struct timespec. gettimeofday() est obsolète depuis POSIX:2008. - Abandonner int, long & Cie pour les échanges de données, passer à stdint.h diff --git a/infrastructure-centred/owlps-client/Makefile b/infrastructure-centred/owlps-client/Makefile index 3ca989a..bfe3614 100644 --- a/infrastructure-centred/owlps-client/Makefile +++ b/infrastructure-centred/owlps-client/Makefile @@ -25,7 +25,7 @@ DEPFLAGS = -MMD XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) PICFLAG = -fPIC LIBS = -L../../libowlps -lowlps -L../libowlps-client -lowlps-client -STATIC_LIBS = -liw -lm +STATIC_LIBS = -liw -lm -lrt ## Cibles de compilation standard ## diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index c17be17..1f026f0 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -629,7 +629,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, return ; memcpy(couple.ap_mac_addr_bytes, my_mac, 6) ; // Copy AP MAC - couple.start_time = header->ts ; // Capture time is in the pcap header + // Capture time is in the pcap header: + couple.start_time = timeval_to_timestamp(header->ts) ; // Transmission time on the mobile is unknown (unless the packet is // an explicit request): bzero(&couple.request_time, sizeof(TIMESTAMP)) ; diff --git a/libowlps/Makefile b/libowlps/Makefile index f0289e1..60a44c3 100644 --- a/libowlps/Makefile +++ b/libowlps/Makefile @@ -38,7 +38,7 @@ CFLAGS=-O2 -Wall -Wextra -Wstrict-prototypes -O -I. DEPFLAGS=-MMD XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) PICFLAG=-fPIC -LIBS=-liw +LIBS = -liw -lrt #STRIPFLAGS= -Wl,-s #LDFLAGS= diff --git a/libowlps/Makefile_atheros b/libowlps/Makefile_atheros index 07161ca..372d8e8 100644 --- a/libowlps/Makefile_atheros +++ b/libowlps/Makefile_atheros @@ -38,7 +38,7 @@ CFLAGS=-O2 -Wall -Wextra -Wstrict-prototypes -O -I. DEPFLAGS=-MMD XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS) PICFLAG=-fPIC -LIBS=-liw +LIBS = -liw -lrt #STRIPFLAGS= -Wl,-s #LDFLAGS= LATHEROS=-L$(TOOLCHAIN)/mips/usr/lib/ diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index 149af98..e29e711 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -91,12 +91,50 @@ char frequency_to_channel(unsigned short channel) /* - * Set the TIMESTAMP 'now' at the current time. + * Set the TIMESTAMP 'now' at the current time (millisecond-precision). */ void timestamp_now(TIMESTAMP *now) { - if (gettimeofday(now, NULL)) - perror("Cannot get the current time") ; + if (timestamp_now_ns(now)) + timestamp_round_to_ms(now) ; +} + + + +/* + * Set the TIMESTAMP 'now' at the current time (nanosecond-precision). + */ +BOOL timestamp_now_ns(TIMESTAMP *now) +{ + if (clock_gettime(CLOCK_REALTIME, now)) + { + perror("Cannot get the current time") ; + return FALSE ; + } + return TRUE ; +} + + + +/* + * Lower the precision of 'now' to milliseconds. + */ +void timestamp_round_to_ms(TIMESTAMP *now) +{ + now->tv_nsec = now->tv_nsec / 1000000 * 1000000 ; +} + + + +/* + * Returns a TIMESTAMP from a struct timeval. + */ +TIMESTAMP timeval_to_timestamp(const struct timeval d) +{ + TIMESTAMP res ; + res.tv_sec = d.tv_sec ; + res.tv_nsec = d.tv_usec * 1000 ; + return res ; } @@ -106,25 +144,11 @@ void timestamp_now(TIMESTAMP *now) */ unsigned long long timestamp_to_ms(TIMESTAMP d) { - return d.tv_sec * 1000 + d.tv_usec / 1000 ; + return d.tv_sec * 1000 + d.tv_nsec / 1000000 ; } -/* - * Converts a date value in milliseconds into a TIMESTAMP. - * -TIMESTAMP ms_to_timestamp(unsigned long long tms) -{ - TIMESTAMP d ; - d.tv_sec = tms / 1000 ; - d.tv_usec = (tms - d.tv_sec * 1000) * 1000 ; - return d ; -} -*/ - - - /* * Returns the time (in milliseconds) between two dates. */ diff --git a/libowlps/owlps.h b/libowlps/owlps.h index c6ab664..b4a99f4 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -13,7 +13,6 @@ #include -#include #include #include @@ -61,7 +60,7 @@ typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ; /* Timestamp type */ -typedef struct timeval TIMESTAMP ; +typedef struct timespec TIMESTAMP ; /* Message sent by the listener to the aggregator */ @@ -224,6 +223,9 @@ char frequency_to_channel(unsigned short channel) ; // Time void timestamp_now(TIMESTAMP *now) ; +BOOL timestamp_now_ns(TIMESTAMP *now) ; +void timestamp_round_to_ms(TIMESTAMP *now) ; +TIMESTAMP timeval_to_timestamp(const struct timeval d) ; unsigned long long timestamp_to_ms(TIMESTAMP date) ; unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;