Cheetah Software  1.0
rt_serial.cpp
Go to the documentation of this file.
1 
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 
12 #define termios asmtermios
13 
14 #include <asm/termios.h>
15 
16 #undef termios
17 
18 #include <termios.h>
19 
20 #include <errno.h>
21 #include <math.h>
22 #include <pthread.h>
23 
24 #include <stropts.h>
25 
26 #include <endian.h>
27 
28 #include <stdint.h>
29 
30 #include <rt/rt_serial.h>
31 
40 int set_interface_attribs_custom_baud(int fd, int speed, int parity, int port) {
41  (void)parity;
42  (void)port;
43 
44  printf("\t[RT SERIAL] Configuring serial device...\n");
45  struct termios2 tty;
46 
47  ioctl(fd, TCGETS2, &tty);
48  tty.c_cflag &= ~CBAUD;
49  tty.c_cflag |= BOTHER;
50  tty.c_ispeed = speed;
51  tty.c_ospeed = speed;
52 
53  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
54  // disable IGNBRK for mismatched speed tests; otherwise receive break
55  // as \000 chars
56  tty.c_iflag &= ~IGNBRK; // disable break processing
57  tty.c_lflag = 0; // no signaling chars, no echo,
58  // no canonical processing
59  tty.c_oflag = 0; // no remapping, no delays
60  tty.c_cc[VMIN] = 0; // read doesn't block
61  tty.c_cc[VTIME] = 1; // 0.5 seconds read timeout
62 
63  tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
64 
65  tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,
66  // enable reading
67  // tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
68  tty.c_cflag |= PARENB;
69  tty.c_cflag &= ~CSTOPB;
70  tty.c_cflag &= ~CRTSCTS;
71  // cfmakeraw(&tty);
72 
73  ioctl(fd, TCSETS2, &tty);
74  return 0;
75 }
int set_interface_attribs_custom_baud(int fd, int speed, int parity, int port)
Configure serial port.
Definition: rt_serial.cpp:40