clock.h 810 Bytes
Newer Older
1
2
3
#ifndef PRRT_CLOCK_H
#define PRRT_CLOCK_H

4
#include "packet.h"
5
#include <stdint.h>
6
#include <stdbool.h>
7

8
9
10
#define MAX_TIMESTAMP (prrtTimestamp_t) 4294967295
#define HALF_TIMESTAMP (prrtTimestamp_t) 2147483648

11
typedef struct prrtClock {
Andreas Schmidt's avatar
Andreas Schmidt committed
12
13
    prrtTimestamp_t lastMeasurement;
    prrtTimedelta_t meanDeviation;
14
    int32_t skew;
Andreas Schmidt's avatar
Andreas Schmidt committed
15
    prrtTimestamp_t virtualTime;
16
17
18
} PrrtClock;


Andreas Schmidt's avatar
Andreas Schmidt committed
19
PrrtClock* PrrtClock_create(void);
20
21
bool PrrtClock_destroy(PrrtClock* clock);

Andreas Schmidt's avatar
Andreas Schmidt committed
22
23
prrtTimestamp_t PrrtClock_get_current_time_us(void);
prrtTimestamp_t PrrtClock_get_current_time_ms(void);
24
prrtTimestamp_t PrrtClock_get_prrt_time_us(PrrtClock *clock);
25

Andreas Schmidt's avatar
Andreas Schmidt committed
26
bool PrrtClock_update(PrrtClock *clock, prrtTimestamp_t referenceTime, prrtTimedelta_t rtt);
27

28
29
#define diff_ts(timeA, timeB) abs(((int32_t) timeA) - ((int32_t)timeB))

30
#endif //PRRT_CLOCK_H