void clksyncProcessSamples(SyncStatus sync) { unsigned long current_offset; long average_offset; current_offset = sclockGetOffsetTicks(); average_offset = sync->accumulator/sync->responses; sclockSetOffsetTicks(current_offset - average_offset); sync->accumulator = 0; sync->requests = 0; sync->responses = 0; sync->iterations++; if((average_offset < sync->tolerance) && (average_offset > -(sync->tolerance))) { sync->state = STATE_SYNCED; } if(sync->iterations > MAX_ITERATIONS) { sync->state = STATE_ITERS_EXCEEDED; } }
void sclockSetOffsetMillis(unsigned long offset) { sclockSetOffsetTicks(offset*MILLIS_FACTOR); }