17 #if !USE_ARBITRARY_BAUDRATE
20 #include <linux/termios.h>
25 #define B100000 100000
32 case B1200:
return 1200;
33 case B2400:
return 2400;
34 case B4800:
return 4800;
35 case B9600:
return 9600;
57 #define UPARITY_EVEN 2
71 #define TRACE(type,fmt,args...)
86 #if !USE_ARBITRARY_BAUDRATE
94 if (tcflush(me->
fd, TCIFLUSH)) {
95 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n",
"", strerror(errno), errno);
96 fprintf(stderr,
"flush (%d) failed: %s (%d)\n", me->
fd, strerror(errno), errno);
105 if (tcflush(me->
fd, TCOFLUSH)) {
106 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n",
"", strerror(errno), errno);
107 fprintf(stderr,
"flush (%d) failed: %s (%d)\n", me->
fd, strerror(errno), errno);
113 if ((me->
fd = open(device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
114 TRACE(
TRACE_ERROR,
"%s, open failed: %s (%d)\n", device, strerror(errno), errno);
118 TRACE(
TRACE_ERROR,
"%s, get term settings failed: %s (%d)\n", device, strerror(errno), errno);
124 me->
cur_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
125 | ICRNL |
IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
128 me->
cur_termios.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | PARODD | HUPCL | CSTOPB);
131 me->
cur_termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | FLUSHO | PENDIN);
134 me->
cur_termios.c_oflag &=~(OPOST|ONLCR|OCRNL|ONOCR|ONLRET);
140 TRACE(
TRACE_ERROR,
"%s, set term speed failed: %s (%d)\n", device, strerror(errno), errno);
145 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n", device, strerror(errno), errno);
154 void(*term_conf_callback)(
struct termios *, speed_t *))
158 if ((me->
fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
159 TRACE(
TRACE_ERROR,
"%s, open failed: %s (%d)\n", device, strerror(errno), errno);
163 TRACE(
TRACE_ERROR,
"%s, get term settings failed: %s (%d)\n", device, strerror(errno), errno);
170 TRACE(
TRACE_ERROR,
"%s, set term speed failed: %s (%d)\n", device, strerror(errno), errno);
175 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n", device, strerror(errno), errno);
188 if (!me || me->
fd < 0) {
191 if (tcflush(me->
fd, TCIOFLUSH)) {
197 TRACE(
TRACE_ERROR,
"restoring term attributes (%s) (%d)\n", strerror(errno), errno);
213 if (!me || me->
fd < 0) {
217 TRACE(
TRACE_ERROR,
"%s, set term speed failed: %s (%d)\n", device, strerror(errno), errno);
227 if (!me || me->
fd < 0) {
255 TRACE(
TRACE_ERROR,
"setting term attributes (%s) (%d)\n", strerror(errno), errno);
261 #else // USE_ARBITRARY_BAUDRATE
266 int ioctl(
int d,
int request, ...);
267 int tcflush (
int __fd,
int __queue_selector);
274 if (tcflush(me->
fd, TCIFLUSH)) {
275 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n",
"", strerror(errno), errno);
276 fprintf(stderr,
"flush (%d) failed: %s (%d)\n", me->
fd, strerror(errno), errno);
285 if (tcflush(me->
fd, TCOFLUSH)) {
286 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n",
"", strerror(errno), errno);
287 fprintf(stderr,
"flush (%d) failed: %s (%d)\n", me->
fd, strerror(errno), errno);
293 if ((me->
fd = open(device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
294 TRACE(
TRACE_ERROR,
"%s, open failed: %s (%d)\n", device, strerror(errno), errno);
306 me->
cur_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
307 | ICRNL |
IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
310 me->
cur_termios.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | PARODD | HUPCL | CSTOPB);
313 me->
cur_termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | FLUSHO | PENDIN);
316 me->
cur_termios.c_oflag &=~(OPOST|ONLCR|OCRNL|ONOCR|ONLRET);
344 void(*term_conf_callback)(
struct termios *, speed_t *))
348 (void)term_conf_callback;
356 if (!me || me->
fd < 0) {
359 if (tcflush(me->
fd, TCIOFLUSH)) {
365 TRACE(
TRACE_ERROR,
"restoring term attributes (%s) (%d)\n", strerror(errno), errno);
381 if (!me || me->
fd < 0) {
403 if (!me || me->
fd < 0) {