Skip to content

Commit

Permalink
[ieee802154-sniffer] Remove lazy_static in favor of normal initialisa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
GnomedDev committed Sep 2, 2024
1 parent 16b84c4 commit d63a55b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 58 deletions.
1 change: 0 additions & 1 deletion extras/ieee802154-sniffer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
114 changes: 57 additions & 57 deletions extras/ieee802154-sniffer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
};

use clap::Parser;
use lazy_static::lazy_static;
use pcap_file::{
pcap::{PcapHeader, PcapPacket, PcapWriter},
DataLink,
Expand Down Expand Up @@ -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();

Expand All @@ -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");
Expand Down

0 comments on commit d63a55b

Please sign in to comment.