Home | History | Annotate | Download | only in algos

Lines Matching refs:sync

38 void apHubSyncReset(struct ApHubSync* sync) {
39 sync->state = 0;
41 osLog(LOG_DEBUG, "ApHub sync reset");
45 void apHubSyncAddDelta(struct ApHubSync* sync, uint64_t apTime, uint64_t hubTime) {
50 if (apTime > sync->lastTs + SYNC_EXPIRATION || sync->lastTs == 0) {
51 apHubSyncReset(sync);
54 sync->lastTs = apTime;
56 if (sync->state == NOT_INITED) {
58 sync->windowMax = delta;
59 sync->windowTimeout = apTime + SYNC_WINDOW_TIMEOUT;
61 sync->state = USE_MAX;
63 sync->windowMax = (delta > sync->windowMax) ? delta : sync->windowMax;
64 if (apTime > sync->windowTimeout) {
68 if (sync->state == USE_MAX) {
69 sync->deltaEstimation = sync->windowMax;
71 sync->deltaEstimation = ((SYNC_FILTER_B - SYNC_FILTER_A) * sync->deltaEstimation +
72 SYNC_FILTER_A * sync->windowMax) / SYNC_FILTER_B;
74 sync->state = USE_FILTERED;
76 osLog(LOG_DEBUG, "ApHub new sync offset = %" PRId64, sync->deltaEstimation);
79 sync->windowMax = INT64_MIN;
80 sync->windowTimeout = apTime + SYNC_WINDOW_TIMEOUT;
85 int64_t apHubSyncGetDelta(struct ApHubSync* sync, uint64_t hubTime) {
87 switch (sync->state) {
92 ret = sync->windowMax;
95 ret = sync->deltaEstimation;
100 osLog(LOG_WARN, "ApHub sync: Invalid sync state %d", sync->state);
101 apHubSyncReset(sync);