TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Ardupilot/ardupilot/llms.txt
Use this file to discover all available pages before exploring further.
GCS_MAVLink library is ArduPilot’s implementation of the MAVLink protocol. It manages every aspect of ground-station communication: sending telemetry streams, handling incoming commands and parameter requests, routing messages between multiple serial ports, and optionally authenticating links with cryptographic signing. Every ArduPilot vehicle type builds on this library.
Telemetry Streaming
Periodic messages (attitude, GPS, battery, RC) are organised into named streams and sent at configurable rates via the
SR0_*–SR5_* parameters.Command Handling
Incoming
COMMAND_LONG and COMMAND_INT messages are dispatched to per-command handlers and acknowledged with MAV_RESULT values.Multi-Port Support
Up to 8 simultaneous MAVLink channels (5 on smaller boards) can be active at once, each with independent stream rates and options.
Message Routing
The
MAVLink_routing class automatically learns component routes and forwards packets to the correct port, enabling companion-computer topologies.Core classes
Two classes divide the work:GCS is the global singleton that owns all active channels and provides convenience helpers, while GCS_MAVLINK handles one physical serial port.
| Class | Role |
|---|---|
GCS | Global singleton; broadcasts messages to all channels, owns the status-text queue |
GCS_MAVLINK | Per-channel object; encodes/decodes MAVLink frames, manages stream buckets |
MAVLink_routing | Static routing table; learns and forwards messages between channels |
GCS_FTP | File-transfer-over-MAVLink implementation (enabled by AP_MAVLINK_FTP_ENABLED) |
Sending messages
Status text
The recommended way to send a human-readable message to a GCS is theGCS_SEND_TEXT macro. Unlike calling gcs().send_text() directly, the macro is evaluated lazily and avoids formatting overhead when no GCS is connected.
MAV_SEVERITY levels (from highest to lowest): EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG.
Named float
send_named_float() sends a NAMED_VALUE_FLOAT MAVLink message — useful for publishing a custom scalar without defining a full log message type:
Arbitrary MAVLink messages
Any pre-encoded MAVLink struct can be sent via the low-levelsend_message() overload that accepts a raw packet pointer and a mavlink_msg_entry_t:
Telemetry stream rates
Telemetry messages are grouped into named streams. Each stream has a corresponding parameter familySRn_* where n is the port index (0–5).
| Stream enum | Parameter suffix | Typical messages |
|---|---|---|
STREAM_RAW_SENSORS | RAW_SENS | RAW_IMU, SCALED_PRESSURE, SCALED_IMU2 |
STREAM_EXTENDED_STATUS | EXT_STAT | SYS_STATUS, MEMINFO, NAV_CONTROLLER_OUTPUT |
STREAM_RC_CHANNELS | RC_CHAN | SERVO_OUTPUT_RAW, RC_CHANNELS |
STREAM_RAW_CONTROLLER | RAW_CTRL | (reserved for raw controller data) |
STREAM_POSITION | POSITION | GLOBAL_POSITION_INT, LOCAL_POSITION_NED |
STREAM_EXTRA1 | EXTRA1 | ATTITUDE, SIMSTATE |
STREAM_EXTRA2 | EXTRA2 | VFR_HUD |
STREAM_EXTRA3 | EXTRA3 | AHRS, HWSTATUS, WIND, RANGEFINDER |
STREAM_PARAMS | PARAMS | PARAM_VALUE (parameter list streaming) |
STREAM_ADSB | ADSB | ADSB_VEHICLE |
0 disables the stream. Mission Planner and QGroundControl request stream rates on connect via REQUEST_DATA_STREAM.
Message routing
MAVLink_routing maintains a table of up to 20 routes. Each route maps a (sysid, compid) pair to the mavlink_channel_t on which that component was last seen. Routes are learned automatically from incoming heartbeats and other messages.
GCS_MAVLINK::find_by_mavtype(…)):
| Method | Purpose |
|---|---|
find_by_mavtype(mav_type, sysid, compid, channel) | Locate a component by MAV_TYPE |
find_by_mavtype_and_compid(mav_type, compid, sysid, channel) | Locate by type and component ID |
send_to_components(msgid, pkt, pkt_len) | Broadcast to all learned components |
disable_channel_routing(chan) | Prevent forwarding on a channel (e.g. for high-latency links) |
MAVLink signing
MAVLink 2 signing (authentication) is available whenAP_MAVLINK_SIGNING_ENABLED is defined. The signing key is stored in EEPROM/flash and loaded at startup.
FTP over MAVLink
WhenAP_MAVLINK_FTP_ENABLED is set, the GCS_FTP class implements the MAVLink FTP sub-protocol (message ID FILE_TRANSFER_PROTOCOL). This allows Mission Planner and QGroundControl to:
- Download log files directly from the SD card.
- Upload parameter files.
- Browse and delete files on the flight controller’s filesystem.
GCS_MAVLINK channel locks itself (_locked = true) during an active FTP session so that the port is not used for normal MAVLink traffic simultaneously.
Handling incoming commands
COMMAND_LONG and COMMAND_INT
AllCOMMAND_LONG messages are internally converted to COMMAND_INT via convert_COMMAND_LONG_to_COMMAND_INT(), then dispatched through handle_command_int_packet(). Vehicle subclasses override this method to handle vehicle-specific commands.
MAV_RESULT value. The base class sends the COMMAND_ACK automatically.
Adding a new message handler
To handle a new incoming MAVLink message type, overridehandle_message() in your vehicle’s GCS_MAVLINK subclass:
Always call
GCS_MAVLINK::handle_message(msg) in the default branch. The base class handles many essential messages (heartbeat, param, mission, timesync, etc.) that must not be silently dropped.Payload space guards
Before sending a message, check that there is room in the transmit buffer to avoid dropped packets:Complete example: custom status and command
Key parameters
SERIALn_BAUD / SERIALn_PROTOCOL
SERIALn_BAUD / SERIALn_PROTOCOL
Set a serial port to MAVLink 1 (
1) or MAVLink 2 (2) by setting SERIALn_PROTOCOL. The baud rate is set with SERIALn_BAUD.SRn_EXT_STAT, SRn_POSITION, SRn_EXTRA1, …
SRn_EXT_STAT, SRn_POSITION, SRn_EXTRA1, …
Per-channel stream rates in Hz.
SR0_* applies to the first MAVLink port, SR1_* to the second, and so on up to SR5_*.SERIALn_OPTIONS
SERIALn_OPTIONS
Bitmask of per-port options. Bit 0 disables MAVLink 2 signing. Bit 1 (
NO_FORWARD) prevents packets being forwarded to or from this port. Bit 2 (NOSTREAMOVERRIDE) ignores REQUEST_DATA_STREAM from GCS.