bulk_sensor: Don't assume chip_clock is zero on start of queries

Send an explicit clock query in ChipClockUpdater to seed the initial
clock.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-12-27 12:58:53 -05:00
parent 266e96621c
commit 2dc4cfc5df
4 changed files with 13 additions and 9 deletions

View File

@ -310,7 +310,7 @@ class ADXL345:
reqclock=reqclock) reqclock=reqclock)
logging.info("ADXL345 starting '%s' measurements", self.name) logging.info("ADXL345 starting '%s' measurements", self.name)
# Initialize clock tracking # Initialize clock tracking
self.clock_updater.note_start(reqclock) self.clock_updater.note_start()
self.last_error_count = 0 self.last_error_count = 0
def _finish_measurements(self): def _finish_measurements(self):
# Halt bulk reading # Halt bulk reading

View File

@ -222,15 +222,15 @@ class ChipClockUpdater:
return self.last_overflows return self.last_overflows
def clear_duration_filter(self): def clear_duration_filter(self):
self.max_query_duration = 1 << 31 self.max_query_duration = 1 << 31
def note_start(self, reqclock): def note_start(self):
self.last_sequence = 0 self.last_sequence = 0
self.last_overflows = 0 self.last_overflows = 0
self.clock_sync.reset(reqclock, 0) # Set initial clock
self.clear_duration_filter() self.clear_duration_filter()
self.update_clock(minclock=reqclock) self.update_clock(is_reset=True)
self.clear_duration_filter() self.clear_duration_filter()
def update_clock(self, minclock=0): def update_clock(self, is_reset=False):
params = self.query_status_cmd.send([self.oid], minclock=minclock) params = self.query_status_cmd.send([self.oid])
mcu_clock = self.mcu.clock32_to_clock64(params['clock']) mcu_clock = self.mcu.clock32_to_clock64(params['clock'])
seq_diff = (params['next_sequence'] - self.last_sequence) & 0xffff seq_diff = (params['next_sequence'] - self.last_sequence) & 0xffff
self.last_sequence += seq_diff self.last_sequence += seq_diff
@ -250,4 +250,8 @@ class ChipClockUpdater:
# inaccuracy of query responses and plus .5 for assumed offset # inaccuracy of query responses and plus .5 for assumed offset
# of hardware processing time. # of hardware processing time.
chip_clock = msg_count + 1 chip_clock = msg_count + 1
self.clock_sync.update(mcu_clock + duration // 2, chip_clock) avg_mcu_clock = mcu_clock + duration // 2
if is_reset:
self.clock_sync.reset(avg_mcu_clock, chip_clock)
else:
self.clock_sync.update(avg_mcu_clock, chip_clock)

View File

@ -162,7 +162,7 @@ class LIS2DW:
reqclock=reqclock) reqclock=reqclock)
logging.info("LIS2DW starting '%s' measurements", self.name) logging.info("LIS2DW starting '%s' measurements", self.name)
# Initialize clock tracking # Initialize clock tracking
self.clock_updater.note_start(reqclock) self.clock_updater.note_start()
self.last_error_count = 0 self.last_error_count = 0
def _finish_measurements(self): def _finish_measurements(self):
# Halt bulk reading # Halt bulk reading

View File

@ -175,7 +175,7 @@ class MPU9250:
reqclock=reqclock) reqclock=reqclock)
logging.info("MPU9250 starting '%s' measurements", self.name) logging.info("MPU9250 starting '%s' measurements", self.name)
# Initialize clock tracking # Initialize clock tracking
self.clock_updater.note_start(reqclock) self.clock_updater.note_start()
self.last_error_count = 0 self.last_error_count = 0
def _finish_measurements(self): def _finish_measurements(self):
# Halt bulk reading # Halt bulk reading