33 log->
error(
"Unable to open port \"%s\": %s",
PORT, strerror(errno));
39 struct termios options;
43 options.c_cflag |= (CLOCAL | CREAD);
46 log->
error(
"failed to write options");
62 switch (new_baudrate) {
100 new_baudrate = B4800;
103 new_baudrate = B9600;
106 new_baudrate = B19200;
109 new_baudrate = B38400;
112 new_baudrate = B57600;
115 new_baudrate = B115200;
118 new_baudrate = B230400;
121 new_baudrate = B460800;
124 new_baudrate = B500000;
127 new_baudrate = B576000;
130 new_baudrate = B921600;
133 new_baudrate = B1000000;
136 new_baudrate = B1152000;
139 new_baudrate = B1500000;
142 new_baudrate = B2000000;
145 new_baudrate = B2500000;
148 new_baudrate = B3000000;
151 new_baudrate = B3500000;
154 new_baudrate = B4000000;
161 struct termios options;
166 cfsetispeed(&options, new_baudrate);
167 cfsetospeed(&options, new_baudrate);
170 log->
error(
"failed to write baudrate %i", new_baudrate);
176 uint32_t character_size;
177 switch (word_length) {
179 character_size = CS5;
182 character_size = CS6;
185 character_size = CS7;
189 character_size = CS8;
193 struct termios options;
199 options.c_cflag &= ~CSIZE;
200 options.c_cflag |= character_size;
207 struct termios options;
213 switch (parity_bit) {
215 options.c_cflag |= PARENB;
216 options.c_cflag &= ~PARODD;
217 options.c_cflag &= ~CSTOPB;
218 options.c_iflag |= (INPCK | ISTRIP);
221 options.c_cflag |= PARENB;
222 options.c_cflag |= PARODD;
223 options.c_cflag &= ~CSTOPB;
224 options.c_iflag |= (INPCK | ISTRIP);
228 options.c_cflag &= ~PARENB;
229 options.c_cflag &= ~CSTOPB;
238 struct termios options;
243 switch (new_flowcontrol) {
246 options.c_cflag |= CNEW_RTSCTS;
250 options.c_iflag &= ~(IXON | IXOFF | IXANY);
253 options.c_iflag |= (IXON | IXOFF | IXANY);
254 options.c_cc[VSTART] =
XON;
255 options.c_cc[VSTOP] =
XOFF;
257 options.c_cflag &= ~CNEW_RTSCTS;
261 options.c_iflag |= (IXON | IXOFF | IXANY);
262 options.c_cc[VSTART] =
XON;
263 options.c_cc[VSTOP] =
XOFF;
265 options.c_cflag |= CNEW_RTSCTS;
273 options.c_cflag &= ~CNEW_RTSCTS;
275 options.c_iflag &= ~(IXON | IXOFF | IXANY);
284 struct termios options;
291 options.c_cflag &= ~CSTOPB;
294 options.c_cflag |= CSTOPB;
307 struct termios options;
313 options.c_lflag |= (ICANON | ECHO | ECHOE);
320 struct termios options;
326 options.c_oflag |= OPOST;
333 struct termios options;
339 options.c_oflag &= ~OPOST;
346 struct termios options;
352 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
361 struct termios options;
367 options.c_oflag |= OPOST;
368 options.c_oflag |= ONLCR;
378 log->
error(
"Error with tcsetattr = %s", strerror(errno));
389 log->
error(
"Error with tcgetattr = %s", strerror(errno));
uint32_t set_baudrate(uint32_t new_baudrate)
Set baudrate of the UART.
err_t set_options(struct termios *options)
Set options to the file description of the UART.
err_t canonical_input()
Set input to Canonical.
err_t set_word_length(word_length_t word_length)
Set UART data bits length.
err_t processed_output()
Process output before sending it (enabled c_oflag)
err_t _set_word_length(word_length_t word_length) override
Set UART data bits length.
err_t _set_parity(parity_t parity_bit) override
Set parity bit.
uint32_t _set_baudrate(uint32_t new_baudrate) override
Set baudrate of the UART.
err_t set_parity(parity_t parity_bit)
Set parity bit.
size_t _write(uint8_t *data, size_t dataSize) override
write data to the link/bus.
aruna::log::channel_t * log
size_t _read(uint8_t *buffer, size_t buffer_size) override
Read bytes and out them in the buffer.
POSIX_UART(char *port, uint32_t baudrate)
err_t get_options(struct termios *options)
Get options of the file description UART device.
err_t raw_output()
Disabled output processing (disabled c_oflag)
err_t _set_stop_bit(stop_bit_t stop_bit) override
set stop bit
int error(const char *format,...)
log error message
err_t map_NL_to_CRNL()
Map Newline to CR-NL for output.
err_t _set_flowcontrol(flowcontrol_t new_flowcontrol) override
Set software or hardware flowcontrol.
err_t set_flowcontrol(flowcontrol_t new_flowcontrol)
Set software or hardware flowcontrol.
static const comm::port_t port
static const uint8_t XOFF
err_t raw_input()
Set input to raw.