feat(oot): support external MAVLink handler, stream, and dialect with opt in custom init scripts in Out of Tree modules#27415
Open
methodmissing wants to merge 10 commits into
Open
Conversation
…AVLink dialect support
…VLink dialect registration and handling
|
This pull request has been mentioned on Dronecode Forum | Open Source Drone Development. There might be relevant details there: https://discuss.px4.io/t/px4-dev-call-may-20-2026-team-sync-and-community-q-a/48985/3 |
Contributor
🔎 FLASH Analysispx4_fmu-v5x [Total VM Diff: 776 byte (0.04 %)]px4_fmu-v6x [Total VM Diff: 760 byte (0.04 %)]Updated: 2026-05-20T13:55:55 |
Contributor
|
No broken links found in changed files. |
| Registered handlers are invoked from the MAVLink receiver thread's `default` switch case. | ||
| Registration is mutex-protected; dispatch is lock-free. | ||
|
|
||
| ### Outbound Streams |
Contributor
There was a problem hiding this comment.
This is cool, but what if I just want to send a message or command, not stream it?
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.
mavlink: external handler, stream, and dialect support for out-of-tree modules
Summary
References #26261 , specifically to attempt to address some difficulties I bumped into with a "clean cut" out of tree external module
Adds first-class MAVLink support for out-of-tree (OOT) modules: custom dialect
code generation, inbound message handling, outbound streaming, and ROMFS init
script injection — all without patching PX4 source.
Currently, OOT modules that need custom MAVLink messages must manually symlink
dialect XMLs, patch
mavlink_receiver.cpp, and hand-editrcS. This PReliminates all of that with a convention-based approach.
Tested end-to-end with a PX4 module and driver for the SE05x secure element present on Pixhawk 6X boards that uses 6 custom MAVLink messages for PKI enrollment over USB, running on Pixhawk 6X-RT hardware.
Changes
1. External MAVLink handler registry (
mavlink_ext_handler.{h,cpp})Static callback table (max 8 entries, probably should be configurable) for inbound custom messages. Registration
is mutex-protected; dispatch is lock-free from the receiver thread's
defaultcase:
It should have no overhead in the hot / happy path as it injects at the
defaultcase handler which currently hard drops any unknown MAVLink message IDs.OOT module usage:
2. External MAVLink stream registry (
mavlink_ext_stream.{h,cpp})Static callback table for outbound streams, dispatched from
Mavlink::task_main()after the built-in stream loop. Supports rate-limited intervals and integrates
with
SET_MESSAGE_INTERVALso QGC/pymavlink can control OOT stream ratesidentically to built-in streams:
3. CMake dialect registration (
px4_add_external_mavlink_dialect)Shared CMake function that copies OOT dialect XMLs into mavgen's search path
and auto-overrides
CONFIG_MAVLINK_DIALECTfromcommon:The dialect XML uses standard
<include>common.xml</include>inheritance, soall built-in messages remain available. Multiple dialects from different OOT
modules are supported.
4. ROMFS init script injection (
ROMFS/CMakeLists.txt,rcS)OOT modules can provide
init/rc.ext_moduleswhich is automatically copiedinto the ROMFS image and sourced by
rcSafter the logger starts:Example
init/rc.ext_modules:se05x start se05x_mavlink start se05x derive-keys &Directory convention:
Integration points (minimal PX4 source changes)
mavlink_receiver.cpp#include+dispatch()indefault:+set_intervalfallbackmavlink_main.cpp#include+ext_stream_dispatch()in main loopCMakeLists.txtinclude()dialect cmake + dialect auto-override afteradd_subdirectoryROMFS/CMakeLists.txtrc.ext_modulesinto ROMFS imagercSrc.ext_modulesafterrc.loggingAll new files:
mavlink_ext_handler.{h,cpp},mavlink_ext_stream.{h,cpp},px4_add_external_mavlink_dialect.cmake.Design decisions
arrays (8 slots each, can be configurable). No heap allocation at runtime. Lock-free dispatch.
register/unregisterare mutex-protected(called once at init/shutdown).
dispatchiterates the array without locking— safe because entries are only appended/cleared while the slot count is
atomically visible.
CONFIG_MAVLINK_DIALECTifit's the default
common. If a board already sets a specific dialect, it'spreserved.
rc.ext_moduleshook isif [ -f ... ]guarded. No impact on builds without
EXTERNAL_MODULES_LOCATION.Testing
Validated on Pixhawk 6X-RT (fmu-v6xrt) with the SE05x secure element OOT
module performing:
certificate transfers)
HMAC-SHA384)
Example usage in OOT module
Header file of the MAVLink handler concerns
Custom MAVLink SE05x dialect
Includes
common.xmlCustom init to boostrap the SE05x driver, MAVLink handler and session keys
Build output demonstrating MAVLink dialect and ROMFS integration