//! Template project for Rust on ESP32-C3 (`no_std`) based on [`esp-hal`](https://github.com/esp-rs/esp-hal)
//!
//! Useful resources:
//! - [The Rust on ESP Book](https://docs.esp-rs.org/book/)
//! - [Embedded Rust (no_std) on Espressif](https://docs.esp-rs.org/no_std-training/)
//! - [Matrix channel](https://matrix.to/#/#esp-rs:matrix.org)

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{clock::CpuClock, delay::Delay, main};
use log::info;

#[main]
fn main() -> ! {
   esp_println::logger::init_logger_from_env();
    
    let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
    let peripherals = esp_hal::init(config);
    
    esp_alloc::heap_allocator!(size: 72 * 1024);

    let timg0 = TimerGroup::new(peripherals.TIMG0);
    let esp_wifi_ctrl = init(
        timg0.timer0,
        Rng::new(peripherals.RNG),
        peripherals.RADIO_CLK,
    )
    .unwrap();

    // We must initialize some kind of interface and start it.
    let (mut controller, _interfaces) =
        esp_wifi::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap();

    controller.set_mode(wifi::WifiMode::Sta).unwrap();
    controller.start().unwrap();

    let mut sniffer = controller.take_sniffer().unwrap();
    sniffer.set_promiscuous_mode(true).unwrap();

    sniffer.set_receive_cb(|packet| {
        let _ = match_frames! {
            packet.data,
            _beacon = BeaconFrame => {
                // 在此处处理 ASTM Vendor Specific IE
                process_astm_data(packet.data, packet.data.len());
            }
        };
    });
    
    unsafe {
        esp_wifi_set_channel(6, 0);
    }

    // 保持任务循环持续
    loop {
        Timer::after(Duration::from_secs(10)).await;  // 这里可以设置适当的间隔来处理任务
    }
}

Loading
esp32-c3-devkitm-1