|
| 1 | +//! # PX4 bindings for Rust |
| 2 | +//! |
| 3 | +//! This crate provides the framework to make dynamically loadable PX4 modules |
| 4 | +//! in Rust. Right now, it provides bindings for the two most important APIs: |
| 5 | +//! Logging and uORB. It also provides the entry point for your module, and |
| 6 | +//! handles panics on the main thread of the module. |
| 7 | +//! |
| 8 | +//! ## Compiling and running |
| 9 | +//! |
| 10 | +//! To build a PX4 module in Rust, create a crate as you would for any other |
| 11 | +//! application binary, and then add the following to your Cargo.toml: |
| 12 | +//! |
| 13 | +//! ```text |
| 14 | +//! [lib] |
| 15 | +//! crate-type = ["cdylib"] |
| 16 | +//! path = "src/main.rs" |
| 17 | +//! ``` |
| 18 | +//! |
| 19 | +//! This will turn your program into a loadable module instead of a standalone |
| 20 | +//! application. The resulting file will be called `lib<name>.so`, which you |
| 21 | +//! can manually rename to `<name>.px4mod` if you want. |
| 22 | +//! |
| 23 | +//! To run your module, use the |
| 24 | +//! [`dyn`](https://dev.px4.io/en/middleware/modules_command.html#dyn) |
| 25 | +//! PX4 command. Give it the full path name, followed by any arguments to your |
| 26 | +//! module. Note that `dyn` will *not* reload your file if you run it again. |
| 27 | +//! If you want to run a changed version of your module, you'll either need to |
| 28 | +//! restart PX4, or move/rename the file. |
| 29 | +//! |
| 30 | +//! ## Entry point |
| 31 | +//! |
| 32 | +//! Mark your entry function with `#[px4_module_main]`. The boilerplate code |
| 33 | +//! needed to set up the environment and export the function under the right |
| 34 | +//! name is then inserted automatically. |
| 35 | +//! |
| 36 | +//! Your main function should take a `&[&str]` as argument, and return a `i32` |
| 37 | +//! status code. A panic from your main thread is caught and results in a |
| 38 | +//! status code of −1. |
| 39 | +//! |
| 40 | +//! ### Example |
| 41 | +//! |
| 42 | +//! ``` |
| 43 | +//! extern crate px4; |
| 44 | +//! |
| 45 | +//! use px4::px4_module_main; |
| 46 | +//! |
| 47 | +//! #[px4_module_main] |
| 48 | +//! fn my_module(args: &[&str]) -> i32 { |
| 49 | +//! 0 |
| 50 | +//! } |
| 51 | +//! ``` |
| 52 | +//! |
| 53 | +//! ## Logging |
| 54 | +//! |
| 55 | +//! As soon as your main function is entered, logging is already set up using |
| 56 | +//! the standard [`log` crate](https://docs.rs/log/). You can use the standard |
| 57 | +//! logging macros such as `info!`, `warn!`, and `error!` to log messages, |
| 58 | +//! equivalent to `PX4_INFO` (etc.) in C and C++. |
| 59 | +//! |
| 60 | +//! Use the `info_raw!` macro to send raw output, equivalent to the |
| 61 | +//! `PX4_INFO_RAW` macro in C and C++. |
| 62 | +//! Do not use standard output or standard error for this, as the standard |
| 63 | +//! streams of the PX4 process are often not the ones connected to the terminal |
| 64 | +//! the user is looking at. |
| 65 | +//! |
| 66 | +//! ### Example |
| 67 | +//! |
| 68 | +//! ``` |
| 69 | +//! extern crate log; |
| 70 | +//! extern crate px4; |
| 71 | +//! |
| 72 | +//! use log::{info, warn}; |
| 73 | +//! use px4::px4_module_main; |
| 74 | +//! |
| 75 | +//! #[px4_module_main] |
| 76 | +//! fn my_module(args: &[&str]) -> i32 { |
| 77 | +//! info!("Hello World!"); |
| 78 | +//! warn!("A warning!"); |
| 79 | +//! panic!("Bye!"); |
| 80 | +//! } |
| 81 | +//! ``` |
| 82 | +//! |
| 83 | +//! ### uORB |
| 84 | +//! |
| 85 | +//! See the [`uorb` module](uorb/index.html) for documentation on how to use |
| 86 | +//! the uORB bindings. |
| 87 | +//! |
| 88 | +
|
1 | 89 | extern crate log;
|
2 | 90 | extern crate px4_macros;
|
3 | 91 |
|
|
0 commit comments