19 #define TRACE(type,fmt,args...)
39 if (tcflush(me->
fd, TCIFLUSH)) {
40 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n",
"", strerror(errno), errno);
41 fprintf(stderr,
"flush (%d) failed: %s (%d)\n", me->
fd, strerror(errno), errno);
50 if (tcflush(me->
fd, TCOFLUSH)) {
51 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n",
"", strerror(errno), errno);
52 fprintf(stderr,
"flush (%d) failed: %s (%d)\n", me->
fd, strerror(errno), errno);
58 if ((me->
fd = open(device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
59 TRACE(
TRACE_ERROR,
"%s, open failed: %s (%d)\n", device, strerror(errno), errno);
63 TRACE(
TRACE_ERROR,
"%s, get term settings failed: %s (%d)\n", device, strerror(errno), errno);
69 me->
cur_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
70 | ICRNL |
IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
73 me->
cur_termios.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | PARODD | HUPCL | CSTOPB);
76 me->
cur_termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | FLUSHO | PENDIN);
79 me->
cur_termios.c_oflag &=~(OPOST|ONLCR|OCRNL|ONOCR|ONLRET);
82 TRACE(
TRACE_ERROR,
"%s, set term speed failed: %s (%d)\n", device, strerror(errno), errno);
87 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n", device, strerror(errno), errno);
96 void(*term_conf_callback)(
struct termios *, speed_t *))
100 if ((me->
fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
101 TRACE(
TRACE_ERROR,
"%s, open failed: %s (%d)\n", device, strerror(errno), errno);
105 TRACE(
TRACE_ERROR,
"%s, get term settings failed: %s (%d)\n", device, strerror(errno), errno);
112 TRACE(
TRACE_ERROR,
"%s, set term speed failed: %s (%d)\n", device, strerror(errno), errno);
117 TRACE(
TRACE_ERROR,
"%s, set term attr failed: %s (%d)\n", device, strerror(errno), errno);
130 if (!me || me->
fd < 0) {
133 if (tcflush(me->
fd, TCIOFLUSH)) {
139 TRACE(
TRACE_ERROR,
"restoring term attributes (%s) (%d)\n", strerror(errno), errno);
void serial_port_flush_output(struct SerialPort *me)
#define TRACE(type, fmt, args...)
struct termios orig_termios
void serial_port_flush(struct SerialPort *me)
void serial_port_free(struct SerialPort *me)
struct termios cur_termios
struct SerialPort * serial_port_new(void)
void serial_port_close(struct SerialPort *me)
int serial_port_open_raw(struct SerialPort *me, const char *device, speed_t speed)
int serial_port_open(struct SerialPort *me, const char *device, void(*term_conf_callback)(struct termios *, speed_t *))