diff options
author | Guido Günther <agx@sigxcpu.org> | 2014-02-05 08:38:23 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-02-05 08:38:23 +0100 |
commit | dc645b92b9a7db3076ae34986ac219d01677d124 (patch) | |
tree | 963a5d6ad150a88a2a8ab6d994d79d539e19383a /libqcdm/src/com.c | |
parent | 87bd9deec22af69bb27226254803ac5c63b18d78 (diff) |
Imported Upstream version 0.4+git.20100624t180933.6e79d15upstream/0.4+git.20100624t180933.6e79d15
Diffstat (limited to 'libqcdm/src/com.c')
-rw-r--r-- | libqcdm/src/com.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libqcdm/src/com.c b/libqcdm/src/com.c new file mode 100644 index 0000000..353103a --- /dev/null +++ b/libqcdm/src/com.c @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2010 Red Hat, Inc. + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <errno.h> +#include <termios.h> +#include <fcntl.h> +#include <string.h> + +#include "com.h" +#include "error.h" + +gboolean +qcdm_port_setup (int fd, GError **error) +{ + struct termios stbuf; + + g_type_init (); + + errno = 0; + memset (&stbuf, 0, sizeof (stbuf)); + if (tcgetattr (fd, &stbuf) != 0) { + g_set_error (error, + QCDM_SERIAL_ERROR, QCDM_SERIAL_CONFIG_FAILED, + "tcgetattr() error: %d", errno); + } + + stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB); + stbuf.c_iflag &= ~(HUPCL | IUTF8 | IUCLC | ISTRIP | IXON | IXOFF | IXANY | ICRNL); + stbuf.c_oflag &= ~(OPOST | OCRNL | ONLCR | OLCUC | ONLRET); + stbuf.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHONL); + stbuf.c_lflag &= ~(NOFLSH | XCASE | TOSTOP | ECHOPRT | ECHOCTL | ECHOKE); + stbuf.c_cc[VMIN] = 1; + stbuf.c_cc[VTIME] = 0; + stbuf.c_cc[VEOF] = 1; + stbuf.c_cflag |= (B115200 | CS8 | CREAD | 0 | 0); /* No parity, 1 stop bit */ + + errno = 0; + if (tcsetattr (fd, TCSANOW, &stbuf) < 0) { + g_set_error (error, + QCDM_SERIAL_ERROR, QCDM_SERIAL_CONFIG_FAILED, + "tcsetattr() error: %d", errno); + return FALSE; + } + + return TRUE; +} + |