Skip to content

MAVLink: refine reconnect STATUSTEXT (per-peer tracking, snapshot rate limit) - #11731

Open
xznhj8129 wants to merge 7 commits into
iNavFlight:maintenance-10.xfrom
xznhj8129:mav/reconnect-refine
Open

MAVLink: refine reconnect STATUSTEXT (per-peer tracking, snapshot rate limit)#11731
xznhj8129 wants to merge 7 commits into
iNavFlight:maintenance-10.xfrom
xznhj8129:mav/reconnect-refine

Conversation

@xznhj8129

Copy link
Copy Markdown
Contributor

Follow-up to the reconnect STATUSTEXT handling merged in #11715, addressing review feedback on the reconnect-detection design.

The original commit tracked heartbeat presence with a single timestamp per physical port and sent an arming-reason snapshot on every judged reconnect. Review raised two soundness issues with that:

  • a steady peer on a port masks a newly joining peer behind the same port (their heartbeats keep the single timestamp fresh), and a peer failing over to another port is never noticed;
  • MAVLink leaves heartbeat rate channel-dependent, so a peer heartbeating slower than the 5 s gap threshold is classified as reconnecting on every beat, resending the arming notice each time.

Changes

  • Per-peer tracking. Heartbeat presence now lives in the route-table entry (sysid/compid), not per port. A steady peer no longer masks a new one; a peer moving to another port registers as a reconnect there. If the route table is full the new peer degrades gracefully to the pre-existing broadcast-only behaviour.
  • Snapshot rate limit. A 10 s per-port floor on arming snapshots, so a slow-heartbeat peer can't elicit a resend on every beat.
  • Dropped the enable-transition snapshot. It fired into a port nobody had connected to yet (boot) and duplicated the first-heartbeat snapshot on shared-port enable. Reconnect is now driven purely by the heartbeat signal; the enable transition still resets per-port one-shot state via the port reset path.

Testing

  • SITL builds clean with warnings-as-errors; mavlink_unittest 38/38 at this level (no new unit tests — behaviour is timing/multi-peer and covered by the live rig below).
  • Live SITL + pymavlink: existing reconnect regression 6/6, plus new cases — a 6.5 s-period peer is capped to 3 arming sends across 5 beats (was 5), and a second sysid joining a busy port gets its own snapshot while the steady peer produces none.

Built on the mav/04-streams-protocol content already in maintenance-10.x via #11715, so this shows a single commit.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

- MAV_CMD_COMPONENT_ARM_DISARM and MSP2_INAV_ARM_DISARM through the
  normal arming path, succeeding only when the requested state is
  reached
- RTH via a temporary BOXNAVRTH source on the RC mode selector
  (activateRTHMode) instead of the failsafe/geozone forced-RTH latch;
  wired to MAV_CMD_NAV_RETURN_TO_LAUNCH, ArduPilot DO_SET_MODE RTL,
  MSP2_INAV_ACTIVATE_RTH, and Programming Framework operation 61.
  Cleared by a pilot flight-mode change or disarm
- QGC/ArduPilot pause: DO_SET_MODE Loiter/PosHold/Brake enters normal
  PosHold at the current position via a temporary BOXNAVPOSHOLD source
- Normal current-position LAND (transient waypoint, uploaded mission
  untouched) via MAV_CMD_NAV_LAND, MSP2_INAV_ACTIVATE_LANDING, PF op 62
- MAV_CMD_DO_SET_HOME through the native waypoint-0 backend
- MSP2_INAV_TIMESYNC returning the MAVLink TIMESYNC boot clock
- Temporary fixed-wing loiter-radius override: DO_REPOSITION.param3
  (meters) or int32 loiterRadius appended to MSP2_INAV_SET_GLOBAL_TARGET
  (cm); volatile, cleared on disarm/reboot, only active in PosHold
- SET_POSITION_TARGET_GLOBAL_INT / _LOCAL_NED guided handling
- MAV_CMD_CONDITION_YAW; explicit unsupported MAV_CMD_NAV_TAKEOFF stub
- GCSN OSD flight-mode element while GCS navigation is active

Unit slice: 81/81 passing.
A command-triggered landing (MAV_CMD_NAV_LAND / MSP direct land) borrows
NAV_STATE_WAYPOINT_RTH_LAND and the FW autoland FSM with a transient
waypoint, while activeWaypointIndex still points at whatever mission item
was last active. The unconditional reached-marking added for mission LAND
items would emit MISSION_ITEM_REACHED for that stale index and could mark
a loaded mission complete. Capture forcedLandingActivated before the
existing clears and skip the marking for commanded landings at both
finish sites.
MSP transport over MAVLink TUNNEL (private payload type 0x8001,
MAVLink 2 only) so the Configurator can talk MSP over an existing
MAVLink telemetry link. Reuses the MSP parser/encoder through narrow
msp_serial seams; replies are fragmented and returned on the ingress
port only; MSPv1/v2 framing symmetry is preserved end-to-end. Reboot
post-processing is allowed; serial passthrough and ESC 4-way are
rejected before dispatch. Malformed payload lengths are dropped and
stale partial frames time out. Reply/frame buffers are file-scope, not
task stack.

Companion configurator branch adds the MAVLink Tunnel wireless option.
Full mavlink_unittest suite: 86/86 passing.

Final PR of the mavlink_multiport2 stack: tree now matches the feature
branch (remaining deltas are upstream maintenance-10.x drift only).
docs/Mavlink.md documents the full MAVLink stack: multiport + routing,
datastream groups and CLI settings, identity/capabilities, mLRS
integration, supported outgoing/incoming messages and commands, mode
mappings, mission behavior and MSP parity gaps, MSP-over-MAVLink
tunnel, and high-latency mode. Updated from the development branch to
cover flight-mode-change STATUSTEXT notices and reworded for mainline.

docs/Settings.md regenerated from settings.yaml (picks up the per-port
mavlink_port{1-4}_* settings).
End-to-end live harness against a running SITL/FC MAVLink endpoint:
API version, FC variant/version, build info, EEPROM write, reboot over
the tunnel, and reconnect recovery after reboot.
- Document per-peer reconnect STATUSTEXT/arming re-announcement
- Fix STATUSTEXT severity: arming-disable and mode notices are NOTICE only
- Correct MSP-parity LAND/RTH rows: leg speed and RTH land flag are captured on upload, dropped on download
- Restrict stream-rate CLI settings to port 1 (ports 2-4 have none)
- Complete upload-translator list (RTH/SET_POI/SET_HEAD) and DO_REPOSITION param4 heading
- Note downloads always reply MISSION_ITEM_INT
- Fix dead MSP-Navigation-Messages.md link -> Navigation.md wp section
Review feedback on the reconnect STATUSTEXT commit:

- Track heartbeat presence per peer in the route table instead of one
  timestamp per port, so a steady peer cannot mask a newly joining one
  behind the same port, and a peer failing over to another port
  registers as a reconnect there. If the route table is full the new
  peer degrades to broadcast-only behavior.
- Rate-limit arming snapshots per port so a peer heartbeating slower
  than the gap threshold cannot elicit a resend on every beat.
- Drop the enable-transition snapshot: it fired into a port nobody had
  connected to yet (boot) and duplicated the first-heartbeat snapshot on
  shared-port enable. Reconnect is now driven purely by the heartbeat
  signal; the enable transition still resets per-port one-shot state via
  the port reset path.
@xznhj8129
xznhj8129 force-pushed the mav/reconnect-refine branch from 76e8e3e to 9a4d419 Compare July 26, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant