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§impl RadioLink
impl RadioLink
Sourcepub const INTERNAL_BUFFER_SIZE: usize = 512usize
pub const INTERNAL_BUFFER_SIZE: usize = 512usize
The length of the link’s FIFO input and output buffers.
Sourcepub fn open(port: SmartPort, id: &str, link_type: LinkType) -> Self
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);
}
Sourcepub fn unread_bytes(&self) -> Result<usize, LinkError>
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
- A
LinkError::ReadFailed
error is returned if the input buffer could not be accessed.
§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);
}
}
Sourcepub fn available_write_bytes(&self) -> Result<usize, LinkError>
pub fn available_write_bytes(&self) -> Result<usize, LinkError>
Returns the number of bytes free in the radio’s output buffer.
§Errors
- A
LinkError::ReadFailed
error is returned if the output buffer could not be accessed.
§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);
}
}
Sourcepub fn is_linked(&self) -> bool
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§impl Read for RadioLink
impl Read for RadioLink
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
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
- An error with the kind
io::ErrorKind::AddrNotAvailable
is returned if there is no device connected. - An error with the kind
io::ErrorKind::AddrInUse
is returned a device other than a radio is connected. - An error with the kind
io::ErrorKind::NotConnected
is returned if a connection with another radio has not been established. UseRadioLink::is_linked
to check this if needed. - An error with the kind
io::ErrorKind::Other
is returned if an unexpected internal read error occurred.
§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>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read moreSource§unsafe fn initializer(&self) -> Initializer
unsafe fn initializer(&self) -> Initializer
Read
er can work with buffers of uninitialized
memory. Read moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl SmartDevice for RadioLink
impl SmartDevice for RadioLink
Source§const UPDATE_INTERVAL: Duration
const UPDATE_INTERVAL: Duration
Source§fn port_number(&self) -> u8
fn port_number(&self) -> u8
Source§fn device_type(&self) -> SmartDeviceType
fn device_type(&self) -> SmartDeviceType
SmartDeviceType
that this device is associated with. Read moreSource§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Source§impl Write for RadioLink
impl Write for RadioLink
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into the radio’s output buffer, returning how many bytes were written.
§Errors
- An error with the kind
io::ErrorKind::NotConnected
is returned if a connection with another radio has not been established. UseRadioLink::is_linked
to check this if needed. - An error with the kind
io::ErrorKind::Other
is returned if an unexpected internal write error occurred.
§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<()>
fn flush(&mut self) -> Result<()>
This function does nothing.
VEXLink immediately sends and clears data sent into the write buffer.
§Errors
- An error with the kind
io::ErrorKind::NotConnected
is returned if a connection with another radio has not been established. UseRadioLink::is_linked
to check this if needed.