mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-25 23:38:06 +00:00
Merge pull request #6 from ferrous-systems/simplify_puzzle
Simplify puzzle
This commit is contained in:
commit
806c4f09a0
2 changed files with 13 additions and 12 deletions
|
@ -369,6 +369,8 @@ The Dongle will respond differently depending on the length of the incoming pack
|
|||
- On one-byte sized packets it will respond with the *direct* mapping from a *plaintext* letter -- the letter contained in the packet -- to the *ciphertext* letter.
|
||||
- On packets of any other length the Dongle will respond with the string `correct` if it received the decrypted string, otherwise it will respond with the `incorrect` string.
|
||||
|
||||
The Dongle will always respond with packets that are valid UTF-8.
|
||||
|
||||
Our suggestion is to use a dictionary / map. `std::collections::HashMap` is not available in `no_std` code (without linking to a global allocator) but you can use one of the maps in the [`heapless`] crate. To make this crate available in your application get the latest version from [crates.io] and add it to the `beginner/apps/Cargo.toml` file, for example:
|
||||
|
||||
[`heapless`]: https://docs.rs/heapless
|
||||
|
|
|
@ -23,12 +23,11 @@ fn main() -> ! {
|
|||
packet.copy_from_slice(msg.as_bytes());
|
||||
radio.send(&packet);
|
||||
log::info!("sent: {:?}", msg);
|
||||
radio.recv(&mut packet).ok();
|
||||
if let Ok(s) = str::from_utf8(&*packet) {
|
||||
log::info!("received: {}", s);
|
||||
} else {
|
||||
log::info!("received: {:?}", &*packet);
|
||||
// listen for a response packet and ensure it is not corrupted
|
||||
if radio.recv(&mut packet).is_ok() {
|
||||
// convert the packet contents to str or print error message on failure
|
||||
let response = str::from_utf8(&*packet).expect("could not convert response to str");
|
||||
log::info!("received: {}", response);
|
||||
}
|
||||
|
||||
dk::exit()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue