2020-06-09 09:52:27 +00:00
|
|
|
#![deny(unused_must_use)]
|
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
use core::str;
|
|
|
|
|
|
|
|
use cortex_m_rt::entry;
|
2020-06-17 16:37:53 +00:00
|
|
|
use dk::ieee802154::{Channel, Packet};
|
2020-06-09 09:52:27 +00:00
|
|
|
use panic_log as _; // the panicking behavior
|
|
|
|
|
2020-06-22 17:11:42 +00:00
|
|
|
const TEN_MS: u32 = 10_000;
|
|
|
|
|
2020-06-09 09:52:27 +00:00
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
let board = dk::init().unwrap();
|
|
|
|
let mut radio = board.radio;
|
2020-06-22 17:11:42 +00:00
|
|
|
let mut timer = board.timer;
|
2020-06-09 09:52:27 +00:00
|
|
|
|
2020-06-17 16:37:53 +00:00
|
|
|
// puzzle.hex uses channel 25
|
|
|
|
radio.set_channel(Channel::_25);
|
|
|
|
|
2020-06-09 09:52:27 +00:00
|
|
|
let mut packet = Packet::new();
|
|
|
|
|
|
|
|
// try these
|
2020-06-22 17:11:42 +00:00
|
|
|
let msg = b"";
|
|
|
|
// let msg = b"A";
|
|
|
|
// let msg = b"Hello?";
|
|
|
|
|
|
|
|
packet.copy_from_slice(msg);
|
|
|
|
log::info!(
|
|
|
|
"sending: {}",
|
|
|
|
str::from_utf8(msg).expect("msg was not valid UTF-8 data")
|
|
|
|
);
|
2020-06-09 09:52:27 +00:00
|
|
|
|
|
|
|
radio.send(&packet);
|
2020-06-22 17:11:42 +00:00
|
|
|
if radio.recv_timeout(&mut packet, &mut timer, TEN_MS).is_ok() {
|
|
|
|
log::info!(
|
|
|
|
"received: {}",
|
|
|
|
str::from_utf8(&packet).expect("response was not valid UTF-8 data")
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
log::error!("no response or response packet was corrupted");
|
2020-06-09 09:52:27 +00:00
|
|
|
}
|
|
|
|
dk::exit()
|
|
|
|
}
|