mavsdk::MavlinkDirectServer Class Reference ​
#include: mavlink_direct_server.hpp
Enable direct MAVLink communication using libmav from a server component.
Unlike MavlinkDirect, this does not require a discovered system: it sends from the local server component, which makes it suitable for broadcasting messages (e.g. as an autopilot or custom component) without a connected counterpart.
Data Structures ​
struct MavlinkMessage
Public Types ​
| Type | Description |
|---|---|
| enum Result | Possible results returned for action requests. |
| std::function< void(Result)> ResultCallback | Callback type for asynchronous MavlinkDirectServer calls. |
| std::function< void(MavlinkMessage)> MessageCallback | Callback type for subscribe_message. |
| Handle< MavlinkMessage > MessageHandle | Handle type for subscribe_message. |
Public Member Functions ​
| Type | Name | Description |
|---|---|---|
| Â | MavlinkDirectServer (std::shared_ptr< ServerComponent > server_component) | Constructor. Creates the plugin for a ServerComponent instance. |
| Â | ~MavlinkDirectServer () override | Destructor (internal use only). |
| Â | MavlinkDirectServer (const MavlinkDirectServer & other) | Copy constructor. |
| Result | send_message (MavlinkMessage message)const | Send a MAVLink message directly. |
| MessageHandle | subscribe_message (std::string message_name, const MessageCallback & callback) | Subscribe to incoming MAVLink messages. |
| void | unsubscribe_message (MessageHandle handle) | Unsubscribe from subscribe_message. |
| Result | load_custom_xml (std::string xml_content)const | Load custom MAVLink message definitions from XML. |
| const MavlinkDirectServer & | operator= (const MavlinkDirectServer &)=delete | Equality operator (object is not copyable). |
Constructor & Destructor Documentation ​
MavlinkDirectServer() ​
mavsdk::MavlinkDirectServer::MavlinkDirectServer(std::shared_ptr< ServerComponent > server_component)Constructor. Creates the plugin for a ServerComponent instance.
The plugin is typically created as shown below:
auto mavlink_direct_server = MavlinkDirectServer(server_component);Parameters
- std::shared_ptr< ServerComponent > server_component - The ServerComponent instance associated with this server plugin.
~MavlinkDirectServer() ​
mavsdk::MavlinkDirectServer::~MavlinkDirectServer() overrideDestructor (internal use only).
MavlinkDirectServer() ​
mavsdk::MavlinkDirectServer::MavlinkDirectServer(const MavlinkDirectServer &other)Copy constructor.
Parameters
- const MavlinkDirectServer& other -
Member Typdef Documentation ​
typedef ResultCallback ​
using mavsdk::MavlinkDirectServer::ResultCallback = std::function<void(Result)>Callback type for asynchronous MavlinkDirectServer calls.
typedef MessageCallback ​
using mavsdk::MavlinkDirectServer::MessageCallback = std::function<void(MavlinkMessage)>Callback type for subscribe_message.
typedef MessageHandle ​
using mavsdk::MavlinkDirectServer::MessageHandle = Handle<MavlinkMessage>Handle type for subscribe_message.
Member Enumeration Documentation ​
enum Result ​
Possible results returned for action requests.
| Value | Description |
|---|---|
Unknown | Unknown result. |
Success | Request succeeded. |
Error | Error. |
InvalidMessage | Invalid MAVLink message. |
InvalidField | Invalid field name or value. |
ConnectionError | Connection error. |
NoSystem | No system connected. |
Timeout | Request timed out. |
Member Function Documentation ​
send_message() ​
Result mavsdk::MavlinkDirectServer::send_message(MavlinkMessage message) constSend a MAVLink message directly.
This allows sending any MAVLink message with full control over the message content. Leave target_system_id and target_component_id at 0 to broadcast.
This function is blocking.
Parameters
- MavlinkMessage message -
Returns
 Result - Result of request.
subscribe_message() ​
MessageHandle mavsdk::MavlinkDirectServer::subscribe_message(std::string message_name, const MessageCallback &callback)Subscribe to incoming MAVLink messages.
This provides direct access to incoming MAVLink messages. Use an empty string in message_name to subscribe to all messages, or specify a message name (e.g., "HEARTBEAT") to filter for specific message types. Unlike the MavlinkDirect (client) plugin, this is not scoped to a single system: it receives matching messages from all systems.
Parameters
- std::string message_name -
- const MessageCallback& callback -
Returns
 MessageHandle -
unsubscribe_message() ​
void mavsdk::MavlinkDirectServer::unsubscribe_message(MessageHandle handle)Unsubscribe from subscribe_message.
Parameters
- MessageHandle handle -
load_custom_xml() ​
Result mavsdk::MavlinkDirectServer::load_custom_xml(std::string xml_content) constLoad custom MAVLink message definitions from XML.
This allows loading custom MAVLink message definitions at runtime, extending the available message types beyond the built-in definitions.
This function is blocking.
Parameters
- std::string xml_content -
Returns
 Result - Result of request.
operator=() ​
const MavlinkDirectServer & mavsdk::MavlinkDirectServer::operator=(const MavlinkDirectServer &)=deleteEquality operator (object is not copyable).
Parameters
- const MavlinkDirectServer& -
Returns
 const MavlinkDirectServer & -

