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

source

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

source

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

source

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")?;
source

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.

source

pub fn serial(&self) -> Result<String, Error>

Return the serial number of this radio

source

pub fn reset(&mut self) -> Result<(), Error>

Reset dongle parameters to boot values.

This function is called by Crazyradio::open_*.

source

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.

source

pub fn set_channel(&mut self, channel: Channel) -> Result<(), Error>

Set the radio channel.

source

pub fn set_datarate(&mut self, datarate: Datarate) -> Result<(), Error>

Set the datarate.

source

pub fn set_address(&mut self, address: &[u8; 5]) -> Result<(), Error>

Set the radio address.

source

pub fn set_power(&mut self, power: Power) -> Result<(), Error>

Set the transmit power.

source

pub fn set_ard_time(&mut self, delay: Duration) -> Result<(), Error>

Set time to wait for the ack packet.

source

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.

source

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.

source

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.

source

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

source

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 …).

source

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.

source

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

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.

source

pub async fn open_first_async() -> Result<Self, Error>

Available on crate feature async only.

Async vesion of Crazyradio::open_first()

source

pub async fn open_nth_async(nth: usize) -> Result<Self, Error>

Available on crate feature async only.

Async vesion of Crazyradio::open_nth()

source

pub async fn open_by_serial_async(serial: &str) -> Result<Self, Error>

Available on crate feature async only.
source

pub async fn list_serials_async() -> Result<Vec<String>, Error>

Available on crate feature async only.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.