Skip to content

fix: connection refused on telemetry, fallback check to 57600 baudrate - #2070

Open
OmkarSarkar204 wants to merge 1 commit into
ArduPilot:masterfrom
OmkarSarkar204:telemetry-connection
Open

OmkarSarkar204 wants to merge 1 commit into
ArduPilot:masterfrom
OmkarSarkar204:telemetry-connection

Conversation

@OmkarSarkar204

Copy link
Copy Markdown
Contributor

Description

Add serial baudrate fallback during FC auto detection

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

Copilot AI lite review requested due to automatic review settings September 16, 2026 06:54

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.

🟡 Changes recommended

Fallback conditions, reconnect persistence, and regression test coverage need to be addressed.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds a 57600-baud fallback for serial flight-controller auto-detection.

Changes:

  • Defines a fallback baudrate.
  • Retries failed serial detection at 57600 baud.
File summaries
File Summary
ardupilot_methodic_configurator/backend_flightcontroller_connection.py Implements serial baudrate fallback logic.
Review details

Suppressed comments (2)

ardupilot_methodic_configurator/backend_flightcontroller_connection.py:379

  • When auto-detection is called with an explicitly selected baudrate such as 921600, a failed first attempt still enters this branch because the condition only excludes 57600. That silently overrides the caller's choice and can connect at an unintended speed; the comment above describes this fallback as applying after a failed DEFAULT_BAUDRATE attempt. Restrict this condition to connection_baudrate == DEFAULT_BAUDRATE (or otherwise only enable it when the default was selected).
            if (
                not autodetect_serial[-1].device.startswith(("tcp:", "udp:"))
                and int(DEFAULT_FALLBACK_BAUDRATE) != connection_baudrate

ardupilot_methodic_configurator/backend_flightcontroller_connection.py:396

  • After this retry succeeds, _baudrate still contains the original connection_baudrate. FlightController.reset_and_reconnect() later calls create_connection_with_retry(..., baudrate=self.baudrate) directly, bypassing this fallback, so a board discovered only at 57600 will be retried at 115200 after a reboot and fail. Persist the effective fallback baudrate or route that reconnect path through the same fallback logic.
                if err == "":
                    return ""
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

@OmkarSarkar204
OmkarSarkar204 force-pushed the telemetry-connection branch 3 times, most recently from 14c6bfe to 2ad8146 Compare September 16, 2026 07:31
@amilcarlucas amilcarlucas added the AIReview Request an automated AI review; picked up by the reviewprs sweep label Sep 16, 2026
@AP-Review

AP-Review commented Sep 16, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-09-16)

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

Reviewed at head 2ad8146360.

Full report, including everything that was checked and found clean: https://uav.tridgell.net/DevCallReviews/2026_09_17_AIReview/devcall_pr_reviews.html#prMethodicConfigurator-2070

Verdict: REQUEST CHANGES

The premise is right and useful — SiK radios default to 57600 while the tool defaults to 115200, so auto-detect silently fails — and the structural concerns all check out clean: the fallback is correctly gated on the no-heartbeat error alone (not a blanket except), it cannot loop, it leaks nothing, and the accurate diagnostic survives for every other failure. All three real error paths were provoked against pyserial/pymavlink to confirm that. The one blocker is that the gate compares against an untranslated English string, so the fix is a no-op for every non-English user. Also worth saying plainly: the failing CI check is not this PR's fault.


BUG — ardupilot_methodic_configurator/backend_flightcontroller_connection.py:377

The fallback compares against the untranslated English literal, so it never fires in any other UI language. The message is produced by _("No MAVLink heartbeat received, connection failed.") at :503, but :377 compares err == the bare English string. Verified: with sys.argv = ["amc","--language","de"] the message comes back as 'Kein MAVLink-Herzschlag empfangen, Verbindung fehlgeschlagen.', connect() makes 1 attempt at 115200 only and returns 'Keine automatisch erkannten Ports haben reagiert.'; in English the same scenario makes 2 attempts [115200, 57600]. All five shipped locales (de/it/ja/pt/zh_CN) have a non-empty msgstr for this id. Suggested fix: hoist it into a module constant NO_HEARTBEAT_ERROR = _("...") and compare against that, or return a sentinel/enum from _select_supported_autopilot instead of comparing UI text.

ISSUE — ardupilot_methodic_configurator/backend_flightcontroller_connection.py:379

An explicitly requested baudrate is silently overridden. The guard only excludes 57600, so FlightControllerConnection(baudrate=921600).connect(device="") tries [921600, 57600]. Reachable from --baudrate 921600 with no --device (__main__.py:225) and from the GUI auto-connect button, which passes the combobox value (frontend_tkinter_connection_selection.py:270). Recommend connection_baudrate == DEFAULT_BAUDRATE instead.

ISSUE — ardupilot_methodic_configurator/backend_flightcontroller_connection.py:387

The effective baudrate is not persisted, so a board found at 57600 will fail to come back after a reboot. After a successful fallback, conn.baudrate is still 115200, and FlightController.reset_and_reconnect() reconnects with baudrate=self.baudrate (backend_flightcontroller.py:322). This tool reboots the FC routinely after parameter writes, so this is on the normal path. Set self._baudrate = DEFAULT_FALLBACK_BAUDRATE on success.

ISSUE — tests/test_backend_flightcontroller_connection.py:430

The new test's key assertion is tautological, and neither guard is covered. It compares the observed baudrate against int(DEFAULT_FALLBACK_BAUDRATE) — the constant under test. Verified by mutation: changing DEFAULT_FALLBACK_BAUDRATE from 57600 to 38400 leaves the test green. Assert the literal 57600; that number is the whole point of the PR. Separately, collapsing the condition at :378-379 to just the error comparison (dropping both the tcp:/udp: and the already-57600 checks) leaves all 110 tests passing — so add cases for "already at 57600 → no second attempt" and "non-heartbeat error → no second attempt".

Lower-priority notes (1)

ardupilot_methodic_configurator/backend_flightcontroller_connection.py:338 — The explicit-device path returns before the fallback, so the GUI dropdown case is not covered. A user who picks their telemetry port from the dropdown still gets no 57600 retry; only auto-detect benefits. Given the title mentions telemetry, worth confirming this covers the reported scenario. Also :378: the startswith(("tcp:", "udp:")) guard appears unreachable — _auto_detect_serial() returns entries from mavutil.auto_detect_serial() or from _connection_tuples filtered on "mavlink" in description, and network ports are registered as (port, port) so their description never contains "mavlink". Harmless, but dead weight.

What was checked and found clean

The structural concerns all check out, and the failing CI check is not this PR's. Exception selection is right. Provoked with pyserial/pymavlink 3.5/2.4.49: a missing port raises serial.serialutil.SerialException ([Errno 2]), permission-denied raises SerialException ([Errno 13], not PermissionError), and a refused TCP raises ConnectionRefusedError. All three are caught at :932 and returned as str(e), which never equals the heartbeat literal — so none trigger the fallback and the user keeps the accurate diagnostic. No leak: create_connection_with_retry:923 calls self.disconnect() before returning the no-heartbeat error, and disconnect():234 closes self.master and nulls it. Terminates: straight-line, one extra attempt, retries=1, CONNECTION_RETRY_TIMEOUT = 2 s. The fallback test does exercise the fallback — mutation-proven: replacing the error literal with a never-matching string, and deleting the whole block, each make it fail. No reliance on pyserial's .interface anywhere. CI: Publish Tests Results is not a fork-permission problem and not a test failure — the publish step succeeded; the failing step is coverage report --fail-under=89 reporting 88%, and the PR's own base commit 966a071b on master fails identically (88%, job 104181085511). All 17 other checks pass.

@OmkarSarkar204
OmkarSarkar204 force-pushed the telemetry-connection branch 3 times, most recently from 34c41d9 to a2b7fd5 Compare September 27, 2026 21:41
@AP-Review

Copy link
Copy Markdown

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

Re-reviewed at head dc229ccebe (you were last told 2ad8146360); my earlier comment above is superseded. Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/followups/2026_09_28_1802/devcall_pr_reviews.html#prMethodicConfigurator-2070

The blocker and both functional issues from my previous comment are fixed. Only the test-coverage point is still open, plus the low-priority note. Thanks, this is a clean update.

# Previous finding Status
1 BUG: fallback compared against an untranslated English string Resolved. backend_flightcontroller_connection.py:384 now compares against _(). I ran it under --language en/de/it/ja/pt/zh_CN and all six now retry at [115200, 57600]. A board answering only at 57600 under --language de connects.
2 Explicit baudrate silently overridden Resolved. The == DEFAULT_BAUDRATE guard at :386 works: baudrate=921600 makes one attempt only.
3 Effective baudrate not persisted Resolved. :403 saves it. Checked through FlightController: after a fallback connect, reset_and_reconnect() reconnects at 57600.
4 Test assertion is tautological, and the guards aren't covered Still open, see below
5 (low priority) No fallback on the explicit-device path; the tcp/udp guard is unreachable Unchanged. The PR description now scopes this to auto-detection, which is fine. I also have to correct myself on the tcp/udp guard: it is reachable, because _auto_detect_serial() can return a tcp:/udp: address through its "mavlink" description filter (:844), and the guard at :385 correctly keeps the fallback off for it. Keep it.

The structural points from last time still hold at this head:

  • The fallback fires only on the no-heartbeat error. Permission-denied, device-busy and connection-refused each make one attempt and keep their own error text.
  • master is None after every failed attempt.
  • There is exactly one extra attempt.

Still open: tests/test_backend_flightcontroller_connection.py:430

The new test doesn't pin any of this round's three fixes. Each of these changes still leaves all 155 tests in test_backend_flightcontroller_connection.py and test_backend_flightcontroller.py passing:

  • going back to the bare English literal
  • going back to the != 57600 guard
  • deleting the self._baudrate = ... line
  • setting DEFAULT_FALLBACK_BAUDRATE = 38400
  • dropping the no-heartbeat check so that any error triggers the retry

Deleting the whole fallback block does fail the test, so it does exercise the path. Suggestions:

  • Assert the literal 57600 rather than int(DEFAULT_FALLBACK_BAUDRATE).
  • Add a case where baudrate=921600 gives one call only.
  • Add a case where a non-heartbeat error gives one call only.
  • After a successful fallback, assert connection.baudrate == 57600.
  • For the translation fix, patch the module's _ to a non-identity function in a test, so a bare literal would stop matching.

Minor:

  • DEFAULT_FALLBACK_BAUDRATE is already an int, so the int(...) wrappers at :397, :403 and in the test are redundant.
  • The test docstring's THEN clause (tests/test_backend_flightcontroller_connection.py:405) describes only the first attempt, not the fallback.

CI: pytest (ubuntu-latest, 3.10) has 7 errors, all 30 s pytest-timeouts while parsing parameter-metadata XML in acceptance_template_import_from_params.py fixtures. Publish Tests Results fails only as a consequence. This is unrelated to this PR, and the other Python versions pass.

This branch has not been deployed

No deployments
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