mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 14:19:57 +08:00
* fix(mavlink): rate-limit the parameter dump to its share of the link A full PARAM_REQUEST_LIST dump was only throttled in MAVLINK_MODE_LOW_BANDWIDTH. In every other mode the sole backpressure was get_free_tx_buf() in send_param(), which on NuttX is just FIONSPACE on the UART and knows nothing about what the link behind it can carry. MAV_x_RATE scales _rate_mult, which applies to the streams only, so the dump ignored it entirely. Since _main_loop_delay is floored at 100 Hz, the dump ran at ~100 Hz (~3.9 kB/s) no matter how low MAV_x_RATE was set. On a 57600 SiK radio (AIR_SPEED=64) that hands the radio roughly three times what it can carry. The radio drops whole MAVLink packets, which shows up as 4-6% loss across everything sharing the link - the parameters themselves still arrive, it is the rest of the telemetry that suffers. Measured on an FMU-v6C: 4.4-6.2% loss during a dump, going to 0.00% with this change. Derive a minimum send interval from the configured data rate instead, so the dump takes a bounded share of the budget and scales with the link. The 8 Hz low bandwidth cap is kept as a floor so that mode does not speed up. Fast links are unaffected: on USB the computed interval falls below the main loop period, so it never fires. Also stop advancing _send_all_index when send_param() fails for want of TX buffer space. The return value was discarded after the index had already moved on, so that parameter was skipped silently and never resent, leaving the ground station to notice the gap and re-request it. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): let streams yield budget during a parameter dump With the dump now taking a defined share of the link budget, the streams were still sized against the whole of it, so the two together could over-subscribe the link and push it back into dropping packets. Reserve the dump's share in update_rate_mult() while a full dump is in progress, the same way const_rate streams and ulog streaming are already accounted for. Links with spare bandwidth are unaffected by construction: bandwidth_mult is capped at 1.0 regardless, so subtracting the reserve only bites once the streams are actually close to the limit. Verified on USB, where tx rate mult stays at 1.000 throughout a dump. This keys off a full PARAM_REQUEST_LIST transfer rather than the existing sending_parameters(), which stays true for 2 s after any single parameter goes out and would reserve bandwidth far more often than intended. Measured on an FMU-v6C over a 57600 SiK: during a dump the streams scale back from 0.473 to 0.232 and total output drops from 1428 to 1052 B/s, inside the 1200 B/s budget, with no loss. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): pin the TELEM1 data rate to a radio-safe default MAV_0_RATE defaulted to a hardcoded 1200 B/s while every other instance defaulted to 0, meaning baudrate/20. The value predates the yaml config migration in 2018 and no rationale is recorded for it. Deriving it from the baudrate is tempting but wrong for a telemetry radio, where the serial rate says little about what goes over the air. A SiK radio at 57600 baud with the common 64 kbps air rate carries around 2000 B/s with error correction enabled, and roughly twice that without, where baudrate/20 would suggest 2880. Error correction is not visible to us from here, so 2880 over-drives the link on any radio that has it on, and the radio drops packets rather than telling us. Measured on an FMU-v6C over a 57600 SiK: at 2880 with error correction enabled a parameter download loses 1.3-1.8% and an FTP burst download fails outright, while at 2000 both complete cleanly. With error correction off there is more headroom and 2880 is fine, so 2000 is the value that works either way. Pin instance 0 to 2000 rather than deriving it, and say why in the parameter description so that anyone on a better link knows they can raise it. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): keep the FTP session alive while a burst is streaming _last_work_buffer_access is only updated by _ensure_buffers_exist(), which runs when a client request arrives. A burst download streams without any client requests, so nothing refreshes it for the duration of the burst and send() closes the session out from under the transfer once the inactivity timeout expires. A burst is bounded by a 35 KiB chunk, which over USB is done long before the timeout, so this never shows there. Over a telemetry radio a single chunk easily takes longer than 30 s, and the session is then torn down mid-transfer: reproducible against an FMU-v6C over a 57600 SiK as a failure at just over 31 s, every time. Treat streaming a burst as the activity it is. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): fit FTP burst downloads to a telemetry radio A burst download was bounded only by get_free_tx_buf(), the local UART buffer, which knows nothing about what the radio behind it can carry. Over a 57600 SiK that hands the radio several times its capacity: the radio's reported txbuf collapses to zero, PX4 sheds 600-1500 B/s of its own, the regular streams are squeezed to 40%, and the transfer dies around 10% of the way through a 128 KiB file. It cannot be reproduced over USB, where there is no such bottleneck. Three things are needed, and none of them is sufficient alone. Keep the packet inside one radio packet. A SiK splits anything larger than its max_data_packet_length across several radio packets and reassembles them correctly, but the split costs air time and drops the rate the link can carry by roughly a third, which is enough to push the burst over the edge. That limit is 250 bytes without error correction and 118 with it, and we cannot tell which from here, so size for the smaller. The payload is derived rather than hardcoded because the framing overhead depends on whether signing is active. Pace the burst against its share of the configured rate, scaled by the radio's own txbuf feedback so it finds whatever the link actually carries: that differs by more than two to one depending on error correction. Note this deliberately does not use get_rate_mult(), which folds in the budget split that this share has already been subtracted from - applying it here too counts the reduction twice and starves the burst into the client's inter-packet timeout. Reserve that share in update_rate_mult() so the streams yield it instead of the two together over-subscribing the link. All of it is conditional on a radio reporting RADIO_STATUS, so a direct serial or USB connection is unaffected. Measured on an FMU-v6C over a 57600 SiK, downloading a 128528 byte file with MAVSDK. Without error correction, at the default rate: three runs of three complete byte-identical in 2:05, with no timeouts, no gap-fill reads and 1414 burst packets for 1414 packets' worth of file, where the same download fails outright before this change. With error correction enabled, which halves both the capacity and the packet size, it completes in 3:10. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * docs(telemetry): note what a SiK link actually carries The page says the vehicle-side radio typically needs no configuration, which is true for getting a link up but leaves out that the serial baudrate says little about what goes over the air, and that setting MAV_0_RATE above what the link carries makes the radio drop packets rather than making telemetry faster. Add a short section with the rough figures, what to do about it, and the two AT commands that report the radio's own limits. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): honour the size requested for an FTP burst _workBurst recorded the offset, sequence number and target ids from a BurstReadFile request but not its size, and the streaming loop always read a full payload. A client could not ask for smaller packets, which the spec provides for and which ArduPilot already honours, so the two servers behaved differently for the same request. The single-shot ReadFile path was never affected. Record the requested size, treating zero as "as much as fits" to match ArduPilot, and use it for the burst. The clamp against what a radio carries in one piece stays, and has to be applied after the request rather than instead of it. Every ground station in the field asks for a full payload today, so honouring the request on its own would hand a radio packets it has to split, which is the behaviour this series set out to fix. Asking for less than the radio can carry is respected; asking for more is not. Reported by @DonLakeFlyer. Measured against an FMU-v6C over a 57600 SiK with error correction on, where the radio carries 118 bytes in one piece: a request for 239 is answered with 91 bytes per packet, 200 likewise, and a request for 64 is answered with 64. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): keep single-shot FTP reads within one radio packet too _workRead already honoured the size a client asked for, so it was left alone when the burst path was taught to stay inside one radio packet. That leaves a hole: when a burst loses something, the client fills the gap with ReadFile requests, and those go out at the size it asked for. Against a radio carrying 118 bytes in one piece, a 110 byte request is 137 bytes on the wire and is split - which is exactly what the burst clamp exists to avoid, reappearing on the recovery path. Observed against QGroundControl master over a 57600 SiK with error correction on: burst packets came back at 91 bytes as intended while the gap-filling reads came back at 110, and both of the retries in that download were on the latter. Apply the same clamp to both, and share it rather than repeating it. Reducing the reply is safe and stays within the spec, which lets a server return less than was asked for. Clients already handle it because they track what is outstanding from the size in the reply: QGroundControl answers a short read by requesting the remainder, and MAVSDK writes whatever arrives at the offset given. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(boards): no more RGB LEDs for out of flash v2 * fix(mavlink): address review of the FTP and parameter pacing Keep batching parameters. The dump was throttled with a minimum interval between messages, which the batch loop for USB and UDP links immediately ran into: it sends up to 20 messages per call, and every one after the first was refused. Take the budget in bytes instead, accumulated over time, so a link with room to spare still sends its batch while a slow one is spread out as before. Share one budget between bulk transfers. A parameter dump and an FTP burst each paced themselves against half the link, and the streams only yielded the larger of the two shares, so the pair of them together could take the whole link and leave the telemetry nothing. Split one bulk share between whichever of them are running. Leave MAVLink 1 replies alone. Only MAVLink 2 drops the trailing zeros of a payload, so shrinking an FTP reply on a MAVLink 1 link costs the client bytes without making the packet any smaller, and the pacing has to budget for the whole payload there. End a burst that fails. The server returned 'not complete' for a failed read, so it sent the same NAK every couple of milliseconds until the client reset the session. ArduPilot marks that packet as the end of the burst; do the same. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julian Oes <julian@oes.ch> * fixup! fix(mavlink): rate-limit the parameter dump to its share of the link Signed-off-by: Julian Oes <julian@oes.ch> * fixup! fix(mavlink): fit FTP burst downloads to a telemetry radio Signed-off-by: Julian Oes <julian@oes.ch> * fixup! fix(mavlink): address review of the FTP and parameter pacing Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): treat a UDP data rate of 0 like USB Now that the parameter dump follows the configured data rate, MAV_x_RATE=0 on an ethernet link matters more. UDP has no baudrate, so 0 fell through to the 57600 serial initialiser and resolved to 2880 B/s, throttling the dump to about 39 parameters per second. Every in-tree ethernet configuration sets a rate explicitly, so this only bites when ethernet is moved to an instance left at 0, or on av/x-v1, which starts UDP without -r. Give UDP the same 100000 B/s fallback that USB already has. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): pace LOG_DATA log downloads behind a radio A LOG_DATA download was bounded only by the local UART buffer, so it over-drives a telemetry radio the same way an FTP burst did: the radio gets far more than it can carry over the air and drops packets, including the telemetry sharing the link. Pace it like the FTP burst. Behind a radio that reports RADIO_STATUS, send one packet per call, against the bulk share of the configured rate scaled by the radio's txbuf feedback. A log download now also counts as a bulk transfer, so it splits the bulk share with a parameter dump or FTP burst running at the same time, and the streams yield that share while it runs. A direct serial, USB or UDP link is unaffected. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes <julian@oes.ch> --------- Signed-off-by: Julian Oes <julian@oes.ch>