[lib] Add timestamp_to_string()
This commit is contained in:
parent
d0b15bf978
commit
788a61a712
|
@ -15,7 +15,7 @@ BOOL run = TRUE ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converts a MAC address from bytes to string.
|
* Converts a MAC address from bytes to string.
|
||||||
* /!\ You *must* manually free the returned string /!\
|
* /!\ You *must* manually free the returned string. /!\
|
||||||
*/
|
*/
|
||||||
char* owl_mac_bytes_to_string(uint8_t *mac_binary)
|
char* owl_mac_bytes_to_string(uint8_t *mac_binary)
|
||||||
{
|
{
|
||||||
|
@ -147,6 +147,19 @@ uint64_t owl_timestamp_to_ms(TIMESTAMP d)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converts a TIMESTAMP date value into a printable string.
|
||||||
|
* 'dst' must be an allocated array of at least TIMESTAMP_STR_LEN
|
||||||
|
* characters.
|
||||||
|
*/
|
||||||
|
void owl_timestamp_to_string(char *dst, TIMESTAMP src)
|
||||||
|
{
|
||||||
|
snprintf(dst, TIMESTAMP_STR_LEN, "%"PRIu32".%"PRIu32,
|
||||||
|
src.tv_sec, src.tv_nsec) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the time (in milliseconds) between two dates.
|
* Returns the time (in milliseconds) between two dates.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -66,6 +66,8 @@ typedef struct _TIMESTAMP
|
||||||
uint32_t tv_sec ;
|
uint32_t tv_sec ;
|
||||||
uint32_t tv_nsec ;
|
uint32_t tv_nsec ;
|
||||||
} TIMESTAMP ;
|
} TIMESTAMP ;
|
||||||
|
// Length of a TIMESTAMP when converted to string:
|
||||||
|
#define TIMESTAMP_STR_LEN 22 // 22 = 10 digits, '.', 10 digits, '\0'
|
||||||
|
|
||||||
|
|
||||||
/* Message sent by the listener to the aggregator */
|
/* Message sent by the listener to the aggregator */
|
||||||
|
@ -230,6 +232,7 @@ uint_fast8_t owl_frequency_to_channel(uint_fast16_t channel) ;
|
||||||
int owl_timestamp_now(TIMESTAMP *now) ;
|
int owl_timestamp_now(TIMESTAMP *now) ;
|
||||||
TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) ;
|
TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) ;
|
||||||
TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ;
|
TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ;
|
||||||
|
void owl_timestamp_to_string(char *dst, TIMESTAMP src) ;
|
||||||
uint64_t owl_timestamp_to_ms(TIMESTAMP date) ;
|
uint64_t owl_timestamp_to_ms(TIMESTAMP date) ;
|
||||||
uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||||
TIMESTAMP owl_hton_timestamp(TIMESTAMP date) ;
|
TIMESTAMP owl_hton_timestamp(TIMESTAMP date) ;
|
||||||
|
|
Loading…
Reference in New Issue