diff --git a/extras/ieee802154-sniffer/Cargo.toml b/extras/ieee802154-sniffer/Cargo.toml index a15f339ea4d..c590be02960 100644 --- a/extras/ieee802154-sniffer/Cargo.toml +++ b/extras/ieee802154-sniffer/Cargo.toml @@ -8,4 +8,3 @@ r-extcap = "0.2.4" pcap-file = "2.0.0" serialport = "4.2.0" clap = { version = "4.1.7", features = ["derive"] } -lazy_static = "1.4.0" diff --git a/extras/ieee802154-sniffer/src/main.rs b/extras/ieee802154-sniffer/src/main.rs index ccf4e85b800..097ad184302 100644 --- a/extras/ieee802154-sniffer/src/main.rs +++ b/extras/ieee802154-sniffer/src/main.rs @@ -4,7 +4,6 @@ use std::{ }; use clap::Parser; -use lazy_static::lazy_static; use pcap_file::{ pcap::{PcapHeader, PcapPacket, PcapWriter}, DataLink, @@ -35,59 +34,6 @@ fn config_option_value(value: &'static str) -> ConfigOptionValue { .build() } -lazy_static! { - static ref METADATA: Metadata = Metadata { - help_url: "http://github.com/esp-rs".into(), - display_description: "esp-ieee802154".into(), - ..r_extcap::cargo_metadata!() - }; - static ref WIFI_CAPTURE_INTERFACE: Interface = Interface { - value: "802.15.4".into(), - display: "esp-ieee802154 Sniffer".into(), - dlt: Dlt { - data_link_type: DataLink::USER0, - name: "USER0".into(), - display: "IEEE802.15.4".into(), - }, - }; - static ref CONFIG_SERIALPORT: StringConfig = StringConfig::builder() - .config_number(1) - .call("serialport") - .display("Serialport") - .tooltip("Serialport to connect to") - .required(false) - .placeholder("") - .build(); - static ref CONFIG_CHANNEL: SelectorConfig = SelectorConfig::builder() - .config_number(3) - .call("channel") - .display("Channel") - .tooltip("Channel Selector") - .default_options([ - ConfigOptionValue::builder() - .value("11") - .display("11") - .default(true) - .build(), - config_option_value("12"), - config_option_value("13"), - config_option_value("14"), - config_option_value("15"), - config_option_value("16"), - config_option_value("17"), - config_option_value("18"), - config_option_value("19"), - config_option_value("20"), - config_option_value("21"), - config_option_value("22"), - config_option_value("23"), - config_option_value("24"), - config_option_value("25"), - config_option_value("26"), - ]) - .build(); -} - fn main() { let args = AppArgs::parse(); @@ -97,17 +43,71 @@ fn main() { } } + let wifi_capture_interface = Interface { + value: "802.15.4".into(), + display: "esp-ieee802154 Sniffer".into(), + dlt: Dlt { + data_link_type: DataLink::USER0, + name: "USER0".into(), + display: "IEEE802.15.4".into(), + }, + }; + match args.extcap.run().unwrap() { ExtcapStep::Interfaces(interfaces_step) => { - interfaces_step.list_interfaces(&METADATA, &[&*WIFI_CAPTURE_INTERFACE], &[]); + let metadata = Metadata { + help_url: "http://github.com/esp-rs".into(), + display_description: "esp-ieee802154".into(), + ..r_extcap::cargo_metadata!() + }; + + interfaces_step.list_interfaces(&metadata, &[&wifi_capture_interface], &[]); } ExtcapStep::Dlts(dlts_step) => { dlts_step - .print_from_interfaces(&[&*WIFI_CAPTURE_INTERFACE]) + .print_from_interfaces(&[&wifi_capture_interface]) .unwrap(); } ExtcapStep::Config(config_step) => { - config_step.list_configs(&[&*CONFIG_SERIALPORT, &*CONFIG_CHANNEL]) + let config_serialport = StringConfig::builder() + .config_number(1) + .call("serialport") + .display("Serialport") + .tooltip("Serialport to connect to") + .required(false) + .placeholder("") + .build(); + + let config_channel = SelectorConfig::builder() + .config_number(3) + .call("channel") + .display("Channel") + .tooltip("Channel Selector") + .default_options([ + ConfigOptionValue::builder() + .value("11") + .display("11") + .default(true) + .build(), + config_option_value("12"), + config_option_value("13"), + config_option_value("14"), + config_option_value("15"), + config_option_value("16"), + config_option_value("17"), + config_option_value("18"), + config_option_value("19"), + config_option_value("20"), + config_option_value("21"), + config_option_value("22"), + config_option_value("23"), + config_option_value("24"), + config_option_value("25"), + config_option_value("26"), + ]) + .build(); + + config_step.list_configs(&[&config_serialport, &config_channel]) } ExtcapStep::ReloadConfig(_reload_config_step) => { panic!("Unsupported operation");