mavlink: unified TX architecture - move all service sends to TX thread#26512
Draft
mavlink: unified TX architecture - move all service sends to TX thread#26512
Conversation
🔎 FLASH Analysispx4_fmu-v5x [Total VM Diff: 1488 byte (0.07 %)]px4_fmu-v6x [Total VM Diff: 1520 byte (0.08 %)]Updated: 2026-02-17T23:15:35 |
Contributor
|
Docs should be added somewhere in https://docs.px4.io/main/en/mavlink/ explaining the pattern. So obviously in https://docs.px4.io/main/en/mavlink/streaming_messages#define-the-streaming-class but also "How to TX a mavlink message" section. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MAV_RATEbudget — streams automatically back off when service traffic is activeProblem
The RX thread (
MavlinkReceiver) both received messages AND sent service responses, bypassingMAV_RATEbandwidth management entirely. This caused uncontrolled link bursting that breaks low-bandwidth links with hard throughput limits (e.g. telemetry radios).Changes
New:
MavlinkTxQueue— thread-safe queue wrappingVariableLengthRingbuffer. Services encode messages viamavlink_msg_*_encode_chan()+enqueue_tx()instead of callingmavlink_msg_*_send_struct()directly. The TX thread drains the queue under a per-cycle byte budget.Converted services:
MavlinkParametersManager—send_param(),send_error(), hash PARAM_VALUE, UAVCAN forwardingMavlinkFTP—_reply(), resend path, burst readsMavlinkMissionManager— all 6 send helpers (ack, current, count, item, request, item_reached)MavlinkLogHandler—send_log_entry(),state_sending_data()MavlinkReceiver— PING response, MESSAGE_INTERVALMavlinkTimesync— TIMESYNC responseThread safety: Per-service
pthread_mutex_tprotects shared state betweenhandle_message()(RX thread) andsend()(TX thread).Bandwidth accounting:
update_rate_mult()now subtracts measured service traffic (EMA of bytes/sec) from available stream bandwidth, replacing the oldsending_parameters()hack.Test plan
MAV_1_RATElow (e.g. 1200 B/s), trigger param download — streams should back off, heartbeat continues, no TX overrunsmavlink statusshows reasonable rate_mult values during service activity