2020-01-01 19:32:35 +00:00
|
|
|
use rn2903::{bytes_to_string, Rn2903};
|
2019-12-31 22:51:30 +00:00
|
|
|
use std::env::args;
|
|
|
|
use std::process::exit;
|
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args: Vec<_> = args().collect();
|
|
|
|
if args.len() <= 1 {
|
|
|
|
eprintln!("rn2903_lora_packet_rx <serial port>");
|
|
|
|
eprintln!("\tRecieve LoRa packets and print their corresponding hex values.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut txvr = Rn2903::new_at(&args[1]).expect("Could not open device. Error");
|
|
|
|
println!(
|
|
|
|
"Successfully connected. Version: {}",
|
|
|
|
txvr.system_version()
|
|
|
|
.expect("Could not read from device. Error:")
|
|
|
|
);
|
|
|
|
|
|
|
|
txvr.mac_pause().unwrap();
|
|
|
|
txvr.transact(b"sys set pindig GPIO10 0").unwrap();
|
|
|
|
loop {
|
2020-01-01 19:32:35 +00:00
|
|
|
if let Some(packet) = txvr.radio_rx(65535).unwrap() {
|
|
|
|
println!("{:?}", packet);
|
|
|
|
txvr.transact(b"sys set pindig GPIO10 1").unwrap();
|
|
|
|
thread::sleep(Duration::from_millis(100));
|
|
|
|
txvr.transact(b"sys set pindig GPIO10 0").unwrap();
|
|
|
|
}
|
2019-12-31 22:51:30 +00:00
|
|
|
}
|
|
|
|
}
|