embedded-trainings-2020/beginner/apps/src/bin/radio-send.rs

38 lines
810 B
Rust
Raw Normal View History

2020-06-09 09:52:27 +00:00
#![deny(unused_must_use)]
#![no_main]
#![no_std]
2020-06-24 12:57:47 +00:00
use core::str;
2020-06-09 09:52:27 +00:00
use cortex_m_rt::entry;
2020-06-24 12:57:47 +00:00
use dk::ieee802154::{Channel, Packet, TxPower};
2020-06-09 09:52:27 +00:00
use panic_log as _; // the panicking behavior
#[entry]
fn main() -> ! {
let board = dk::init().unwrap();
let mut radio = board.radio;
// these are the initial settings
radio.set_channel(Channel::_20);
radio.set_txpower(TxPower::Pos8dBm);
let mut packet = Packet::new();
2020-06-24 12:57:47 +00:00
// these three are equivalent
let msg: &[u8; 5] = &[72, 101, 108, 108, 111];
// let msg: &[u8; 5] = &[b'H', b'e', b'l', b'l', b'o'];
// let msg: &[u8; 5] = b"Hello";
log::info!(
"sending: {}",
str::from_utf8(msg).expect("msg is not valid UTF-8 data")
);
packet.copy_from_slice(msg);
radio.send(&packet);
2020-06-09 09:52:27 +00:00
dk::exit();
2020-06-09 09:52:27 +00:00
}