Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app/node_monitor: fix handling of info request time #72

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading