Skip to main content

mavlink_core/
consts.rs

1//! MAVLink frame constants.
2//!
3//! These constants can be used when allocating buffers or inspecting
4//! MAVLink 1 and MAVLink 2 frame layouts.
5//!
6//! ```
7//! use mavlink_core::consts;
8//!
9//! let v1_buffer = [0_u8; consts::v1::FRAME_SIZE];
10//! let v2_buffer = [0_u8; consts::v2::FRAME_SIZE];
11//!
12//! assert_eq!(v1_buffer.len(), consts::v1::FRAME_SIZE);
13//! assert_eq!(v2_buffer.len(), consts::MAX_FRAME_SIZE);
14//! ```
15
16/// Size of the STX marker.
17pub const STX_SIZE: usize = 1;
18/// Offset of the STX marker.
19pub const STX_OFFSET: usize = 0;
20/// Maximum payload length.
21pub const MAX_PAYLOAD_LEN: usize = 255;
22/// Offset of the payload length field.
23pub const PAYLOAD_LEN_OFFSET: usize = 1;
24/// Size of the checksum field.
25pub const CHECKSUM_SIZE: usize = 2;
26
27/// Maximum MAVLink frame size.
28pub const MAX_FRAME_SIZE: usize = v2::FRAME_SIZE;
29
30/// MAVLink 1 frame constants.
31pub mod v1 {
32    /// Header size, excluding the STX marker.
33    pub const HEADER_SIZE: usize = 5;
34
35    /// Maximum frame size.
36    pub const FRAME_SIZE: usize =
37        super::STX_SIZE + HEADER_SIZE + super::MAX_PAYLOAD_LEN + super::CHECKSUM_SIZE;
38}
39
40/// MAVLink 2 frame constants.
41pub mod v2 {
42    /// Header size, excluding the STX marker.
43    pub const HEADER_SIZE: usize = 9;
44
45    /// Offset of the incompatibility flags field.
46    pub const INCOMPAT_FLAGS_OFFSET: usize = 2;
47
48    /// Signed-frame incompatibility flag.
49    pub const IFLAG_SIGNED: u8 = 0x01;
50
51    /// Incompatibility flags handled by this crate.
52    pub const SUPPORTED_IFLAGS: u8 = IFLAG_SIGNED;
53
54    /// Signature link id size.
55    pub const SIGNATURE_LINK_ID_SIZE: usize = 1;
56
57    /// Signature timestamp size.
58    pub const SIGNATURE_TIMESTAMP_SIZE: usize = 6;
59
60    /// Signature value size.
61    pub const SIGNATURE_VALUE_SIZE: usize = 6;
62
63    /// Total signature trailer size.
64    pub const SIGNATURE_SIZE: usize =
65        SIGNATURE_LINK_ID_SIZE + SIGNATURE_TIMESTAMP_SIZE + SIGNATURE_VALUE_SIZE;
66
67    /// Maximum frame size.
68    pub const FRAME_SIZE: usize = super::STX_SIZE
69        + HEADER_SIZE
70        + super::MAX_PAYLOAD_LEN
71        + super::CHECKSUM_SIZE
72        + SIGNATURE_SIZE;
73}