use heapless::Vec;
use postcard::experimental::max_size::MaxSize;
use serde::{Deserialize, Serialize};
use crate::time::DateTime;
#[derive(Debug, Clone, Serialize, Deserialize, MaxSize)]
#[repr(u8)]
pub enum RxCSIFmt {
Bw20,
HtBw20,
HtBw20Stbc,
SecbBw20,
SecbHtBw20,
SecbHtBw20Stbc,
SecbHtBw40,
SecbHtBw40Stbc,
SecaBw20,
SecaHtBw20,
SecaHtBw20Stbc,
SecaHtBw40,
SecaHtBw40Stbc,
Undefined,
}
#[cfg(not(feature = "esp32c6"))]
#[derive(Debug, Clone, Serialize, Deserialize, MaxSize)]
pub struct CSIDataPacket {
pub mac: [u8; 6],
pub rssi: i32,
pub timestamp: u32,
pub rate: u32,
pub sgi: u32,
pub secondary_channel: u32,
pub channel: u32,
pub bandwidth: u32,
pub antenna: u32,
pub sig_mode: u32,
pub mcs: u32,
pub smoothing: u32,
pub not_sounding: u32,
pub aggregation: u32,
pub stbc: u32,
pub fec_coding: u32,
pub ampdu_cnt: u32,
pub noise_floor: i32,
pub rx_state: u32,
pub sig_len: u32,
pub date_time: Option<DateTime>,
pub sequence_number: u16,
pub data_format: RxCSIFmt,
pub csi_data_len: u16,
pub csi_data: Vec<i8, 612>,
}
#[cfg(not(feature = "esp32c6"))]
impl CSIDataPacket {
pub fn print_csi_w_metadata(self) {
use crate::logging::logging::log_csi;
log_csi(self);
}
pub fn csi_fmt_from_params(&mut self) {
match self.secondary_channel {
0 => {
match self.sig_mode {
0 => self.data_format = RxCSIFmt::Bw20,
1 => {
match self.stbc {
0 => self.data_format = RxCSIFmt::HtBw20,
1 => self.data_format = RxCSIFmt::HtBw20Stbc,
_ => self.data_format = RxCSIFmt::Undefined,
}
}
_ => self.data_format = RxCSIFmt::Undefined,
}
}
1 => {
match self.sig_mode {
0 => self.data_format = RxCSIFmt::SecaBw20,
1 => {
match self.bandwidth {
0 => {
match self.stbc {
0 => self.data_format = RxCSIFmt::SecaHtBw20,
1 => self.data_format = RxCSIFmt::SecaHtBw20Stbc,
_ => self.data_format = RxCSIFmt::Undefined,
}
}
1 => {
match self.stbc {
0 => self.data_format = RxCSIFmt::SecaHtBw40,
1 => self.data_format = RxCSIFmt::SecaHtBw40Stbc,
_ => self.data_format = RxCSIFmt::Undefined,
}
}
_ => self.data_format = RxCSIFmt::Undefined,
}
}
_ => self.data_format = RxCSIFmt::Undefined,
}
}
2 => {
match self.sig_mode {
0 => self.data_format = RxCSIFmt::SecbBw20,
1 => {
match self.bandwidth {
0 => {
match self.stbc {
0 => self.data_format = RxCSIFmt::SecbHtBw20,
1 => self.data_format = RxCSIFmt::SecbHtBw20Stbc,
_ => self.data_format = RxCSIFmt::Undefined,
}
}
1 => {
match self.stbc {
0 => self.data_format = RxCSIFmt::SecbHtBw40,
1 => self.data_format = RxCSIFmt::SecbHtBw40Stbc,
_ => self.data_format = RxCSIFmt::Undefined,
}
}
_ => self.data_format = RxCSIFmt::Undefined,
}
}
_ => self.data_format = RxCSIFmt::Undefined,
}
}
_ => self.data_format = RxCSIFmt::Undefined,
}
}
pub fn mac(&self) -> &[u8; 6] {
&self.mac
}
pub fn rssi(&self) -> i32 {
self.rssi
}
pub fn timestamp(&self) -> u32 {
self.timestamp
}
pub fn rate(&self) -> u32 {
self.rate
}
pub fn sgi(&self) -> u32 {
self.sgi
}
pub fn secondary_channel(&self) -> u32 {
self.secondary_channel
}
pub fn channel(&self) -> u32 {
self.channel
}
pub fn bandwidth(&self) -> u32 {
self.bandwidth
}
pub fn antenna(&self) -> u32 {
self.antenna
}
pub fn sig_mode(&self) -> u32 {
self.sig_mode
}
pub fn mcs(&self) -> u32 {
self.mcs
}
pub fn smoothing(&self) -> u32 {
self.smoothing
}
pub fn not_sounding(&self) -> u32 {
self.not_sounding
}
pub fn aggregation(&self) -> u32 {
self.aggregation
}
pub fn stbc(&self) -> u32 {
self.stbc
}
pub fn fec_coding(&self) -> u32 {
self.fec_coding
}
pub fn ampdu_cnt(&self) -> u32 {
self.ampdu_cnt
}
pub fn noise_floor(&self) -> i32 {
self.noise_floor
}
pub fn rx_state(&self) -> u32 {
self.rx_state
}
pub fn sig_len(&self) -> u32 {
self.sig_len
}
pub fn date_time(&self) -> Option<&DateTime> {
self.date_time.as_ref()
}
pub fn sequence_number(&self) -> u16 {
self.sequence_number
}
pub fn data_format(&self) -> RxCSIFmt {
self.data_format.clone()
}
pub fn csi_data_len(&self) -> u16 {
self.csi_data_len
}
pub fn csi_data(&self) -> &[i8] {
self.csi_data.as_slice()
}
}
#[cfg(feature = "esp32c6")]
#[derive(Debug, Clone, Serialize, Deserialize, MaxSize)]
pub struct CSIDataPacket {
pub mac: [u8; 6],
pub rssi: i32,
pub timestamp: u32,
pub rate: u32,
pub noise_floor: i32,
pub sig_len: u32,
pub rx_state: u32,
pub dump_len: u32,
pub he_sigb_len: u32,
pub cur_single_mpdu: u32,
pub cur_bb_format: u32,
pub rx_channel_estimate_info_vld: u32,
pub rx_channel_estimate_len: u32,
pub second: u32,
pub channel: u32,
pub is_group: u32,
pub rxend_state: u32,
pub rxmatch3: u32,
pub rxmatch2: u32,
pub rxmatch1: u32,
pub rxmatch0: u32,
pub date_time: Option<DateTime>,
pub sequence_number: u16,
pub csi_data_len: u16,
pub data_format: RxCSIFmt,
pub csi_data: Vec<i8, 612>,
}
#[cfg(feature = "esp32c6")]
impl CSIDataPacket {
pub fn print_csi_w_metadata(self) {
use crate::logging::logging::log_csi;
log_csi(self);
}
pub fn csi_fmt_from_params(&mut self) {
self.data_format = RxCSIFmt::Undefined;
}
pub fn mac(&self) -> &[u8; 6] {
&self.mac
}
pub fn rssi(&self) -> i32 {
self.rssi
}
pub fn timestamp(&self) -> u32 {
self.timestamp
}
pub fn rate(&self) -> u32 {
self.rate
}
pub fn noise_floor(&self) -> i32 {
self.noise_floor
}
pub fn sig_len(&self) -> u32 {
self.sig_len
}
pub fn rx_state(&self) -> u32 {
self.rx_state
}
pub fn dump_len(&self) -> u32 {
self.dump_len
}
pub fn he_sigb_len(&self) -> u32 {
self.he_sigb_len
}
pub fn cur_single_mpdu(&self) -> u32 {
self.cur_single_mpdu
}
pub fn cur_bb_format(&self) -> u32 {
self.cur_bb_format
}
pub fn rx_channel_estimate_info_vld(&self) -> u32 {
self.rx_channel_estimate_info_vld
}
pub fn rx_channel_estimate_len(&self) -> u32 {
self.rx_channel_estimate_len
}
pub fn second(&self) -> u32 {
self.second
}
pub fn channel(&self) -> u32 {
self.channel
}
pub fn is_group(&self) -> u32 {
self.is_group
}
pub fn rxend_state(&self) -> u32 {
self.rxend_state
}
pub fn rxmatch3(&self) -> u32 {
self.rxmatch3
}
pub fn rxmatch2(&self) -> u32 {
self.rxmatch2
}
pub fn rxmatch1(&self) -> u32 {
self.rxmatch1
}
pub fn rxmatch0(&self) -> u32 {
self.rxmatch0
}
pub fn csi_data(&self) -> &[i8] {
self.csi_data.as_slice()
}
pub fn csi_data_len(&self) -> u16 {
self.csi_data_len
}
}