px4/uorb/mod.rs
1//! Bindings to the uORB messaging system.
2//!
3//! ## Message definitions
4//!
5//! This crate provides a way to import a message definition from a `.msg`
6//! file:
7//!
8//! ```ignore
9//! use px4::px4_message;
10//!
11//! #[px4_message("msg/foo.msg")] pub struct foo;
12//! ```
13//!
14//! This will read `msg/foo.msg`, relative to the root of the crate (where your
15//! Cargo.toml is), parse its contents, and generate the equivalent Rust
16//! struct. In addition, [`Message`](trait.Message.html), `Clone` and `Debug`
17//! are derived automatically.
18//!
19//! ## Subscribing
20//!
21//! Subscribing is done through the [`Subscribe` trait](trait.Subscribe.html),
22//! which is automatically implemented for all messages.
23//!
24//! ```ignore
25//! use px4::uorb::Subscribe;
26//!
27//! let sub = foo::subscribe().unwrap();
28//!
29//! info!("Latest foo: {:?}", sub.get().unwrap());
30//! ```
31//!
32//! ## Publishing
33//!
34//! Publishing is done through the [`Publish` trait](trait.Publish.html),
35//! which is automatically implemented for all messages.
36//!
37//! ```ignore
38//! use px4::uorb::Publish;
39//!
40//! let mut publ = foo::advertise();
41//!
42//! publ.publish(&foo { timestamp: 123, a: 4, b: 5 }).unwrap();
43//! ```
44
45mod c;
46mod publish;
47mod subscribe;
48
49pub use self::c::{Metadata, priority};
50pub use self::publish::{Publisher, Publish};
51pub use self::subscribe::{Subscription, Subscribe};
52
53/// A message which can be published and/or subscribed to.
54///
55/// This trait is automatically implemented for all messages imported using
56/// `#[px4_message]`.
57pub unsafe trait Message {
58 /// Get the metadata of this type of message.
59 fn metadata() -> &'static Metadata;
60}