1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Contains prototypes for the V5 Generic Serial related functions.

extern "C" {
    /**
    Enables generic serial on the given port.

    \note This function must be called before any of the generic serial
    functions will work.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - The given value is not within the range of V5 ports (1-21).
    EACCES - Another resource is currently trying to access the port.

    \param port
           The V5 port number from 1-21

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn serial_enable(port: u8) -> i32;
    /**
    Sets the baudrate for the serial port to operate at.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - The given value is not within the range of V5 ports (1-21).
    EACCES - Another resource is currently trying to access the port.

    \param port
           The V5 port number from 1-21
    \param baudrate
           The baudrate to operate at

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn serial_set_baudrate(port: u8, baudrate: i32) -> i32;
    /**
    Clears the internal input and output FIFO buffers.

    This can be useful to reset state and remove old, potentially unneeded data
    from the input FIFO buffer or to cancel sending any data in the output FIFO
    buffer.

    \note This function does not cause the data in the output buffer to be
    written, it simply clears the internal buffers. Unlike stdout, generic
    serial does not use buffered IO (the FIFO buffers are written as soon
    as possible).

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - The given value is not within the range of V5 ports (1-21).
    EACCES - Another resource is currently trying to access the port.

    \param port
           The V5 port number from 1-21

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn serial_flush(port: u8) -> i32;
    /**
     Returns the number of bytes available to be read in the the port's FIFO
     input buffer.

     \note This function does not actually read any bytes, is simply returns the
     number of bytes available to be read.

     This function uses the following values of errno when an error state is
     reached:
     EINVAL - The given value is not within the range of V5 ports (1-21).
     EACCES - Another resource is currently trying to access the port.

     \param port
            The V5 port number from 1-21

     \return The number of bytes available to be read or PROS_ERR if the operation
     failed, setting errno.
    */
    pub fn serial_get_read_avail(port: u8) -> i32;
    /**
     Returns the number of bytes free in the port's FIFO output buffer.

     \note This function does not actually write any bytes, is simply returns the
     number of bytes free in the port's buffer.

     This function uses the following values of errno when an error state is
     reached:
     EINVAL - The given value is not within the range of V5 ports (1-21).
     EACCES - Another resource is currently trying to access the port.

     \param port
            The V5 port number from 1-21

     \return The number of bytes free or PROS_ERR if the operation failed,
     setting errno.
    */
    pub fn serial_get_write_free(port: u8) -> i32;
    /**
     Reads the next byte available in the port's input buffer without removing it.

     This function uses the following values of errno when an error state is
     reached:
     EINVAL - The given value is not within the range of V5 ports (1-21).
     EACCES - Another resource is currently trying to access the port.

     \param port
            The V5 port number from 1-21

     \return The next byte available to be read, -1 if none are available, or
     PROS_ERR if the operation failed, setting errno.
    */
    pub fn serial_peek_byte(port: u8) -> i32;
    /**
    Reads the next byte available in the port's input buffer.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - The given value is not within the range of V5 ports (1-21).
    EACCES - Another resource is currently trying to access the port.

    \param port
           The V5 port number from 1-21

    \return The next byte available to be read, -1 if none are available, or
    PROS_ERR if the operation failed, setting errno.
    */
    pub fn serial_read_byte(port: u8) -> i32;
    /**
     Reads up to the next length bytes from the port's input buffer and places
     them in the user supplied buffer.

     \note This function will only return bytes that are currently available to be
     read and will not block waiting for any to arrive.

     This function uses the following values of errno when an error state is
     reached:
     EINVAL - The given value is not within the range of V5 ports (1-21).
     EACCES - Another resource is currently trying to access the port.

     \param port
            The V5 port number from 1-21
     \param buffer
            The location to place the data read
     \param length
            The maximum number of bytes to read

     \return The number of bytes read or PROS_ERR if the operation failed, setting
     errno.
    */
    pub fn serial_read(port: u8, buffer: *mut u8, length: i32) -> i32;
    /**
     Write the given byte to the port's output buffer.

     \note Data in the port's output buffer is written to the serial port as soon
     as possible on a FIFO basis and can not be done manually by the user.

     This function uses the following values of errno when an error state is
     reached:
     EINVAL - The given value is not within the range of V5 ports (1-21).
     EACCES - Another resource is currently trying to access the port.
     EIO - Serious internal write error.

     \param port
            The V5 port number from 1-21
     \param buffer
            The byte to write

     \return The number of bytes written or PROS_ERR if the operation failed,
     setting errno.
    */
    pub fn serial_write_byte(port: u8, buffer: u8) -> i32;
    /**
     Writes up to length bytes from the user supplied buffer to the port's output
     buffer.

     \note Data in the port's output buffer is written to the serial port as soon
     as possible on a FIFO basis and can not be done manually by the user.

     This function uses the following values of errno when an error state is
     reached:
     EINVAL - The given value is not within the range of V5 ports (1-21).
     EACCES - Another resource is currently trying to access the port.
     EIO - Serious internal write error.

     \param port
            The V5 port number from 1-21
     \param buffer
            The data to write
     \param length
            The maximum number of bytes to write

     \return The number of bytes written or PROS_ERR if the operation failed,
     setting errno.
    */
    pub fn serial_write(port: u8, buffer: *mut u8, length: i32) -> i32;
}