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/// Default capacity used by buffered MAVLink readers in standard environments.
31pub const DEFAULT_READ_BUFFER_CAPACITY: usize = 16 * 1024;
32
33/// MAVLink 1 frame constants.
34pub mod v1 {
35 /// Header size, excluding the STX marker.
36 pub const HEADER_SIZE: usize = 5;
37
38 /// Maximum frame size.
39 pub const FRAME_SIZE: usize =
40 super::STX_SIZE + HEADER_SIZE + super::MAX_PAYLOAD_LEN + super::CHECKSUM_SIZE;
41}
42
43/// MAVLink 2 frame constants.
44pub mod v2 {
45 /// Minimum header size, excluding the STX marker.
46 pub const MIN_HEADER_SIZE: usize = 9;
47
48 /// Additional header size if `IFLAG_SYSID32` is set.
49 pub const SYSID32_EXTRA_HEADER_SIZE: usize = 3;
50
51 /// Maximum header size, excluding the STX marker.
52 pub const MAX_HEADER_SIZE: usize = MIN_HEADER_SIZE + SYSID32_EXTRA_HEADER_SIZE;
53
54 /// Offset of the incompatibility flags field.
55 pub const INCOMPAT_FLAGS_OFFSET: usize = 2;
56
57 /// Signed-frame incompatibility flag.
58 pub const IFLAG_SIGNED: u8 = 0x01;
59
60 /// 32bit system ID incompatibility flag.
61 pub const IFLAG_SYSID32: u8 = 0x02;
62
63 /// Incompatibility flags handled by this crate.
64 pub const SUPPORTED_IFLAGS: u8 = IFLAG_SIGNED | IFLAG_SYSID32;
65
66 /// Signature link id size.
67 pub const SIGNATURE_LINK_ID_SIZE: usize = 1;
68
69 /// Signature timestamp size.
70 pub const SIGNATURE_TIMESTAMP_SIZE: usize = 6;
71
72 /// Signature value size.
73 pub const SIGNATURE_VALUE_SIZE: usize = 6;
74
75 /// Total signature trailer size.
76 pub const SIGNATURE_SIZE: usize =
77 SIGNATURE_LINK_ID_SIZE + SIGNATURE_TIMESTAMP_SIZE + SIGNATURE_VALUE_SIZE;
78
79 /// Maximum frame size.
80 pub const FRAME_SIZE: usize = super::STX_SIZE
81 + MAX_HEADER_SIZE
82 + super::MAX_PAYLOAD_LEN
83 + super::CHECKSUM_SIZE
84 + SIGNATURE_SIZE;
85}