Skip to content

Commit

Permalink
clocksync: Simplify 32bit clock upconversion code
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Dec 10, 2023
1 parent 62bf52b commit c5bd813
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions klippy/clocksync.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ def _handle_clock(self, params):
self.queries_pending = 0
# Extend clock to 64bit
last_clock = self.last_clock
clock = (last_clock & ~0xffffffff) | params['clock']
if clock < last_clock:
clock += 0x100000000
self.last_clock = clock
clock_delta = (params['clock'] - last_clock) & 0xffffffff
self.last_clock = clock = last_clock + clock_delta
# Check if this is the best round-trip-time seen so far
sent_time = params['#sent_time']
if not sent_time:
Expand Down Expand Up @@ -138,10 +136,9 @@ def estimated_print_time(self, eventtime):
# misc commands
def clock32_to_clock64(self, clock32):
last_clock = self.last_clock
clock_diff = (last_clock - clock32) & 0xffffffff
if clock_diff & 0x80000000:
return last_clock + 0x100000000 - clock_diff
return last_clock - clock_diff
clock_diff = (clock32 - last_clock) & 0xffffffff
clock_diff -= (clock_diff & 0x80000000) << 1
return last_clock + clock_diff
def is_active(self):
return self.queries_pending <= 4
def dump_debug(self):
Expand Down

0 comments on commit c5bd813

Please sign in to comment.