Skip to content

Commit

Permalink
app/node_monitor: fix handling of info request time
Browse files Browse the repository at this point in the history
Avoids exception spam and cases where discovery gets stuck due to
`_info_requested_at` not existing if an info is seen before a status.
  • Loading branch information
tpwrules authored and tridge committed Nov 12, 2024
1 parent 44c6cdf commit 5c2edbb
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions dronecan/app/node_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self):
self.info = None
self.monotonic_timestamp = None
self._remaining_retries = NodeMonitor.MAX_RETRIES
self._info_requested_at = 0

@property
def discovered(self):
Expand Down Expand Up @@ -166,7 +167,6 @@ def _on_node_status(self, e):
new_entry = False
except KeyError:
entry = self.Entry()
entry._info_requested_at = 0
self._registry[node_id] = entry
new_entry = True

Expand All @@ -175,23 +175,21 @@ def _on_node_status(self, e):
if new_entry:
self._call_event_handlers(self.UpdateEvent(entry, self.UpdateEvent.EVENT_ID_NEW))

should_retry_now = entry.monotonic_timestamp - entry._info_requested_at > self.MIN_RETRY_INTERVAL

if not entry.discovered and should_retry_now and not e.node.is_anonymous:
entry._info_requested_at = entry.monotonic_timestamp
# noinspection PyProtectedMember
entry._register_retry()
e.node.request(uavcan.protocol.GetNodeInfo.Request(), node_id, # @UndefinedVariable
priority=self.TRANSFER_PRIORITY, callback=self._on_info_response)
if not entry.discovered and not e.node.is_anonymous:
should_retry_now = entry.monotonic_timestamp - entry._info_requested_at > self.MIN_RETRY_INTERVAL
if should_retry_now:
entry._info_requested_at = entry.monotonic_timestamp
# noinspection PyProtectedMember
entry._register_retry()
e.node.request(uavcan.protocol.GetNodeInfo.Request(), node_id, # @UndefinedVariable
priority=self.TRANSFER_PRIORITY, callback=self._on_info_response)

def _on_info_response(self, e):
if not e:
return

try:
entry = self.get(e.transfer.source_node_id)
if entry._info_requested_at is None:
entry._info_requested_at = entry.monotonic_timestamp
except KeyError:
entry = self.Entry()
self._registry[e.transfer.source_node_id] = entry
Expand Down

0 comments on commit 5c2edbb

Please sign in to comment.