Struct crazyradio::Crazyradio
source · pub struct Crazyradio { /* private fields */ }
Expand description
Represents a Crazyradio
Holds the USB connection to a Crazyradio dongle. The connection is closed when this object goes out of scope.Crazyradio
Usage example:
use crazyradio::{Crazyradio, Error, Channel};
fn main() -> Result<(), Error> {
let mut cr = Crazyradio::open_first()?; // Open the first detected dongle
// Set the radio channel
cr.set_channel(Channel::from_number(42).unwrap());
// Send a `null` packet
let mut ack_data = [0u8; 32];
let ack = cr.send_packet(&[0xff], &mut ack_data)?;
println!("Ack received: {}, length: {}, data: {:?}", ack.received,
ack.length,
&ack_data[..ack.length]);
Ok(())
}
Implementations§
source§impl Crazyradio
impl Crazyradio
sourcepub fn open_first() -> Result<Self, Error>
pub fn open_first() -> Result<Self, Error>
Open the first Crazyradio detected and returns a Crazyradio object.
The dongle is reset to boot values before being returned
sourcepub fn open_nth(nth: usize) -> Result<Self, Error>
pub fn open_nth(nth: usize) -> Result<Self, Error>
Open the nth Crazyradio detected and returns a Crazyradio object.
Radios are ordered appearance in the USB device list. This order is platform-specific.
The dongle is reset to boot values before being returned
sourcepub fn open_by_serial(serial: &str) -> Result<Self, Error>
pub fn open_by_serial(serial: &str) -> Result<Self, Error>
Open a Crazyradio by specifying its serial number
Example:
use crazyradio::Crazyradio;
let mut cr = Crazyradio::open_by_serial("FD61E54B7A")?;
sourcepub fn list_serials() -> Result<Vec<String>, Error>
pub fn list_serials() -> Result<Vec<String>, Error>
Return an ordered list of serial numbers of connected Crazyradios
The order of the list is the same as accepted by the open_nth() function.
sourcepub fn reset(&mut self) -> Result<(), Error>
pub fn reset(&mut self) -> Result<(), Error>
Reset dongle parameters to boot values.
This function is called by Crazyradio::open_*.
sourcepub fn set_cache_settings(&mut self, cache_settings: bool)
pub fn set_cache_settings(&mut self, cache_settings: bool)
Enable or disable caching of settings
If enabled, setting the radio channel, address or datarate will be ignored if the settings is the same as the one already set in the dongle
This is enabled by default and is a useful functionality to efficiently implement communication to multiple device as changing these settings require USB communication and is quite slow.
sourcepub fn set_ard_time(&mut self, delay: Duration) -> Result<(), Error>
pub fn set_ard_time(&mut self, delay: Duration) -> Result<(), Error>
Set time to wait for the ack packet.
sourcepub fn set_ard_bytes(&mut self, nbytes: u8) -> Result<(), Error>
pub fn set_ard_bytes(&mut self, nbytes: u8) -> Result<(), Error>
Set time to wait for the ack packet by specifying the max byte-length of the ack payload.
sourcepub fn set_arc(&mut self, arc: usize) -> Result<(), Error>
pub fn set_arc(&mut self, arc: usize) -> Result<(), Error>
Set the number of time the radio will retry to send the packet if an ack packet is not received in time.
sourcepub fn set_ack_enable(&mut self, ack_enable: bool) -> Result<(), Error>
pub fn set_ack_enable(&mut self, ack_enable: bool) -> Result<(), Error>
Set if the radio waits for an ack packet.
Should be disabled when sending broadcast packets.
sourcepub fn scan_channels(
&mut self,
start: Channel,
stop: Channel,
packet: &[u8]
) -> Result<Vec<Channel>, Error>
pub fn scan_channels( &mut self, start: Channel, stop: Channel, packet: &[u8] ) -> Result<Vec<Channel>, Error>
Sends a packet to a range of channel and returns a list of channel that acked
Used to activally scann for receives on channels. This function sends
sourcepub fn launch_bootloader(self) -> Result<(), Error>
pub fn launch_bootloader(self) -> Result<(), Error>
Launch the bootloader.
Consumes the Crazyradio since it is not usable after that (it is in bootlaoder mode …).
sourcepub fn set_cont_carrier(&mut self, enable: bool) -> Result<(), Error>
pub fn set_cont_carrier(&mut self, enable: bool) -> Result<(), Error>
Set the radio in continious carrier mode.
In continious carrier mode, the radio will transmit a continious sine wave at the setup channel frequency using the setup transmit power.
sourcepub fn send_packet(
&mut self,
data: &[u8],
ack_data: &mut [u8]
) -> Result<Ack, Error>
pub fn send_packet( &mut self, data: &[u8], ack_data: &mut [u8] ) -> Result<Ack, Error>
Send a data packet and receive an ack packet.
Arguments
data
: Up to 32 bytes of data to be send.ack_data
: Buffer to hold the data received from the ack packet payload. The ack payload can be up to 32 bytes, if this buffer length is lower than 32 bytes the ack data might be truncated. The length of the ack payload is returned in Ack::length.
source§impl Crazyradio
impl Crazyradio
Async implementations
Async version of open/getserial functions.
Implemented by launching a thread, calling the sync function and passing the result back though a channel. This is not the most efficient implementation but it keeps the lib executor-independent and these functions are only one-time-call in most programs.
sourcepub async fn open_first_async() -> Result<Self, Error>
Available on crate feature async
only.
pub async fn open_first_async() -> Result<Self, Error>
async
only.Async vesion of Crazyradio::open_first()
sourcepub async fn open_nth_async(nth: usize) -> Result<Self, Error>
Available on crate feature async
only.
pub async fn open_nth_async(nth: usize) -> Result<Self, Error>
async
only.Async vesion of Crazyradio::open_nth()
sourcepub async fn open_by_serial_async(serial: &str) -> Result<Self, Error>
Available on crate feature async
only.
pub async fn open_by_serial_async(serial: &str) -> Result<Self, Error>
async
only.Async vesion of Crazyradio::open_by_serial()
sourcepub async fn list_serials_async() -> Result<Vec<String>, Error>
Available on crate feature async
only.
pub async fn list_serials_async() -> Result<Vec<String>, Error>
async
only.Async vesion of Crazyradio::list_serials()