Skip to content

feat(connection): rank FC autodetection by USB identity - #2198

Merged
amilcarlucas merged 1 commit into
masterfrom
speedup_autodetection
Oct 11, 2026
Merged

amilcarlucas merged 1 commit into
masterfrom
speedup_autodetection

Conversation

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Description

Enumerate serial-port metadata before opening devices and prioritize known flight-controller VID/PID pairs. Rank MAVLink-labeled interfaces and known telemetry adapters as useful hints.

Keep unknown ports and sibling USB interfaces as fallbacks, so devices with separate DroneCAN and MAVLink ports remain discoverable. Add tests for candidate ranking, fallback behavior, and metadata-only enumeration.

Checklist

  • Run pre-commit checks locally
  • Verified by a human programmer
  • All commits are signed off (use git commit --signoff)
  • Code follows our coding standards
  • Documentation updated if needed
  • No breaking changes or properly documented

Testing

Describe how you tested these changes:

  • Unit tests pass
  • Integration tests pass
  • Manual testing performed
  • Tested on flight controller hardware

Enumerate serial-port metadata before opening devices and prioritize
known flight-controller VID/PID pairs. Rank MAVLink-labeled interfaces
and known telemetry adapters as useful hints.

Keep unknown ports and sibling USB interfaces as fallbacks, so devices
with separate DroneCAN and MAVLink ports remain discoverable. Add tests
for candidate ranking, fallback behavior, and metadata-only enumeration.

Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 17:38
@amilcarlucas amilcarlucas added the AIReview Request an automated AI review; picked up by the reviewprs sweep label Oct 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open findings
What changed in this PR

This PR improves flight-controller connection autodetection by ranking serial candidates using USB VID/PID identity and enriched serial-port metadata (plus MAVLink-labeled hints), while preserving sibling interfaces and unknown ports as fallbacks.

Changes:

  • Add USB/metadata-based candidate ranking for serial autodetection and retain fallback candidates.
  • Extend autodetection to merge PyMAVLink-discovered ports with PySerial metadata without opening ports.
  • Add unit tests covering ranking, sibling-interface fallback, and metadata-only enumeration behavior.
File Description
ardupilot_methodic_configurator/​backend_flightcontroller_connection.py Introduces USB/metadata ranking and revised candidate enumeration/sorting for autodetect.
tests/​test_backend_flightcontroller_connection.py Adds fixtures and tests validating ranking order and fallback behavior without probing ports.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +892 to +898
def candidate_rank(port: mavutil.SerialPort) -> tuple[int, bool, ListPortInfo]:
resolved_device = os_path.realpath(port.device)
rank = max(
usb_metadata_ranks.get(resolved_device, 0),
4 if resolved_device in explicit_mavlink_devices else int(resolved_device in pymavlink_detected_devices),
)
return rank, resolved_device in mavlink_interfaces, ListPortInfo(port.device)
from ardupilot_methodic_configurator.data_model_flightcontroller_info import FlightControllerInfo

if TYPE_CHECKING:
from collections.abc import Iterator


@pytest.fixture(name="usb_autodetect_connection")
def fixture_usb_autodetect_connection() -> Iterator[FlightControllerConnection]:
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head ba0a600dde.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2198/1.html#prMethodicConfigurator-2198

Reviewed at ba0a600. The ranking behaves as described: the changed test module passes at this head (131 passed), and comparing base against head with a silent injected connection shows known FC IDs tried first with the other ports following as fallbacks.

One small thing to consider. The MAVLink-labelled seed entries taken from the connection list are now kept, but they are not deduplicated by resolved path (ardupilot_methodic_configurator/backend_flightcontroller_connection.py:867); only ports appended afterwards are checked against detected_devices. If the history holds a symlink alias whose name contains 'mavlink' and it points at a tty that is itself described as MAVLink, the same device is probed twice (one attempt before this PR, two after), which adds 2 s when it does not answer. Deduplicating the seed list by realpath before the merge would cover it. An ordinary by-id alias does not trigger this, so it is a corner case and not a blocker.

For awareness only: because every enumerated port is now a fallback (ardupilot_methodic_configurator/backend_flightcontroller_connection.py:882), ports that pyserial leaves described as 'n/a' are probed too, where the old POSIX last-resort list skipped them. Each silent one costs 2 s before the network ports are tried. From pyserial's macOS code this would include the Bluetooth callout ports when no FC is attached, but that was not run on macOS. The commit message says unknown ports are kept on purpose, so no change is requested.

The Copilot comments look like false alarms: pyserial 3.5's ListPortInfo defines __lt__ with natural ordering, so the sort key at ardupilot_methodic_configurator/backend_flightcontroller_connection.py:898 is safe for serial, tcp: and udp: names, and the test module already has from __future__ import annotations, so the Iterator import under TYPE_CHECKING is fine.

Not tested here: Windows, macOS, real hardware, live network or SITL connection, the GUI, and the full test suite.

@amilcarlucas
amilcarlucas merged commit 1a65ca4 into master Oct 11, 2026
23 of 26 checks passed
@amilcarlucas
amilcarlucas deleted the speedup_autodetection branch October 11, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIReview Request an automated AI review; picked up by the reviewprs sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants