Repository navigation
feat(connection): rank FC autodetection by USB identity - #2198
Conversation
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>
There was a problem hiding this comment.
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.
| 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]: |
|
Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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 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 Not tested here: Windows, macOS, real hardware, live network or SITL connection, the GUI, and the full test suite. |


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
git commit --signoff)Testing
Describe how you tested these changes: