feat(f722): add usb mavlink transport

This commit is contained in:
Onur Özkan committed 2026-09-06 23:14:00 +03:00
1 parent 7dc3ccb619
commit 604a7aba86
18 files changed
+1087 -208

No files matched your search

+22 -8
View File
@@ -5,7 +5,7 @@ use crate::{MavlinkFrame, decode_message, generated::kaptan::MavMessage};
/// An unsigned MAVLink 2 frame whose ID and CRC match the Kaptan dialect.
///
/// The payload is deliberately not decoded during byte admission. Consumers
/// decode it once after taking the frame from the bounded receive queue.
/// decode it once at protocol dispatch.
#[repr(transparent)]
pub struct IntegrityCheckedFrame(MavlinkFrame);
@@ -32,14 +32,20 @@ impl IntegrityCheckedFrame {
}
}
struct IntegrityFramer {
/// Incremental, unbuffered MAVLink 2 framing with Kaptan ID and CRC validation.
///
/// Consumers that can pause byte admission can process each returned frame
/// directly. Interrupt-driven byte streams can use [`IntegrityMavlinkReceiver`]
/// to queue complete frames instead. Accepted frames remain unauthenticated.
pub struct IntegrityMavlinkFramer {
frame: MavlinkFrame,
received: usize,
expected: usize,
}
impl IntegrityFramer {
const fn new() -> Self {
impl IntegrityMavlinkFramer {
/// Creates an empty framer.
pub const fn new() -> Self {
Self {
frame: MavlinkFrame::new(),
received: 0,
@@ -47,7 +53,8 @@ impl IntegrityFramer {
}
}
fn receive_byte(&mut self, byte: u8) -> Option<IntegrityCheckedFrame> {
/// Consumes one byte, returning a complete integrity-checked frame if ready.
pub fn receive_byte(&mut self, byte: u8) -> Option<IntegrityCheckedFrame> {
if self.received == 0 {
if byte == 0xfd {
self.frame.as_mut_slice()[0] = byte;
@@ -81,20 +88,27 @@ impl IntegrityFramer {
IntegrityCheckedFrame::try_new(frame)
}
fn reset(&mut self) {
/// Discards a partial frame after a stream discontinuity.
pub fn reset(&mut self) {
self.frame = MavlinkFrame::new();
self.received = 0;
self.expected = 0;
}
}
impl Default for IntegrityMavlinkFramer {
fn default() -> Self {
Self::new()
}
}
/// Bounded integrity-only MAVLink 2 receiver.
///
/// It rejects signed, incompatible, corrupt, and MAVLink 1 frames, but an
/// accepted frame is still unauthenticated. The composition decides whether
/// and how a received request may be admitted.
pub struct IntegrityMavlinkReceiver<const N: usize> {
framer: IntegrityFramer,
framer: IntegrityMavlinkFramer,
frames: [Option<IntegrityCheckedFrame>; N],
front: usize,
length: usize,
@@ -105,7 +119,7 @@ impl<const N: usize> IntegrityMavlinkReceiver<N> {
pub const fn new() -> Self {
assert!(N != 0, "integrity receiver capacity must be nonzero");
Self {
framer: IntegrityFramer::new(),
framer: IntegrityMavlinkFramer::new(),
frames: [const { None }; N],
front: 0,
length: 0,