Skip to content

MAVLink: support mavlink 2.1 32 bit system IDs#33734

Open
tridge wants to merge 16 commits into
ArduPilot:masterfrom
tridge:pr-mavlink32bitsysid
Open

MAVLink: support mavlink 2.1 32 bit system IDs#33734
tridge wants to merge 16 commits into
ArduPilot:masterfrom
tridge:pr-mavlink32bitsysid

Conversation

@tridge

@tridge tridge commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements 32 bit system IDs

See also:

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Description

This implements mavlink/rfcs#20 but with 32 bit system IDs to allow for IPv4 addresses to be used for system IDs. This should make large drone light shows easier.
I also plan on making full 32 bit integers work with mavlink parameters to make this more practical for real IPv4 addresses. That will be a separate effort

Some open questions:

  • should we put target_system&0xff in the uint8_t target_system field in messages or should we put in 0? This PR uses 0
  • the lua script changes are tricky as the mavlink receiver gets the raw C structure which is now 3 bytes larger. Should we add compatibility code so the new lua script handles both forms? UPDATE: I've added compat code

Comment thread libraries/AP_Follow/AP_Follow.cpp
@tridge
tridge force-pushed the pr-mavlink32bitsysid branch from 76eb4fc to 8c631c4 Compare July 18, 2026 07:54
tridge added 14 commits July 18, 2026 17:57
Pulls in the MAVLink2.1 32 bit system ID and extended target header
support (MAVLINK_IFLAG_SYSID32 / MAVLINK_IFLAG_TARGETTED) from
mavlink/rfcs#20.
Widen system ID handling throughout for MAVLink2.1 32 bit system IDs
(mavlink/rfcs#20):

 - MAV_SYSID, MAV_GCS_SYSID and MAV_GCS_SYSID_HI become AP_Int32 with
   parameter width conversion. Values must stay below 2^24 until the
   parameter transport moves away from float32
 - routing table entries, get_targets() and find_by_mavtype use the
   new mavlink_msg_get_target_sysid/compid helpers so targets in the
   extended TARGETTED header are routed correctly
 - send_message_target() lets raw payload struct senders pass a
   possibly 32 bit target for the extended header; used by the
   mission and FTP reply paths
 - send_to_components() passes our sysid so component relays work
   when our sysid is over 255
 - packet_overhead_chan() accounts for the extended header bytes
 - MANUAL_CONTROL target check uses the TARGETTED-aware getter
Widen gimbal and target sysid storage and pass 32 bit targets via the
extended header aware send path.
Widen camera sysid storage and pass 32 bit targets via the extended
header aware send path.
Widen source/target system IDs in the MAVC log message and the
MAVLink log transfer target.
FOLL_SYSID becomes AP_Int32 with parameter width conversion. Values
must stay below 2^24 until the parameter transport moves away from
float32.
SYSID_TARGET becomes AP_Int32 with parameter width conversion.
Reboots with MAV_SYSID 100000, checks the SYSID32 extended header is
used, fetches parameters from a source system over 255, and runs
mission upload and arming checks at the new sysid.
Widen the CAN forwarding requester system ID so replies to a 32 bit
GCS are not aliased.
Accept 32 bit sysids in MAV_CMD_DO_FOLLOW.
The component ID was compared against the last source system ID
instead of the last source component ID.
tridge added 2 commits July 18, 2026 17:57
The Lua MAVLink module and scripts parse the in-memory
mavlink_message_t structure; the wider sysid moved the compid, msgid
and payload offsets, and the CRC check must reconstruct the wire
header from the incompat flags. The extended header target is exposed
as target_sysid/target_compid.

Users often copy current scripts onto older firmware, so the layout
is detected at runtime from the structure size: 291 bytes for the
older 1 byte sysid layout, 299 bytes for the 32 bit sysid layout.
The same scripts work on both firmware generations.
@tridge
tridge force-pushed the pr-mavlink32bitsysid branch from 8c631c4 to b45972c Compare July 18, 2026 07:57
@tridge

tridge commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Automated review note — AI-generated (Claude), validated against the live diff and cross-checked by a second AI reviewer (Codex). Please sanity-check before acting.

Verdict: REQUEST CHANGES — the widening is coherent and careful (param width conversions, extended-header targeting, routing, Lua dual-layout handling, and the 100000-sysid autotest all check out), but three sysid truncation sites remain in-tree that break when a >255 sysid is actually used:

  • libraries/AP_CANManager/AP_MAVLinkCAN.cpp:298 — local uint8_t system_id copies the widened can_forward.system_id (:337), so CANFD/CAN frame replies (:347/:354) are misaddressed for requesters with sysid > 255. The struct field in AP_MAVLinkCAN.h was widened by this PR but the .cpp local copy was missed.
  • libraries/AP_Generator/AP_Generator_Loweheiser.h:106uint8_t sysid: assignment truncates at AP_Generator_Loweheiser.cpp:691, the source-match guard at :638 then misbehaves, commands at :473 target the truncated ID (the QBB log at :507 would also need widening).
  • libraries/AP_OpenDroneID/AP_OpenDroneID.cpp:138uint8_t val = gcs().sysid_this_mav(); truncates a high local sysid for the ODID Basic ID broadcast.

Positive notes: the handle_statustext() chunking fix (compid was compared against last_src_system) is a genuine drive-by bugfix; packet_overhead_chan()'s conservative extended-header reservation is sound. Procedural: needs the modules/mavlink bump merged with/before it, and a rebase (check-merge-commits failing). NOTE: AP_Follow's width conversion runs lazily on first update_estimates() rather than at init — a tiny window where a param fetch sees the default; harmless but worth knowing.

@tridge tridge removed the DevCallEU label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants