use heapless::Vec as HeaplessVec;
use crate::interfaces::{InterfaceId, InterfaceKind};
pub const ESP_NOW_V2_AIR_MTU: usize = 1_470;
const CHANNEL_TAG: &[u8] = b"esp-now";
pub const CHANNEL_TAG_CAP: usize = CHANNEL_TAG.len();
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Channel(u8);
impl Channel {
pub const DEFAULT: Self = Self(6);
#[must_use]
pub const fn new(channel: u8) -> Option<Self> {
if matches!(channel, 1..=13) {
Some(Self(channel))
} else {
None
}
}
#[must_use]
pub const fn as_u8(self) -> u8 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChannelPolicy {
FollowStation,
Fixed(Channel),
}
#[must_use]
pub fn channel_tag() -> HeaplessVec<u8, CHANNEL_TAG_CAP> {
let mut tag = HeaplessVec::new();
let _ = tag.extend_from_slice(CHANNEL_TAG);
tag
}
#[must_use]
pub fn interface_id() -> InterfaceId {
InterfaceId::from_channel_tag(InterfaceKind::EspNow, CHANNEL_TAG)
}