pros_sys/
link.rs

1#[doc(hidden)]
2pub const E_LINK_RECIEVER: core::ffi::c_uint = 0;
3// PROS PLS FIX 🥺
4pub use E_LINK_RECIEVER as E_LINK_RECEIVER;
5pub const E_LINK_TRANSMITTER: core::ffi::c_uint = 1;
6pub const E_LINK_RX: core::ffi::c_uint = E_LINK_RECEIVER;
7pub const E_LINK_TX: core::ffi::c_uint = E_LINK_TRANSMITTER;
8pub type link_type_e_t = core::ffi::c_uint;
9
10extern "C" {
11    /**
12    Initializes a link on a radio port, with an indicated type. There might be a
13    1 to 2 second delay from when this function is called to when the link is initializes.
14    PROS currently only supports the use of one radio per brain.
15
16    This function uses the following values of errno when an error state is
17    reached:
18    ENXIO - The given value is not within the range of V5 ports (1-21).
19    ENODEV - The port cannot be configured as a radio.
20    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
21
22    \param port
23         The port of the radio for the intended link.
24    \param link_id
25         Unique link ID in the form of a string, needs to be different from other links in
26         the area.
27    \param type
28         Indicates whether the radio link on the brain is a transmitter or receiver,
29         with the transmitter having double the transmitting bandwidth as the receiving
30         end (1040 bytes/s vs 520 bytes/s).
31
32    \return PROS_ERR if initialization fails, 1 if the initialization succeeds.
33    */
34    pub fn link_init(port: u8, link_id: *const core::ffi::c_char, r#type: link_type_e_t) -> u32;
35    /**
36    Initializes a link on a radio port, with an indicated type and the ability for
37    vexlink to override the controller radio. There might be a 1 to 2 second delay
38    from when this function is called to when the link is initializes.
39    PROS currently only supports the use of one radio per brain.
40
41    This function uses the following values of errno when an error state is
42    reached:
43    ENXIO - The given value is not within the range of V5 ports (1-21).
44    ENODEV - The port cannot be configured as a radio.
45    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
46
47    \param port
48         The port of the radio for the intended link.
49    \param link_id
50         Unique link ID in the form of a string, needs to be different from other links in
51         the area.
52    \param type
53         Indicates whether the radio link on the brain is a transmitter or receiver,
54         with the transmitter having double the transmitting bandwidth as the receiving
55         end (1040 bytes/s vs 520 bytes/s).
56
57    \return PROS_ERR if initialization fails, 1 if the initialization succeeds.
58    */
59    pub fn link_init_override(
60        port: u8,
61        link_id: *const core::ffi::c_char,
62        r#type: link_type_e_t,
63    ) -> u32;
64    /**
65    Checks if a radio link on a port is active or not.
66
67    This function uses the following values of errno when an error state is
68    reached:
69    ENXIO - The given value is not within the range of V5 ports (1-21).
70    ENODEV - The port cannot be configured as a radio.
71    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
72
73    \param port
74         The port of the radio for the intended link.
75
76    \return If a radio is connected to a port and it's connected to a link.
77    */
78    pub fn link_connected(port: u8) -> bool;
79    /**
80    Returns the bytes of data available to be read
81
82    This function uses the following values of errno when an error state is
83    reached:
84    ENXIO - The given value is not within the range of V5 ports (1-21).
85    ENODEV - The port cannot be configured as a radio.
86    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
87
88    \param port
89         The port of the radio for the intended link.
90
91    \return PROS_ERR if port is not a link/radio, else the bytes available to be
92    read by the user.
93    */
94    pub fn link_raw_receivable_size(port: u8) -> u32;
95    /**
96    Returns the bytes of data available in transmission buffer.
97
98    This function uses the following values of errno when an error state is
99    reached:
100    ENXIO - The given value is not within the range of V5 ports (1-21).
101    ENODEV - The port cannot be configured as a radio.
102    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
103
104    \param port
105         The port of the radio for the intended link.
106
107    \return PROS_ERR if port is not a link/radio,
108    */
109    pub fn link_raw_transmittable_size(port: u8) -> u32;
110    /**
111    Send raw serial data through vexlink.
112
113    This function uses the following values of errno when an error state is
114    reached:
115    ENXIO - The given value is not within the range of V5 ports (1-21).
116    ENODEV - The port cannot be configured as a radio.
117    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
118    EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no
119    room in the FIFO buffer (queue) to transmit the data.
120    EINVAL - The data given is NULL
121
122    \param port
123         The port of the radio for the intended link.
124    \param data
125         Buffer with data to send
126    \param data_size
127         Bytes of data to be read to the destination buffer
128
129    \return PROS_ERR if port is not a link, and the successfully transmitted
130    data size if it succeeded.
131    */
132    pub fn link_transmit_raw(port: u8, data: *const core::ffi::c_void, data_size: u16) -> u32;
133    /**
134    Receive raw serial data through vexlink.
135
136    This function uses the following values of errno when an error state is
137    reached:
138    ENXIO - The given value is not within the range of V5 ports (1-21).
139    ENODEV - The port cannot be configured as a radio.
140    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
141    EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer
142    or destination buffer.
143
144    \param port
145         The port of the radio for the intended link.
146    \param dest
147         Destination buffer to read data to
148    \param data_size
149         Bytes of data to be read to the destination buffer
150
151    \return PROS_ERR if port is not a link, and the successfully received
152    data size if it succeeded.
153    */
154    pub fn link_receive_raw(port: u8, dest: *mut core::ffi::c_void, data_size: u16) -> u32;
155    /**
156    Send packeted message through vexlink, with a checksum and start byte.
157
158    This function uses the following values of errno when an error state is
159    reached:
160    ENXIO - The given value is not within the range of V5 ports (1-21).
161    ENODEV - The port cannot be configured as a radio.
162    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
163    EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no
164    room in the FIFO buffer (queue) to transmit the data.
165    EINVAL - The data given is NULL
166
167    \param port
168         The port of the radio for the intended link.
169    \param data
170         Buffer with data to send
171    \param data_size
172         Bytes of data to be read to the destination buffer
173
174    \return PROS_ERR if port is not a link, and the successfully transmitted
175    data size if it succeeded.
176    */
177    pub fn link_transmit(port: u8, data: *const core::ffi::c_void, data_size: u16) -> u32;
178    /**
179    Receive packeted message through vexlink, with a checksum and start byte.
180
181    This function uses the following values of errno when an error state is
182    reached:
183    ENXIO - The given value is not within the range of V5 ports (1-21).
184    ENODEV - The port cannot be configured as a radio.
185    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
186    EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer
187    or destination buffer.
188    EBADMSG - Protocol error related to start byte, data size, or checksum.
189
190    \param port
191         The port of the radio for the intended link.
192    \param dest
193         Destination buffer to read data to
194    \param data_size
195         Bytes of data to be read to the destination buffer
196
197    \return PROS_ERR if port is not a link or protocol error, and the successfully
198    transmitted data size if it succeeded.
199    */
200    pub fn link_receive(port: u8, dest: *mut core::ffi::c_void, data_size: u16) -> u32;
201    /**
202    Clear the receive buffer of the link, and discarding the data.
203
204    This function uses the following values of errno when an error state is
205    reached:
206    ENXIO - The given value is not within the range of V5 ports (1-21).
207    ENODEV - The port cannot be configured as a radio.
208    ENXIO - The sensor is still calibrating, or no link is connected via the radio.
209
210    \param port
211         The port of the radio for the intended link.
212
213    \return PROS_ERR if port is not a link, and the successfully received
214    data size if it succeeded.
215    */
216    pub fn link_clear_receive_buf(port: u8) -> u32;
217}