Skip to content

Add topic on MAVLink C library #defines #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [Using MAVLink Libraries](getting_started/use_libraries.md)
* [C (mavgen)](mavgen_c/README.md)
* [Message Signing](mavgen_c/message_signing_c.md)
* [C Defines](mavgen_c/defines.md)
* [Examples](mavgen_c/examples.md)
* [UART Interface (C)](mavgen_c/example_c_uart.md)
* [UDP Example (C)](mavgen_c/example_c_udp.md)
Expand Down
32 changes: 32 additions & 0 deletions en/mavgen_c/defines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# MAVLink C Library #defines

The following C `#defines` can be set in code in order to tune the setup for use on different platforms.

- `MAVLINK_USE_CONVENIENCE_FUNCTIONS` ([protocol.h](https://github.com/ArduPilot/pymavlink/blob/master/generator/C/include_v2.0/protocol.h)): Causes convenience functions to be defined, including: `_mav_finalize_message_chan_send()`, `_mavlink_send_uart()`, `_mavlink_resend_uart()`.
Library users may choose not to set this and roll out their own implementations for efficiency (or other) reasons.
- `MAVLINK_COMM_NUM_BUFFERS`: Sets the maximum number of comms buffers to be used (comms channels).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would I be correct in thinking that you might specify 1 if you knew you had a mavlink component that would only have one connection to the network?

By default this is set to 16 on Linux, Windows and macOS, and to 4 on other platforms.
You might set `#define MAVLINK_COMM_NUM_BUFFERS 2` on an embedded system that would only ever have two channels, in order to reduce memory overheads.
A stack overrun will occur if there are more buffers used than allocated.
See [FAQ > How can I further reduce the generated C library size?](../about/faq.md#developers).
- `MAVLINK_SIGNING_FLAG_SIGN_OUTGOING` ([mavlink_types.h](https://github.com/ArduPilot/pymavlink/blob/master/generator/C/include_v2.0/mavlink_types.h)): Enable/disable outgoing signing.
See [Enabling Signing on a Channel > Enabling Signing on a Channel](../mavgen_c/message_signing_c.md#enabling_signing_channel)
- `MAVLINK_EXTERNAL_RX_STATUS` ([mavlink_helpers.h](https://github.com/ArduPilot/pymavlink/blob/master/generator/C/include_v2.0/mavlink_helpers.h)): `mavlink_status_t* mavlink_get_channel_status(uint8_t chan)` returns the status of a particular channel using a preallocated `static` array.
Define `MAVLINK_EXTERNAL_RX_STATUS` if you want to use your own external array (named `m_mavlink_status`) of `mavlink_status_t` objects.
- `MAVLINK_EXTERNAL_RX_BUFFER` ([mavlink_helpers.h](https://github.com/ArduPilot/pymavlink/blob/master/generator/C/include_v2.0/mavlink_helpers.h)): Set if you want to define your own channel comms buffers on the stack or heap, rather than using the pre-allocated `static` buffers.
If you define this you will need to declare an array of `mavlink_message_t` (one for each channel) named `m_mavlink_buffer`.
- `NATIVE_BIG_ENDIAN` ([protocol.h](https://github.com/ArduPilot/pymavlink/blob/master/generator/C/include_v2.0/protocol.h)): Enable if using MAVLink on a system that is native big-endian (MAVLINK_LITTLE_ENDIAN is true by default).
- `MAVLINK_SEPARATE_HELPERS` ([protocol.h](https://github.com/ArduPilot/pymavlink/blob/master/generator/C/include_v2.0/protocol.h)): Set to remove all the helpers declared `mavlink_helpers.h`, allowing you to provide an alternative implementation.
- `MAVLINK_MAX_PAYLOAD_LEN`: Override the maximum payload length.
The default maximum payload length is 255 bytes. With care you can override this to reduce the size, and hence memory usage (note, the maximum size cannot be increased as it is stored in a `uint8_t).
For example, to reduce the maximum payload to the smallest size supported by a dialect you could do:

```c
#include <version.h>
#define MAVLINK_MAX_PAYLOAD_LEN MAVLINK_MAX_DIALECT_PAYLOAD_SIZE
```

See also [FAQ > How can I further reduce the generated C library size?](../about/faq.md#developers).


There are a number of other internal defines that should not be modified.