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

40 lines
1 KiB
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};
2021-04-12 09:51:44 +00:00
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
use apps as _;
2020-06-09 09:52:27 +00:00
#[entry]
fn main() -> ! {
let board = dk::init().unwrap();
let mut radio = board.radio;
// these are the default settings of the DK's radio
// NOTE if you ran `change-channel` then you may need to update the channel here
radio.set_channel(Channel::_20); // <- must match the Dongle's listening channel
2020-06-09 09:52:27 +00:00
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";
2022-01-07 16:24:21 +00:00
defmt::println!(
2020-06-24 12:57:47 +00:00
"sending: {}",
str::from_utf8(msg).expect("msg is not valid UTF-8 data")
);
packet.copy_from_slice(msg);
2021-03-16 12:26:51 +00:00
radio.send(&mut packet);
2020-06-09 09:52:27 +00:00
dk::exit();
2020-06-09 09:52:27 +00:00
}