VEX Link C API module
Contents
- Reference
Files
- file link.h
Namespaces
- namespace pros::c
Functions
- uint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type)
- Initializes a link on a radio port, with an indicated type.
- uint32_t link_init_override(uint8_t port, const char* link_id, link_type_e_t type)
- Initializes a link on a radio port, with an indicated type and the ability for vexlink to override the controller radio.
- bool link_connected(uint8_t port)
- Checks if a radio link on a port is active or not.
- uint32_t link_raw_receivable_size(uint8_t port)
- Returns the bytes of data available to be read.
- uint32_t link_raw_transmittable_size(uint8_t port)
- Returns the bytes of data available in transmission buffer.
- uint32_t link_transmit_raw(uint8_t port, void* data, uint16_t data_size)
- Send raw serial data through vexlink.
- uint32_t link_receive_raw(uint8_t port, void* dest, uint16_t data_size)
- Receive raw serial data through vexlink.
- uint32_t link_transmit(uint8_t port, void* data, uint16_t data_size)
- Send packeted message through vexlink, with a checksum and start byte.
- uint32_t link_receive(uint8_t port, void* dest, uint16_t data_size)
- Receive packeted message through vexlink, with a checksum and start byte.
- uint32_t link_clear_receive_buf(uint8_t port)
- Clear the receive buffer of the link, and discarding the data.
Enums
- enum link_type_e { E_LINK_RECIEVER = 0, E_LINK_TRANSMITTER, E_LINK_RX = E_LINK_RECIEVER, E_LINK_TX = E_LINK_TRANSMITTER }
Defines
- #define LINK_BUFFER_SIZE
- The maximum size of a link buffer.
Function documentation
uint32_t link_init(uint8_t port,
const char* link_id,
link_type_e_t type)
#include <pros/link.h>
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). |
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. PROS currently only supports the use of one radio per brain.
Example
#define LINK_TRANSMITTER_PORT 1 #define LINK_ID "ROBOT1" void initialize() { link_init(LINK_TRANSMITTER_PORT, LINK_ID, E_LINK_TRANSMITTER); }
uint32_t link_init_override(uint8_t port,
const char* link_id,
link_type_e_t type)
#include <pros/link.h>
Initializes a link on a radio port, with an indicated type and the ability for vexlink to override the controller radio.
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). |
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. PROS currently only supports the use of one radio per brain.
Example
#define LINK_PORT 1 #define LINK_ID "ROBOT1" void initialize() { link_init(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER); link_init_override(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER); }
bool link_connected(uint8_t port)
#include <pros/link.h>
Checks if a radio link on a port is active or not.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
Returns | If a radio is connected to a port and it's connected to a link. |
Example
#define LINK_TRANSMITTER_PORT 1 void opcontrol() { while (true) { if (link_connected(LINK_TRANSMITTER_PORT)) { screen_print(TEXT_MEDIUM, 1, "Link connected!"); } delay(20); } }
uint32_t link_raw_receivable_size(uint8_t port)
#include <pros/link.h>
Returns the bytes of data available to be read.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
Returns | PROS_ERR if port is not a link/radio, else the bytes available to be read by the user. |
Example
#define LINK_RECIVER_PORT 1 void opcontrol() { while (true) { uint32_t receiveable_size = link_raw_receivable_size(LINK_RECIVER_PORT); screen_print(TEXT_MEDIUM, 1, "link_raw_receiveable_size: %d", receiveable_size); delay(20); } }
uint32_t link_raw_transmittable_size(uint8_t port)
#include <pros/link.h>
Returns the bytes of data available in transmission buffer.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
Returns | PROS_ERR if port is not a link/radio, |
Example
#define LINK_TRANSMITTER_PORT 1 void opcontrol() { while (true) { uint32_t transmittable_size = link_raw_transmittable_size(LINK_TRANSMITTER_PORT); screen_print(TEXT_MEDIUM, 1, "link_raw_transmittable_size: %d", transmittable_size); delay(20); } }
uint32_t link_transmit_raw(uint8_t port,
void* data,
uint16_t data_size)
#include <pros/link.h>
Send raw serial data through vexlink.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
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
#define LINK_TRANSMITTER_PORT 1 void opcontrol() { while (true) { char* data = "Hello!"; link_transmit_raw(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); delay(20); } }
uint32_t link_receive_raw(uint8_t port,
void* dest,
uint16_t data_size)
#include <pros/link.h>
Receive raw serial data through vexlink.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
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
#define LINK_RECIVER_PORT 1 void opcontrol() { while (true) { char* result; char* expected = "Hello!"; link_receive_raw(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected)); delay(20); } }
uint32_t link_transmit(uint8_t port,
void* data,
uint16_t data_size)
#include <pros/link.h>
Send packeted message through vexlink, with a checksum and start byte.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
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
#define LINK_TRANSMITTER_PORT 1 void opcontrol() { while (true) { char* data = "Hello!"; link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); delay(20); } }
uint32_t link_receive(uint8_t port,
void* dest,
uint16_t data_size)
#include <pros/link.h>
Receive packeted message through vexlink, with a checksum and start byte.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
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 or protocol error, and the successfully transmitted data size if it succeeded. |
Example
#define LINK_RECIVER_PORT 1 void opcontrol() { while (true) { char* result; char* expected = "Hello!"; link_receive(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected)); delay(20); } }
uint32_t link_clear_receive_buf(uint8_t port)
#include <pros/link.h>
Clear the receive buffer of the link, and discarding the data.
Parameters | |
---|---|
port | The port of the radio for the intended link. |
Returns | PROS_ERR if port is not a link, and the successfully received data size if it succeeded. |
Example
#define LINK_TRANSMITTER_PORT 1 void opcontrol() { while (true) { char* data = "Hello!"; link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); link_clear_receive_buf(LINK_TRANSMITTER_PORT); delay(20); } }
Enum documentation
enum link_type_e
#include <pros/link.h>
Enumerators | |
---|---|
E_LINK_RECIEVER |
Indicates that the radio is a reciever. |
E_LINK_TRANSMITTER |
Indicates that the link is a transmitter. |
E_LINK_RX |
Alias for E_LINK_RECIEVER. |
E_LINK_TX |
Alias for E_LINK_TRANSMITTER. |
Define documentation
#define LINK_BUFFER_SIZE
#include <pros/link.h>
The maximum size of a link buffer.