diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index bc7edeb..a8cb571 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -107,11 +107,15 @@ void owl_timestamp_now(TIMESTAMP *now) int owl_timestamp_now_ns(TIMESTAMP *now) { int ret ; - if ((ret = clock_gettime(CLOCK_REALTIME, now))) + struct timespec now_ts ; + if ((ret = clock_gettime(CLOCK_REALTIME, &now_ts))) { perror("Cannot get the current time") ; return ret ; } + + *now = owl_timespec_to_timestamp(now_ts) ; + return 0 ; } @@ -127,6 +131,19 @@ void owl_timestamp_round_to_ms(TIMESTAMP *now) +/* + * Returns a TIMESTAMP from a struct timespec. + */ +TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) +{ + TIMESTAMP res ; + res.tv_sec = d.tv_sec ; + res.tv_nsec = d.tv_nsec ; + return res ; +} + + + /* * Returns a TIMESTAMP from a struct timeval. */ diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 51fe315..c0944df 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -60,8 +60,12 @@ typedef enum {FALSE, TRUE} BOOL ; typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ; -/* Timestamp type */ -typedef struct timespec TIMESTAMP ; +/* Timestamp type (struct timespec clone with fix-sized fields) */ +typedef struct _TIMESTAMP +{ + uint32_t tv_sec ; + uint32_t tv_nsec ; +} TIMESTAMP ; /* Message sent by the listener to the aggregator */ @@ -226,6 +230,7 @@ uint_fast8_t owl_frequency_to_channel(uint_fast16_t channel) ; void owl_timestamp_now(TIMESTAMP *now) ; int owl_timestamp_now_ns(TIMESTAMP *now) ; void owl_timestamp_round_to_ms(TIMESTAMP *now) ; +TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) ; TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ; uint64_t owl_timestamp_to_ms(TIMESTAMP date) ; uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;