A Rusty interface for the RN2903 LoRa module's serial protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5KB

  1. use rn2903::{NvmAddress, Rn2903};
  2. use std::env::args;
  3. use std::process::exit;
  4. use std::thread;
  5. use std::time::Duration;
  6. fn main() {
  7. let args: Vec<_> = args().collect();
  8. if args.len() <= 1 {
  9. eprintln!("rn2903_nvm_set_get <serial port>");
  10. eprintln!("\tGet, modify, check, and restore the contents of NVM::0x300.");
  11. exit(1);
  12. }
  13. let mut txvr = Rn2903::new_at(&args[1]).expect("Could not open device. Error");
  14. println!(
  15. "Successfully connected. Version: {}",
  16. txvr.system_version()
  17. .expect("Could not read from device. Error:")
  18. );
  19. txvr.system_module_reset().unwrap();
  20. txvr.transact(b"mac pause").unwrap();
  21. let addr = NvmAddress::new(0x300);
  22. txvr.transact(b"sys set pindig GPIO10 1").unwrap();
  23. let prev = txvr.system_get_nvm(addr).unwrap();
  24. println!("Previous value: {:#x}", prev);
  25. txvr.transact(b"sys set pindig GPIO10 0").unwrap();
  26. txvr.transact(b"sys set pindig GPIO11 1").unwrap();
  27. txvr.system_set_nvm(addr, 0xAB).unwrap();
  28. println!("Wrote new value");
  29. txvr.transact(b"sys set pindig GPIO11 0").unwrap();
  30. txvr.transact(b"sys set pindig GPIO10 1").unwrap();
  31. let new = txvr.system_get_nvm(addr).unwrap();
  32. println!("New value: {:#x}", new);
  33. txvr.transact(b"sys set pindig GPIO10 0").unwrap();
  34. txvr.transact(b"sys set pindig GPIO11 1").unwrap();
  35. txvr.system_set_nvm(addr, prev).unwrap();
  36. println!("Restored old value");
  37. txvr.transact(b"sys set pindig GPIO11 0").unwrap();
  38. }