Struct RadioLink

Source
pub struct RadioLink { /* private fields */ }
Expand description

VEXLink Wireless Radio Link

VEXLink is a point-to-point wireless communications protocol between two VEXNet radios. For further information, see https://www.vexforum.com/t/vexlink-documentaton/84538

Implementations§

Source

pub const INTERNAL_BUFFER_SIZE: usize = 512usize

The length of the link’s FIFO input and output buffers.

Source

pub fn open(port: SmartPort, id: &str, link_type: LinkType) -> Self

Opens a radio link from a VEXNet radio plugged into a Smart Port. Once opened, other VEXNet functionality such as controller tethering on this specific radio will be disabled. Other radios connected to the Brain can take over this functionality.

§Panics
  • Panics if a NUL (0x00) character was found anywhere in the specified id.
§Examples
use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    let link = RadioLink::open(port_1, "643A", LinkType::Manager);
}
Source

pub fn unread_bytes(&self) -> Result<usize, LinkError>

Returns the number of bytes that are waiting to be read from the radio’s input buffer.

§Errors
§Examples
use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    let mut link = RadioLink::open(port_1, "643A", LinkType::Manager);

    let mut buffer = vec![0; 2048];

    // Read into `buffer` if there are unread bytes.
    if link.unread_bytes().is_ok_and(|bytes| bytes > 0) {
        _ = link.read(&mut buffer);
    }
}
Source

pub fn available_write_bytes(&self) -> Result<usize, LinkError>

Returns the number of bytes free in the radio’s output buffer.

§Errors
§Examples
use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    let mut link = RadioLink::open(port_1, "643A", LinkType::Manager);

    // Write a byte if there's free space in the buffer.
    if link.available_write_bytes().is_ok_and(|available| available > 0) {
        _ = link.write(0x80);
    }
}
Source

pub fn is_linked(&self) -> bool

Returns true if there is a link established with another radio.

§Examples
use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    let mut link = RadioLink::open(port_1, "643A", LinkType::Manager);

    // Write a byte if we are connected to another radio.
    if link.is_linked() == Ok(true) {
        _ = link.write(0x80);
    }
}

Trait Implementations§

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<RadioLink> for SmartPort

Source§

fn from(device: RadioLink) -> Self

Converts to this type from the input type.
Source§

fn eq(&self, other: &RadioLink) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Read some bytes sent to the radio into the specified buffer, returning how many bytes were read.

§Errors
§Examples
use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    let mut link = RadioLink::open(port_1, "643A", LinkType::Manager);

    let mut buffer = vec![0; 2048];

    loop {
        _ = link.read(&mut buffer);
        sleep(core::time::Duration::from_millis(10)).await;
    }
}
Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
Source§

unsafe fn initializer(&self) -> Initializer

Determines if this Reader can work with buffers of uninitialized memory. Read more
Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adaptor which will chain this stream with another. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adaptor which will read at most limit bytes from it. Read more
Source§

const UPDATE_INTERVAL: Duration

The interval at which the V5 brain reads packets from Smart devices.
Source§

fn port_number(&self) -> u8

Returns the port number of the SmartPort this device is registered on. Read more
Source§

fn device_type(&self) -> SmartDeviceType

Returns the variant of SmartDeviceType that this device is associated with. Read more
Source§

fn is_connected(&self) -> bool

Determine if this device type is currently connected to the SmartPort that it’s registered to. Read more
Source§

fn timestamp(&self) -> Result<SmartDeviceTimestamp, PortError>

Returns the timestamp recorded by this device’s internal clock. Read more
Source§

fn validate_port(&self) -> Result<(), PortError>

Verify that the device type is currently plugged into this port, returning an appropriate PortError if not available. Read more
Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into the radio’s output buffer, returning how many bytes were written.

§Errors
§Examples
use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    let mut link = RadioLink::open(port_1, "643A", LinkType::Manager);

    _ = link.write(b"yo");
}
Source§

fn flush(&mut self) -> Result<()>

This function does nothing.

VEXLink immediately sends and clears data sent into the write buffer.

§Errors
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Write. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.