Home | History | Annotate | Download | only in algos

Lines Matching refs:sync

21 void time_sync_reset(time_sync_t *sync) {
22 sync->n = 0;
23 sync->i = 0;
24 sync->estimate_valid = false;
26 sync->hold_count = 0;
29 bool time_sync_init(time_sync_t *sync) {
30 time_sync_reset(sync);
35 void time_sync_truncate(time_sync_t *sync, size_t window_size) {
37 sync->n = (window_size < sync->n) ? window_size : sync->n;
38 sync->estimate_valid = false;
41 size_t bidx = (sync->i >= sync->n) ? (sync->i - sync->n)
42 : (sync->i + NUM_TIME_SYNC_DATAPOINTS - sync->n);
46 uint64_t tmp1 = sync->time1[0];
47 uint64_t tmp2 = sync->time2[0];
50 sync->time1[m] = sync->time1[m + 1];
51 sync->time2[m] = sync->time2[m + 1];
53 sync->time1[NUM_TIME_SYNC_DATAPOINTS - 1] = tmp1;
54 sync->time2[NUM_TIME_SYNC_DATAPOINTS - 1] = tmp2;
57 sync->i = (sync->n < NUM_TIME_SYNC_DATAPOINTS) ? sync->n : 0;
60 bool time_sync_add(time_sync_t *sync, uint64_t time1, uint64_t time2) {
61 size_t i = sync->i;
63 sync->time1[i] = time1;
64 sync->time2[i] = time2;
70 sync->i = i;
72 size_t prev_n = sync->n;
73 if (sync->n < NUM_TIME_SYNC_DATAPOINTS) {
74 ++sync->n;
77 sync->estimate_valid = false;
79 if (sync->hold_count > 0) {
80 --sync->hold_count;
81 time_sync_truncate(sync, prev_n);
87 bool time_sync_estimate_time1(time_sync_t *sync, uint64_t time2, uint64_t *time1)
91 if (sync->n < 2)
96 if (!sync->estimate_valid) {
97 size_t n = sync->n;
100 size_t i = sync->i;
108 uint64_t time1_base = sync->time1[i];
109 uint64_t time2_base = sync->time2[i];
119 mean_y += floatFromUint64(sync->time1[ii] - time1_base) * invN;
120 mean_x += floatFromUint64(sync->time2[ii] - time2_base) * invN;
134 float y = floatFromUint64(sync->time1[ii] - time1_base) - mean_y;
135 float x = floatFromUint64(sync->time2[ii] - time2_base) - mean_x;
148 sync->alpha = alpha;
149 sync->beta = beta;
150 sync->time1_base = time1_base;
151 sync->time2_base = time2_base;
153 sync->estimate_valid = true;
156 *time1 = sync->time1_base + floatToInt64(sync->alpha + sync->beta * floatFromInt64(time2 - sync->time2_base));
161 void time_sync_hold(time_sync_t *sync, uint8_t count) {
162 sync->hold_count = count;