mavspec_rust_spec/
types.rs

1//! # Tiny types and type aliases
2//!
3//! Type aliases and tiny types (that require a few lines of code) used across the Mavka toolchain.
4
5/// MAVLink message ID regardless of protocol.
6///
7/// * For `MAVLink 1` message ID is a 8-bit unsigned integer.
8/// * For `MAVLink 2` message ID is a 24-bit unsigned integer.
9pub type MessageId = u32;
10
11/// MAVLink extra CRC byte.
12///
13/// # Links
14///
15///  * [CRC_EXTRA calculation](https://mavlink.io/en/guide/serialization.html#crc_extra) in MAVLink docs.
16pub type CrcExtra = u8;
17
18/// Type used to contain `dialect` identifier specified in MAVLink [XML definitions](https://mavlink.io/en/guide/xml_schema.html).
19pub type DialectId = u32;
20
21/// Type used to contain minor dialect `version` specified in MAVLink [XML definitions](https://mavlink.io/en/guide/xml_schema.html).
22///
23/// Dialect version appears in some messages like [HEARTBEAT](https://mavlink.io/en/messages/common.html#HEARTBEAT). In
24/// such cases it is usually not directly set by user.
25pub type DialectVersion = u8;
26
27/// MAVLink protocol version.
28#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
29#[cfg_attr(feature = "specta", derive(specta::Type))]
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31pub enum MavLinkVersion {
32    /// `MAVLink 1` protocol version.
33    V1,
34    /// `MAVLink 2` protocol version.
35    #[default]
36    V2,
37}
38
39/// MAVLink system `ID`.
40///
41/// `ID` of system (vehicle) sending the message.
42pub type SystemId = u8;
43
44/// MAVLink component `ID`.
45///
46/// `ID` of component sending the message.
47pub type ComponentId = u8;
48
49/// MAVLink device `ID`.
50#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
51#[cfg_attr(feature = "specta", derive(specta::Type))]
52#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
53pub struct MavLinkId {
54    /// System `ID`.
55    pub system: SystemId,
56    /// Component `ID`.
57    pub component: ComponentId,
58}
59
60impl MavLinkId {
61    /// Creates a new `ID` from the combination of MAVLink system and component ids.
62    pub fn new(system: SystemId, component: ComponentId) -> Self {
63        Self { system, component }
64    }
65}