mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-24 06:48:11 +00:00
radio-puzzle.rs: simplify error handling, add explanatory comments
This commit is contained in:
parent
6902a5e81b
commit
e8c5acfe9a
1 changed files with 5 additions and 6 deletions
|
@ -23,12 +23,11 @@ fn main() -> ! {
|
||||||
packet.copy_from_slice(msg.as_bytes());
|
packet.copy_from_slice(msg.as_bytes());
|
||||||
radio.send(&packet);
|
radio.send(&packet);
|
||||||
log::info!("sent: {:?}", msg);
|
log::info!("sent: {:?}", msg);
|
||||||
radio.recv(&mut packet).ok();
|
// listen for a response packet and ensure it is not corrupted
|
||||||
if let Ok(s) = str::from_utf8(&*packet) {
|
if radio.recv(&mut packet).is_ok() {
|
||||||
log::info!("received: {}", s);
|
// convert the packet contents to str or print error message on failure
|
||||||
} else {
|
let response = str::from_utf8(&*packet).expect("could not convert response to str");
|
||||||
log::info!("received: {:?}", &*packet);
|
log::info!("received: {}", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
dk::exit()
|
dk::exit()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue