-
Notifications
You must be signed in to change notification settings - Fork 275
Mavgencpp example #733
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
Merged
Merged
Mavgencpp example #733
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # MAVLink C++ UDP Example | ||
|
|
||
| The [MAVLink C++ UDP Example](https://github.com/mavlink/mavlink/tree/master/examples/cpp) is a simple C++ 11 example that sends and receives MAVLink HEARTBEATs over UDP. | ||
|
|
||
| It is the C++ 11 counterpart to the [C UDP example](../mavgen_c/example_c_udp.md): instead of the C pack/decode functions, it uses the generated message structs (e.g. `mavlink::minimal::msg::HEARTBEAT`) together with `mavlink::MsgMap` to serialize and deserialize to and from a `mavlink_message_t`. | ||
|
|
||
| ::: info | ||
| The example should work on any Unix-like system (Linux, MacOS, BSD, etc.). | ||
| These instructions were tested on a _Ubuntu LTS 22.04_ installation with either PX4 or ArduPilot dependencies installed (such as cmake). | ||
| ::: | ||
|
|
||
| ::: warning | ||
| The C++ 11 library requires you to provide a `mavlink::mavlink_get_msg_entry()` function so that `mavlink_parse_char()` can look up the length and CRC extra of incoming messages. | ||
| This example builds it from the dialect's `MESSAGE_ENTRIES` table (see the top of `udp_example.cpp`, and the [Parsing Packets](index.md#parsing-packets) section for more detail). | ||
| ::: | ||
|
|
||
| ## Building/Running the Example | ||
|
|
||
| The following instructions show how to build and run the example. | ||
|
|
||
| 1. Clone the [mavlink/mavlink](https://github.com/mavlink/mavlink/) repository | ||
| 2. Open a terminal in the repository root. | ||
| 3. Use `cmake` to install MAVLink locally: | ||
|
|
||
| ```sh | ||
| cmake -Bbuild -H. -DCMAKE_INSTALL_PREFIX=install | ||
| cmake --build build --target install | ||
| ``` | ||
|
|
||
| This installs both the C (`*.h`) and C++ 11 (`*.hpp`) headers. | ||
|
|
||
| 4. Navigate to [examples/cpp](https://github.com/mavlink/mavlink/tree/master/examples/cpp) | ||
|
|
||
| ```sh | ||
| cd examples/cpp | ||
| ``` | ||
|
|
||
| 5. Use `cmake` to compile and build the example: | ||
|
|
||
| ```sh | ||
| cmake -Bbuild -H. -DCMAKE_PREFIX_PATH=$(pwd)/../../install | ||
| cmake --build build | ||
| ``` | ||
|
|
||
| 6. Run the executable from the terminal: | ||
|
|
||
| ```sh | ||
| ./build/udp_example | ||
| ``` | ||
|
|
||
| By default, the example will listen for data on the localhost IP address, port 14550. | ||
|
|
||
| 7. Open another terminal on the same machine and start either PX4 or ArduPilot. | ||
| These publish to port 14550 on localhost by default. | ||
| 8. The example should start displaying messages about sent and received HEARTBEAT messages in the terminal. | ||
| The following output is displayed if you connect to PX4: | ||
|
|
||
| ```sh | ||
| ~/github/mavlink/mavlink/examples/cpp$ ./build/udp_example | ||
|
|
||
| Sent heartbeat | ||
| Got heartbeat from PX4 autopilot | ||
| Sent heartbeat | ||
| Got heartbeat from PX4 autopilot | ||
| Sent heartbeat | ||
| Got heartbeat from PX4 autopilot | ||
| Sent heartbeat | ||
| Got heartbeat from PX4 autopilot | ||
| Sent heartbeat | ||
| Got heartbeat from PX4 autopilot | ||
| ... | ||
| ``` | ||
|
|
||
| Note that the build and installation instructions are from [examples/cpp/README.md](https://github.com/mavlink/mavlink/blob/master/examples/cpp/README.md). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Examples | ||
|
|
||
| - [UDP Example](../mavgen_cpp/example_cpp_udp.md): Simple C++ 11 example of a MAVLink UDP interface for Unix-like systems (Linux, MacOS, BSD, etc.). |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful.