Format adsb code
This commit is contained in:
68
adsb/src/main.rs
Normal file
68
adsb/src/main.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
mod device;
|
||||
mod error;
|
||||
mod frame;
|
||||
mod hex;
|
||||
|
||||
use error::Result;
|
||||
use crate::device::RtlSdrDevice;
|
||||
use clap::Parser;
|
||||
use rusb::TransferType;
|
||||
use crate::frame::ADSBFrame;
|
||||
use crate::hex::hex_to_bytes;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about = "An ADS-B Receiver")]
|
||||
struct ReceiverArgs {
|
||||
/// Hex-string to decode
|
||||
#[arg(short = 'd', long)]
|
||||
decode: Option<String>,
|
||||
|
||||
/// Connect to the USB device
|
||||
#[arg(short = 'c', long, action)]
|
||||
connect: bool,
|
||||
|
||||
/// List USB devices
|
||||
#[arg(short = 'l', long, action)]
|
||||
list: bool,
|
||||
|
||||
/// Enable debug logging
|
||||
#[arg(short = 'D', long, action)]
|
||||
debug: bool,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = ReceiverArgs::parse();
|
||||
|
||||
let default_filter = if args.debug {
|
||||
"warn,adsb=debug"
|
||||
} else {
|
||||
"warn,adsb=info"
|
||||
};
|
||||
|
||||
env_logger::init_from_env(env_logger::Env::default().filter_or("RUST_LOG", default_filter));
|
||||
|
||||
// Handle connection
|
||||
if args.connect {
|
||||
log::info!("Connecting to device");
|
||||
let mut device = RtlSdrDevice::open(0x0BDA, 0x2832)?;
|
||||
device.read(TransferType::Bulk)
|
||||
}
|
||||
// List devices
|
||||
else if args.list {
|
||||
RtlSdrDevice::list()
|
||||
}
|
||||
// Handle decode mode
|
||||
else if let Some(mut hex_string) = args.decode {
|
||||
if let Some(stripped) = hex_string.strip_prefix("0x") {
|
||||
hex_string = stripped.to_string();
|
||||
}
|
||||
let buf = hex_to_bytes(&hex_string)?;
|
||||
let frame = ADSBFrame::decode(&buf)?;
|
||||
|
||||
log::info!("{}", frame);
|
||||
Ok(())
|
||||
} else {
|
||||
log::warn!("No connection specified");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user