use esp_radio::esp_now::WifiPhyRate;
use esp_radio::wifi::SecondaryChannel;
pub struct EspNowConfig {
phy_rate: WifiPhyRate,
pub(crate) channel: u8,
peer_mac: Option<[u8; 6]>,
secondary_channel: Option<SecondaryChannel>,
force_phy: bool,
he20: bool,
session: crate::SessionRole,
reporting: crate::Reporting,
}
impl Default for EspNowConfig {
fn default() -> Self {
Self {
phy_rate: WifiPhyRate::RateMcs0Lgi,
channel: 1,
peer_mac: None,
secondary_channel: None,
force_phy: false,
he20: false,
session: crate::SessionRole::Initiator,
reporting: crate::Reporting::HOST,
}
}
}
impl EspNowConfig {
pub fn fast_default() -> Self {
Self::default().with_phy_rate(WifiPhyRate::RateMcs7Lgi)
}
pub fn with_channel(mut self, channel: u8) -> Self {
self.channel = channel;
self
}
pub fn with_phy_rate(mut self, phy_rate: WifiPhyRate) -> Self {
self.phy_rate = phy_rate;
self.force_phy = true;
self
}
pub fn with_peer_mac(mut self, peer_mac: [u8; 6]) -> Self {
self.peer_mac = Some(peer_mac);
self
}
pub fn channel(&self) -> u8 {
self.channel
}
pub fn phy_rate(&self) -> &WifiPhyRate {
&self.phy_rate
}
pub fn peer_mac(&self) -> Option<[u8; 6]> {
self.peer_mac
}
pub fn with_ht40(mut self, secondary: SecondaryChannel) -> Self {
self.secondary_channel = Some(secondary);
self.force_phy = true;
self
}
#[cfg(any(feature = "esp32c5", feature = "esp32c6"))]
pub fn with_he20(mut self) -> Self {
self.he20 = true;
self.secondary_channel = None;
self.force_phy = true;
self
}
pub fn he20(&self) -> bool {
self.he20
}
pub fn peer_phy(&self) -> crate::espnow_phy::PeerPhy {
crate::espnow_phy::PeerPhy {
rate: self.phy_rate,
secondary: self.secondary_channel,
he20: self.he20,
}
}
pub fn secondary_channel(&self) -> Option<SecondaryChannel> {
self.secondary_channel
}
pub fn force_phy(&self) -> bool {
self.force_phy
}
pub fn session(mut self, role: crate::SessionRole) -> Self {
self.session = role;
self
}
pub fn reporting(mut self, reporting: crate::Reporting) -> Self {
self.reporting = reporting;
self
}
pub fn session_role(&self) -> crate::SessionRole {
self.session
}
pub const fn sensing_role(&self) -> crate::SensingRole {
crate::SensingRole::TransmitterReceiver
}
pub fn get_reporting(&self) -> crate::Reporting {
self.reporting
}
}