[][src]Struct crazyradio::Crazyradio

pub struct Crazyradio { /* fields omitted */ }

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

impl Crazyradio[src]

pub fn open_first() -> Result<Self, Error>[src]

Open the first Crazyradio detected and returns a Crazyradio object.

The dongle is reset to boot values before being returned

pub fn open_nth(nth: usize) -> Result<Self, Error>[src]

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

pub fn open_by_serial(serial: &str) -> Result<Self, Error>[src]

Open a Crazyradio by specifying its serial number

Example:

use crazyradio::Crazyradio;
let mut cr = Crazyradio::open_by_serial("FD61E54B7A")?;

pub fn list_serials() -> Result<Vec<String>, Error>[src]

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.

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

Return the serial number of this radio

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

Reset dongle parameters to boot values.

This function is called by Crazyradio::open_*.

pub fn set_cache_settings(&mut self, cache_settings: bool)[src]

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.

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

Set the radio channel.

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

Set the datarate.

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

Set the radio address.

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

Set the transmit power.

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

Set time to wait for the ack packet.

pub fn set_ard_bytes(&mut self, nbytes: u8) -> Result<(), Error>[src]

Set time to wait for the ack packet by specifying the max byte-length of the ack payload.

pub fn set_arc(&mut self, arc: usize) -> Result<(), Error>[src]

Set the number of time the radio will retry to send the packet if an ack packet is not received in time.

pub fn set_ack_enable(&mut self, ack_enable: bool) -> Result<(), Error>[src]

Set if the radio waits for an ack packet.

Should be disabled when sending broadcast packets.

pub fn scan_channels(
    &mut self,
    start: Channel,
    stop: Channel,
    packet: &[u8]
) -> Result<Vec<Channel>, Error>
[src]

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

pub fn launch_bootloader(self) -> Result<(), Error>[src]

Launch the bootloader.

Consumes the Crazyradio since it is not usable after that (it is in bootlaoder mode ...).

pub fn set_cont_carrier(&mut self, enable: bool) -> Result<(), Error>[src]

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.

pub fn send_packet(
    &mut self,
    data: &[u8],
    ack_data: &mut [u8]
) -> Result<Ack, Error>
[src]

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.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.