VEX Link C++ API module
///
Files
- file link.hpp
Classes
- class pros::Link
Functions
- Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = true) explicit
- Initializes a link on a radio port, with an indicated type.
- bool connected()
- Checks if a radio link on a port is active or not.
- std::uint32_t raw_receivable_size()
- Returns the bytes of data number of without protocol available to be read.
- std::uint32_t transmit_raw(void* data, std::uint16_t data_size)
- Returns the bytes of data available in transmission buffer.
- std::uint32_t receive_raw(void* dest, std::uint16_t data_size)
- Receive raw serial data through vexlink.
- std::uint32_t transmit(void* data, std::uint16_t data_size)
- Send packeted message through vexlink, with a checksum and start byte.
- std::uint32_t receive(void* dest, std::uint16_t data_size)
- Receive packeted message through vexlink, with a checksum and start byte.
- std::uint32_t clear_receive_buf()
- Clear the receive buffer of the link, and discarding the data.
Function documentation
Link(const std::uint8_t port,
const std::string link_id,
link_type_e_t type,
bool ov = true) explicit
#include <pros/link.hpp>
Initializes a link on a radio port, with an indicated type.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
link_id | Unique link ID in the form of a string, needs to be different from other links in the area. |
type | Indicates whether the radio link on the brain is a transmitter or receiver, with the transmitter having double the transmitting bandwidth as the receiving end (1040 bytes/s vs 520 bytes/s). |
ov | Indicates if the radio on the given port needs vexlink to override the controller radio. Defualts to True. |
Returns | PROS_ERR if initialization fails, 1 if the initialization succeeds. |
There might be a 1 to 2 second delay from when this function is called to when the link is initializes.
Example: pros::Link link(1, "my_link", pros::E_LINK_TX);
bool connected()
#include <pros/link.hpp>
Checks if a radio link on a port is active or not.
Returns | If a radio is connected to a port and it's connected to a link. |
---|
Example:
pros::Link link(1, "my_link", pros::E_LINK_TX); if (link.connected()) { // do something }
std::uint32_t raw_receivable_size()
#include <pros/link.hpp>
Returns the bytes of data number of without protocol available to be read.
Returns | PROS_ERR if port is not a link/radio, else the bytes available to be read by the user. |
---|
Example:
void opcontrol() { pros::Link link(1, "my_link", pros::E_LINK_TX); printf("Bytes available to read: %d", link.receivable_size()); }
std::uint32_t transmit_raw(void* data,
std::uint16_t data_size)
#include <pros/link.hpp>
Returns the bytes of data available in transmission buffer.
Returns | PROS_ERR if port is not a link/radio, else the bytes available to be transmitted by the user. |
---|
Example:
void opcontrol() { pros::Link link(1, "my_link", pros::E_LINK_TX); printf("Bytes available to transmit: %d", link.transmittable_size()); } / std::uint32_t raw_transmittable_size(); /** * Send raw serial data through vexlink. * * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no * room in the FIFO buffer (queue) to transmit the data. * EINVAL - The data given is NULL * * \param data * Buffer with data to send * \param data_size * Buffer with data to send * * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. * * \b Example: * \code * void opcontrol() { * pros::Link link(1, "my_link", pros::E_LINK_TX); * std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04}; * link.transmit_raw(data, 4); * } * *
std::uint32_t receive_raw(void* dest,
std::uint16_t data_size)
#include <pros/link.hpp>
Receive raw serial data through vexlink.
Parameters | |
---|---|
dest | Destination buffer to read data to |
data_size | Bytes of data to be read to the destination buffer |
Returns | PROS_ERR if port is not a link, and the successfully received data size if it succeeded. |
Example:
void opcontrol() { pros::Link link(1, "my_link", pros::E_LINK_TX); std::uint8_t data[4]; link.receive_raw(data, 4); }
std::uint32_t transmit(void* data,
std::uint16_t data_size)
#include <pros/link.hpp>
Send packeted message through vexlink, with a checksum and start byte.
Parameters | |
---|---|
data | Buffer with data to send |
data_size | Bytes of data to be read to the destination buffer |
Returns | PROS_ERR if port is not a link, and the successfully transmitted data size if it succeeded. |
Example:
void opcontrol() { pros::Link link(1, "my_link", pros::E_LINK_TX); std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04}; link.transmit(data, 4); }
std::uint32_t receive(void* dest,
std::uint16_t data_size)
#include <pros/link.hpp>
Receive packeted message through vexlink, with a checksum and start byte.
Parameters | |
---|---|
dest | Destination buffer to read data to |
data_size | Bytes of data to be read to the destination buffer |
Returns | PROS_ERR if port is not a link, and the successfully received data size if it succeeded. |
Example:
void opcontrol() { pros::Link link(1, "my_link", pros::E_LINK_TX); std::uint8_t data[4]; link.receive(data, 4); }
std::uint32_t clear_receive_buf()
#include <pros/link.hpp>
Clear the receive buffer of the link, and discarding the data.
Returns | PROS_ERR if port is not a link, 1 if the operation succeeded. |
---|
Example:
void opcontrol() { pros::Link link(1, "my_link", pros::E_LINK_TX); link.clear_receive_buf(); }