From 48c015ff9d547cdd9119babf7ff62abe89a7d6ba Mon Sep 17 00:00:00 2001 From: Antonio Sanjurjo C <74329840+antonio-sc66@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:24:11 +0100 Subject: [PATCH 1/3] Refactor mavlink-dump. Change from [[bin]] to [[example]]. Splitting the example has the following benefits: - Faster normal compilation for library use - Easier to retain compilation incremental files (faster re-compilation times) - Cleaner library src/ directory - no_std/std definitions and imports can be removed from the mavlink-dump example - Executable name changes from mavlink -> mavlink-dump. More precise to locate and guess what it is for Disadvantage: - Installation time for the example is increased, but it is something rarely done --- Cargo.toml | 3 ++- examples/mavlink-dump/Cargo.toml | 15 +++++++++++++++ .../mavlink-dump/src/main.rs | 8 -------- 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 examples/mavlink-dump/Cargo.toml rename src/bin/mavlink-dump.rs => examples/mavlink-dump/src/main.rs (95%) diff --git a/Cargo.toml b/Cargo.toml index 8ae58048c5..b099521299 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,9 @@ proc-macro2 = "1.0.43" lazy_static = "1.2.0" serde = { version = "1.0.115", optional = true, features = ["derive"] } -[[bin]] +[[example]] name = "mavlink-dump" +path = "examples/mavlink-dump/src/main.rs" required-features = ["ardupilotmega"] [dependencies] diff --git a/examples/mavlink-dump/Cargo.toml b/examples/mavlink-dump/Cargo.toml new file mode 100644 index 0000000000..284ab5c890 --- /dev/null +++ b/examples/mavlink-dump/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "mavlink-dump" +authors = [ + "Patrick José Pereira ", +] +license = "MIT/Apache-2.0" +edition = "2018" +version = "0.1.0" + +[profile.release] +opt-level = 3 +lto = true # Performs "fat" LTO which attempts to perform optimizations across all crates within the dependency graph + +[dependencies.mavlink] # MAVLink library +path = "../../" diff --git a/src/bin/mavlink-dump.rs b/examples/mavlink-dump/src/main.rs similarity index 95% rename from src/bin/mavlink-dump.rs rename to examples/mavlink-dump/src/main.rs index 9d30e84d40..f2f1043504 100644 --- a/src/bin/mavlink-dump.rs +++ b/examples/mavlink-dump/src/main.rs @@ -1,11 +1,6 @@ use mavlink::error::MessageReadError; -#[cfg(feature = "std")] use std::{env, sync::Arc, thread, time::Duration}; -#[cfg(not(feature = "std"))] -fn main() {} - -#[cfg(feature = "std")] fn main() { let args: Vec<_> = env::args().collect(); @@ -65,7 +60,6 @@ fn main() { } /// Create a heartbeat message using 'ardupilotmega' dialect -#[cfg(feature = "std")] pub fn heartbeat_message() -> mavlink::ardupilotmega::MavMessage { mavlink::ardupilotmega::MavMessage::HEARTBEAT(mavlink::ardupilotmega::HEARTBEAT_DATA { custom_mode: 0, @@ -78,7 +72,6 @@ pub fn heartbeat_message() -> mavlink::ardupilotmega::MavMessage { } /// Create a message requesting the parameters list -#[cfg(feature = "std")] pub fn request_parameters() -> mavlink::ardupilotmega::MavMessage { mavlink::ardupilotmega::MavMessage::PARAM_REQUEST_LIST( mavlink::ardupilotmega::PARAM_REQUEST_LIST_DATA { @@ -89,7 +82,6 @@ pub fn request_parameters() -> mavlink::ardupilotmega::MavMessage { } /// Create a message enabling data streaming -#[cfg(feature = "std")] pub fn request_stream() -> mavlink::ardupilotmega::MavMessage { mavlink::ardupilotmega::MavMessage::REQUEST_DATA_STREAM( mavlink::ardupilotmega::REQUEST_DATA_STREAM_DATA { From d1e75934ec4c48baf5f0ae68866e206342f40efc Mon Sep 17 00:00:00 2001 From: Antonio Sanjurjo C <74329840+antonio-sc66@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:29:49 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 45594840cd..e7871ae8ed 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,29 @@ mavlink = "0.12.2" ``` ## Examples -See [src/bin/mavlink-dump.rs](src/bin/mavlink-dump.rs) for a usage example. +See [examples/](examples/mavlink-dump/src/main) for different usage examples. + +### mavlink-dump +[examples/mavlink-dump](examples/mavlink-dump/src/main) contains an executable example that can be used to test message reception. + +It can be executed directly by running: +``` +cargo run --example mavlink-dump [options] +``` It's also possible to install the working example via `cargo` command line: ```sh -cargo install mavlink +cargo install --path examples/mavlink-dump +``` + +It can then be executed by running: +``` +mavlink-dump [options] +``` + +Execution call example: +```sh +mavlink-dump udpin:127.0.0.1:14540 ``` ### Community projects From 436f479736fa9c809d399e05232f1acc05e3307c Mon Sep 17 00:00:00 2001 From: Antonio Sanjurjo C <74329840+antonio-sc66@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:59:22 +0100 Subject: [PATCH 3/3] Update .github workflow to accommodate for the mavlink-dump refactor --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b439439622..9011cc0c69 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@master - uses: dtolnay/rust-toolchain@stable - name: Build mavlink-dump - run: cargo build --verbose --bin mavlink-dump --features ardupilotmega + run: cargo build --verbose --example mavlink-dump msrv: runs-on: ubuntu-latest