use can_socket::CanSocket;
#[derive(clap::Parser)]
struct Options {
#[clap(long, short)]
interface: String,
#[clap(long, short)]
count: usize,
}
fn main() {
if let Err(()) = do_main(clap::Parser::parse()) {
std::process::exit(1);
}
}
fn do_main(options: Options) -> Result<(), ()> {
let socket = CanSocket::bind(&options.interface)
.map_err(|e| eprintln!("Failed to create CAN socket for interface {}: {e}", options.interface))?;
for i in 0.. {
if options.count != 0 && i == options.count {
break;
}
eprintln!("Reading frame {i}...");
let frame = socket.recv()
.map_err(|e| eprintln!("Failed to receive frame on interface {}: {e}", options.interface))?;
println!("{:#?}", frame);
eprintln!()
}
Ok(())
}