clocksync: Simplify 32bit clock upconversion code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
62bf52bfcf
commit
c5bd813d8b
|
@ -66,10 +66,8 @@ class ClockSync:
|
||||||
self.queries_pending = 0
|
self.queries_pending = 0
|
||||||
# Extend clock to 64bit
|
# Extend clock to 64bit
|
||||||
last_clock = self.last_clock
|
last_clock = self.last_clock
|
||||||
clock = (last_clock & ~0xffffffff) | params['clock']
|
clock_delta = (params['clock'] - last_clock) & 0xffffffff
|
||||||
if clock < last_clock:
|
self.last_clock = clock = last_clock + clock_delta
|
||||||
clock += 0x100000000
|
|
||||||
self.last_clock = clock
|
|
||||||
# Check if this is the best round-trip-time seen so far
|
# Check if this is the best round-trip-time seen so far
|
||||||
sent_time = params['#sent_time']
|
sent_time = params['#sent_time']
|
||||||
if not sent_time:
|
if not sent_time:
|
||||||
|
@ -138,10 +136,9 @@ class ClockSync:
|
||||||
# misc commands
|
# misc commands
|
||||||
def clock32_to_clock64(self, clock32):
|
def clock32_to_clock64(self, clock32):
|
||||||
last_clock = self.last_clock
|
last_clock = self.last_clock
|
||||||
clock_diff = (last_clock - clock32) & 0xffffffff
|
clock_diff = (clock32 - last_clock) & 0xffffffff
|
||||||
if clock_diff & 0x80000000:
|
clock_diff -= (clock_diff & 0x80000000) << 1
|
||||||
return last_clock + 0x100000000 - clock_diff
|
return last_clock + clock_diff
|
||||||
return last_clock - clock_diff
|
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return self.queries_pending <= 4
|
return self.queries_pending <= 4
|
||||||
def dump_debug(self):
|
def dump_debug(self):
|
||||||
|
|
Loading…
Reference in New Issue