use alloc::vec::Vec;
use ieee802154::mac::{FrameContent, Header};
pub(crate) const FRAME_SIZE: usize = 129;
pub(crate) const FRAME_VERSION_1: u8 = 0x10; pub(crate) const FRAME_VERSION_2: u8 = 0x20;
const FRAME_AR_OFFSET: usize = 1;
const FRAME_AR_BIT: u8 = 0x20;
const FRAME_VERSION_OFFSET: usize = 2;
const FRAME_VERSION_MASK: u8 = 0x30;
#[derive(Debug, Clone, PartialEq, Eq)]
#[instability::unstable]
pub struct Frame {
pub header: Header,
pub content: FrameContent,
pub payload: Vec<u8>,
pub footer: [u8; 2],
}
#[cfg(feature = "defmt")]
impl defmt::Format for Frame {
fn format(&self, f: defmt::Formatter<'_>) {
defmt::write!(
f,
"Frame {{ header: {}, content: {}, payload: {:?}, footer: {:?} }}",
self.header,
self.content,
self.payload.as_slice(),
self.footer
);
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[instability::unstable]
pub struct ReceivedFrame {
pub frame: Frame,
pub channel: u8,
pub rssi: i8,
pub lqi: u8,
}
pub(crate) fn frame_is_ack_required(frame: &[u8]) -> bool {
if frame.len() <= FRAME_AR_OFFSET {
return false;
}
(frame[FRAME_AR_OFFSET] & FRAME_AR_BIT) != 0
}
pub(crate) fn frame_get_version(frame: &[u8]) -> u8 {
if frame.len() <= FRAME_VERSION_OFFSET {
return 0;
}
frame[FRAME_VERSION_OFFSET] & FRAME_VERSION_MASK
}