diff --git a/gatchat/gattty.c b/gatchat/gattty.c index 02ca389d..5ac733c3 100644 --- a/gatchat/gattty.c +++ b/gatchat/gattty.c @@ -250,7 +250,40 @@ GIOChannel *g_at_tty_open(const char *tty, GHashTable *options) return NULL; channel = g_io_channel_unix_new(fd); - + if (channel == NULL) { + close(fd); + return NULL; + } + + g_io_channel_set_close_on_unref(channel, TRUE); + + return channel; +} + +GIOChannel *g_at_tty_open_qcdm(const char *tty) +{ + GIOChannel *channel; + struct termios ti; + int fd; + + fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return NULL; + + /* Switch TTY to raw mode */ + memset(&ti, 0, sizeof(ti)); + cfmakeraw(&ti); + + /* No parity, 1 stop bit */ + ti.c_cflag &= ~(CSIZE | CSTOPB | PARENB); + ti.c_cflag |= (B115200 | CS8); + + if (tcsetattr (fd, TCSANOW, &ti) < 0) { + close(fd); + return NULL; + } + + channel = g_io_channel_unix_new(fd); if (channel == NULL) { close(fd); return NULL; diff --git a/gatchat/gattty.h b/gatchat/gattty.h index dc3fe160..e4d7c31f 100644 --- a/gatchat/gattty.h +++ b/gatchat/gattty.h @@ -43,6 +43,8 @@ extern "C" { */ GIOChannel *g_at_tty_open(const char *tty, GHashTable *options); +GIOChannel *g_at_tty_open_qcdm(const char *tty); + #ifdef __cplusplus } #endif