MAVLink C Library #defines
The C library generated by mavgen can be configured for different platforms and uses by defining the macros below. They must be defined before the library headers (e.g. mavlink.h) are included, usually in a single header that your code includes instead of the MAVLink headers.
Each entry links to where the library tests the macro, and to where PX4 and ArduPilot set it (if they do).
Sending
MAVLINK_USE_CONVENIENCE_FUNCTIONS
Enables the mavlink_msg_*_send() functions in the generated message headers, and the helpers they use (_mav_finalize_message_chan_send(), _mavlink_send_uart(), _mavlink_resend_uart()). If defined you must also declare a global mavlink_system_t mavlink_system (the sending system and component IDs), and define either MAVLINK_SEND_UART_BYTES or comm_send_ch(). Leave it undefined if you pack and write out messages with your own code (see Transmitting).
Source: mavlink_helpers.h. Set by: PX4, ArduPilot.
MAVLINK_SEND_UART_BYTES
MAVLINK_SEND_UART_BYTES(chan, buf, len) writes len bytes to the channel. If not defined, the library instead calls comm_send_ch(chan, ch) for each byte, which you must then provide.
Source: mavlink_helpers.h. Set by: PX4, ArduPilot.
MAVLINK_START_UART_SEND, MAVLINK_END_UART_SEND
MAVLINK_START_UART_SEND(chan, length) and MAVLINK_END_UART_SEND(chan, length) are called before and after each packet is written by the convenience functions (empty by default). For example, ArduPilot uses them to lock the channel while a packet is written.
Source: protocol.h. Set by: PX4, ArduPilot.
Channels
MAVLINK_COMM_NUM_BUFFERS
Maximum number of channels, and hence of the receive buffers and status structures allocated by the library (one of each per channel). By default this is 16 on Linux, Windows and macOS, and 4 on other platforms. You might reduce this to save memory (e.g. to 1 on a system with only one link). Using a channel number at or above this value will overrun the arrays. See also FAQ > How can I further reduce the generated C library size?.
Source: mavlink_types.h. Set by: PX4, ArduPilot.
HAVE_MAVLINK_CHANNEL_T
The default mavlink_channel_t enum only defines MAVLINK_COMM_0 to MAVLINK_COMM_3. Define this and declare your own mavlink_channel_t if you use more channels.
Source: mavlink_types.h. Set by: PX4.
MAVLINK_GET_CHANNEL_STATUS, MAVLINK_GET_CHANNEL_BUFFER
Define to provide your own mavlink_get_channel_status(uint8_t chan) and mavlink_get_channel_buffer(uint8_t chan), instead of the library versions that return entries from static arrays. This allows you to keep the per-channel state wherever you like (the value of the macro is not used).
Source: mavlink_helpers.h. Set by: PX4 (implementation), ArduPilot (implementation).
MAVLINK_EXTERNAL_RX_STATUS, MAVLINK_EXTERNAL_RX_BUFFER
Keep the library versions of the functions above, but have them use arrays that you define, named m_mavlink_status (of mavlink_status_t) and m_mavlink_buffer (of mavlink_message_t), instead of static arrays inside the functions. These must be visible where mavlink_helpers.h is included (i.e. globals, or global pointers to memory that you allocate), with one entry per channel.
Source: mavlink_helpers.h.
Signing
Signing is enabled for each channel at runtime, as described in C Message Signing. These macros configure the signing implementation.
MAVLINK_MAX_SIGNING_STREAMS
Maximum number of signing streams ((link ID, system ID, component ID) tuples) tracked to detect replayed packets. Default 16. Signed packets from new streams are rejected once this limit is reached.
Source: mavlink_types.h.
MAVLINK_SIGNING_TIMESTAMP_LIMIT
A signed packet from a new stream is rejected if its timestamp is more than this many seconds older than the local signing timestamp. Default 60.
Source: mavlink_helpers.h.
MAVLINK_NO_SIGN_PACKET
Removes the code for signing outgoing packets (packets are never signed).
Source: mavlink_helpers.h.
MAVLINK_NO_SIGNATURE_CHECK
Removes the code for checking the signatures of incoming packets (signed packets are accepted without being verified).
Source: mavlink_helpers.h.
Parsing
MAVLINK_CHECK_MESSAGE_LENGTH
Rejects incoming messages with a payload length outside the minimum and maximum for their message ID. See Additional Checks.
Source: mavlink_helpers.h.
MAVLINK_GET_MSG_ENTRY
Define to provide your own mavlink_get_msg_entry(uint32_t msgid), which returns the CRC extra, lengths, and target field offsets for a message ID. The library version does a bisection search of the dialect's MAVLINK_MESSAGE_CRCS table.
Source: mavlink_helpers.h.
Code Size
MAVLINK_MAX_PAYLOAD_LEN
Maximum payload length (default 255 bytes). Reducing it reduces the size of mavlink_message_t, and hence of every channel buffer. It cannot be increased, because the payload length is stored in a uint8_t. Incoming packets with a longer payload are rejected, and the mavlink_msg_*_send_buf() functions are not generated for messages that are longer. For example, to reduce the maximum payload to the largest message in your dialect:
#include <mavlink/common/version.h>
#define MAVLINK_MAX_PAYLOAD_LEN MAVLINK_MAX_DIALECT_PAYLOAD_SIZE
#include <mavlink/common/mavlink.h>See also FAQ > How can I further reduce the generated C library size?.
Source: mavlink_types.h. Set by: ArduPilot (to 255).
MAVLINK_SEPARATE_HELPERS
Declares the helper functions in mavlink_helpers.h as ordinary functions, instead of defining them as static inline in every file that includes the library. You must then compile them once, normally by including mavlink_helpers.h in a single source file, or provide your own implementation.
Source: protocol.h. Set by: ArduPilot (compiled in).
MAVLINK_NO_CONVERSION_HELPERS
Omits the quaternion, Euler angle, and rotation matrix conversion functions (mavlink_quaternion_to_euler() and so on).
Source: mavlink_conversions.h. Set by: PX4, ArduPilot.
MAVLINK_USE_MESSAGE_INFO
Adds mavlink_get_message_info(), mavlink_get_message_info_by_id() and mavlink_get_message_info_by_name(), which return the name, type and offset of each field in a message. This is off by default because it adds a table describing every message in the dialect.
Source: mavlink_get_info.h.
Platform
NATIVE_BIG_ENDIAN
Define if using MAVLink on a system that is natively big-endian, so that fields are byte-swapped to and from the little-endian wire format.
Source: protocol.h.
WIP/Deprecated/Superseded Diagnostics
MAVLINK_WIP, MAVLINK_DEPRECATED, MAVLINK_SUPERSEDED, MAVLINK_ENUM_WIP, MAVLINK_ENUM_DEPRECATED, MAVLINK_ENUM_SUPERSEDED, and (C++ 11 only) MAVLINK_MSG_TYPE_WIP, MAVLINK_MSG_TYPE_DEPRECATED, MAVLINK_MSG_TYPE_SUPERSEDED are empty by default. Define them as compiler attributes, such as __attribute__((deprecated("..."))), to get compile-time diagnostics where your code uses WIP, deprecated, or superseded messages and enum entries.
Source: protocol.h, message.hpp.
Testing
MAVLINK_ASSERT
MAVLINK_ASSERT(x) is the assertion used by the generated test suites (testsuite.h). Empty by default.
Source: protocol.h.
Other Macros
Other macros in the headers, such as MAVLINK_NEED_BYTE_SWAP, MAVLINK_ALIGNED_FIELDS, MAVLINK_CRC_EXTRA and MAVLINK_USE_CXX_NAMESPACE, are set by the library or generated headers and should not be modified.

