Expand description
Simulated SX126x and SX127x chips, for running a radio program with no radio attached.
A Chip answers its driver over SPI the way the part does. It takes the commands or
the register writes that tune it, puts a frame on the air when it is told to transmit,
and hands a frame over when one arrives while it listens. The program on the other side
says what arrives, with Chip::hear, and reads back what the driver tuned the chip to
and what it sent, with Chip::tuning and Chip::sent, so a program’s radio settings
are checked against what the chip was actually told rather than against the program’s
own intent.
Nothing is timed. A transmission is done as soon as it starts, a reception with a timeout
ends at once when nothing is waiting on the air, and one without a timeout listens until
a frame arrives. The signal levels of a frame are the ones given to Chip::hear,
rounded to the half or whole decibel the chip reports them in.
§Examples
use pamoja_lora::budget::Decibels;
use pamoja_lora::region::Region;
use pamoja_radios::radio::{RadioConfig, Reception};
use pamoja_radios::sim::Chip;
use pamoja_radios::sx126x::config::PowerAmplifier;
use pamoja_radios::sx126x::Board;
// An SX1262 on the bench, and the driver wired to it.
let chip = Chip::sx126x(Board::new(PowerAmplifier::HighPower));
let mut radio = chip.radio();
radio.init()?;
// Tuned from the plan's DR3 at 868.1 MHz, a reading goes out.
let link = Region::Eu868.plan().link_settings(3).expect("DR3 is a LoRa data rate");
radio.configure(RadioConfig::new(868_100_000, link, 14))?;
radio.transmit(b"21.5")?;
let sent = &chip.sent()[0];
assert_eq!(sent.tuning.frequency_hz, 868_100_000);
assert_eq!(sent.tuning.link.spreading_factor(), 9);
assert_eq!(sent.payload, b"21.5");
// An answer arrives 2.5 dB under the noise.
chip.hear(b"ok", Decibels::from_db(-109), Decibels::from_tenths(-25));
let mut buffer = [0u8; 255];
let Reception::Frame { len, levels } = radio.receive(&mut buffer, 1_000_000)? else {
panic!("a frame was waiting");
};
assert_eq!(&buffer[..len], b"ok");
assert_eq!(levels.snr_db, Decibels::from_tenths(-25));Structs§
- Chip
- A simulated SX126x or SX127x, shared between its driver and the program watching it.
- Chip
Delay - The delay a simulated chip’s driver waits with, which passes no time.
- ChipPin
- A line of a simulated chip: BUSY, which never holds the driver up, and NRESET, which resets the chip when it is pulled low and released.
- ChipSpi
- The SPI device of a simulated chip.
- Sent
- A frame a simulated chip put on the air.
- Tuning
- What a chip is tuned to: where it sends and listens, how, and how hard.
Type Aliases§
- SimRadio
- A radio driver wired to a simulated chip.