tmv: Add a method to convert to a struct Timestamp.

This will be needed in order to generate a TLV for the NSM protocol.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2017-11-26 18:40:51 -08:00
parent 36550e415c
commit 7a2013360a
1 changed files with 15 additions and 0 deletions

15
tmv.h
View File

@ -114,6 +114,21 @@ static inline TimeInterval tmv_to_TimeInterval(tmv_t x)
return x.ns << 16; return x.ns << 16;
} }
static inline struct Timestamp tmv_to_Timestamp(tmv_t x)
{
struct Timestamp result;
uint64_t sec, nsec;
sec = x.ns / 1000000000ULL;
nsec = x.ns % 1000000000ULL;
result.seconds_lsb = sec & 0xFFFFFFFF;
result.seconds_msb = (sec >> 32) & 0xFFFF;
result.nanoseconds = nsec;
return result;
}
static inline tmv_t timespec_to_tmv(struct timespec ts) static inline tmv_t timespec_to_tmv(struct timespec ts)
{ {
tmv_t t; tmv_t t;