reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
clock-sync.h
Go to the documentation of this file.
1
16
17#ifndef CLOCK_SYNC_H
18#define CLOCK_SYNC_H
19
20#include "low_level_platform.h"
21#include "net_abstraction.h"
22
23#ifndef LF_CLOCK_SYNC
33#define LF_CLOCK_SYNC LF_CLOCK_SYNC_INIT
34#endif
35
40#define LF_CLOCK_SYNC_OFF 1
41
46#define LF_CLOCK_SYNC_INIT 2
47
52#define LF_CLOCK_SYNC_ON 3
53
61#ifndef _LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL
62#define _LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL 10
63#endif
64
69#ifndef _LF_CLOCK_SYNC_ATTENUATION
70#define _LF_CLOCK_SYNC_ATTENUATION 10
71#endif
72
77#ifndef _LF_CLOCK_SYNC_COLLECT_STATS
78#define _LF_CLOCK_SYNC_COLLECT_STATS true
79#endif
80
90#define CLOCK_SYNC_GUARD_BAND USEC(100)
91
197
202typedef struct lf_stat_ll {
203 int64_t average;
205 int64_t variance;
206 int64_t max;
208
215void reset_socket_stat(struct socket_stat_t* socket_stat);
216
227
245void synchronize_initial_physical_clock_with_rti(net_abstraction_t rti_net);
246
261int handle_T1_clock_sync_message(unsigned char* buffer, void* socket_or_net, instant_t t2, socket_type_t socket_type);
262
282void handle_T4_clock_sync_message(unsigned char* buffer, void* socket_or_net, instant_t r4, socket_type_t socket_type);
283
293int create_clock_sync_thread(lf_thread_t* thread_id);
294
302
310
320
321#endif // CLOCK_SYNC_H
int64_t instant_t
Time instant.
Definition tag.h:101
int64_t interval_t
Interval of time.
Definition tag.h:107
void clock_sync_set_constant_bias(interval_t offset)
Set a fixed offset to the physical clock.
void clock_sync_add_offset(instant_t *t)
Add the current clock synchronization offset to a specified timestamp.
void synchronize_initial_physical_clock_with_rti(net_abstraction_t rti_net)
Synchronize the initial physical clock with the RTI.
uint16_t setup_clock_synchronization_with_rti(void)
Setup necessary functionalities to synchronize clock with the RTI.
int handle_T1_clock_sync_message(unsigned char *buffer, void *socket_or_net, instant_t t2, socket_type_t socket_type)
Handle a clock synchroninzation message T1 coming from the RTI.
#define _LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL
Number of required clock sync T4 messages per synchronization interval.
Definition clock-sync.h:62
int create_clock_sync_thread(lf_thread_t *thread_id)
Create the thread responsible for handling clock synchronization with the RTI if (runtime) clock sync...
void reset_socket_stat(struct socket_stat_t *socket_stat)
Reset statistics on the socket.
void handle_T4_clock_sync_message(unsigned char *buffer, void *socket_or_net, instant_t r4, socket_type_t socket_type)
Handle a clock synchronization message T4 coming from the RTI.
void clock_sync_subtract_offset(instant_t *t)
Subtract the clock synchronization offset from a timestamp.
Platform API support for the C target of Lingua Franca.
Holds generic statistical data.
Definition clock-sync.h:202
int64_t standard_deviation
Definition clock-sync.h:204
int64_t variance
Definition clock-sync.h:205
int64_t max
Definition clock-sync.h:206
int64_t average
Definition clock-sync.h:203
Statistics and state for clock synchronization over a socket connection.
Definition clock-sync.h:109
interval_t network_stat_round_trip_delay_max
Maximum observed round-trip network delay.
Definition clock-sync.h:163
instant_t remote_physical_clock_snapshot_T1
Remote (RTI) physical time when sending sync message (T1).
Definition clock-sync.h:117
int network_stat_sample_index
Current index in the network statistics samples array.
Definition clock-sync.h:172
interval_t local_delay
Estimated local processing delay (T3 - T2).
Definition clock-sync.h:135
interval_t network_stat_samples[10]
Array of network delay samples.
Definition clock-sync.h:195
interval_t clock_synchronization_error_bound
Bound on clock synchronization error.
Definition clock-sync.h:182
interval_t history
Running history of clock synchronization data.
Definition clock-sync.h:154
int received_T4_messages_in_current_sync_window
Counter for T4 messages received in current sync window.
Definition clock-sync.h:145
instant_t local_physical_clock_snapshot_T2
Local (federate) physical time when receiving T1 (T2).
Definition clock-sync.h:126