Skip to content

Commit

Permalink
underflow watchdog fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
falkecarlsen committed Aug 16, 2024
1 parent 7fab7a0 commit 68a887d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions py_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
TUBE_MAX_LEVEL = 900
DEBUG = True
COMMUNICATION_TIMEOUT = 10
UNDERFLOW_CHECK_INTERVAL = 1

ID = 0
UNDERFLOW_CHECK_INTERVAL = 5


class SensorError(Exception):
Expand Down Expand Up @@ -239,22 +237,24 @@ def update_state(self, tube=None, quick=False, initial=False):
def _underflow_check(self):
TAG = "UNDERFLOW_CHECK"
while True:
# sanity check
if not self.ready():
# do liveness check and update state if device is outdated but was ready on last communication
if self.outdated():
print(f"Device is outdated. {self.state.last_update=}, {datetime.now()=}")
# if last line is OK, then device is still alive, do update of state
if self.read_buffer and self.read_buffer[-1] == CLAIRE_READY_SIGNAL:
print(f"Device is alive. {self.state.last_update=}, {datetime.now()=}")
self.busy = False
self.update_state(quick=True)
else:
if DEBUG:
print(f'{TAG}: Device is not ready. Waiting {UNDERFLOW_CHECK_INTERVAL} seconds.')
sleep(UNDERFLOW_CHECK_INTERVAL)
sleep(UNDERFLOW_CHECK_INTERVAL)
continue

# check if water level is below 0 fixme: errors out in callee during long-running functions due to timeout reached
self.update_state(quick=True)
# update state if device is dynamic
if self.state.dynamic:
self.update_state(quick=True)

# check underflows
if self.state.Tube1_sonar_dist_mm < TUBE_MAX_LEVEL:
Expand Down

0 comments on commit 68a887d

Please sign in to comment.