예제 #1
0
파일: gattty.c 프로젝트: AndriusA/ofono
static int open_device(const char *tty, GHashTable *options)
{
	struct termios ti;
	int fd;

	/* Switch TTY to raw mode */
	memset(&ti, 0, sizeof(ti));
	cfmakeraw(&ti);

	if (options) {
		GHashTableIter iter;
		const char *key;
		const char *value;

		g_hash_table_iter_init (&iter, options);
		while (g_hash_table_iter_next(&iter, (void *) &key,
							(void *) &value)) {
			gboolean ok = FALSE;

			if (g_str_equal(key, "Baud"))
				ok = set_baud(value, &ti);
			else if (g_str_equal(key, "StopBits"))
				ok = set_stop_bits(value, &ti);
			else if (g_str_equal(key, "DataBits"))
				ok = set_data_bits(value, &ti);
			else if (g_str_equal(key, "Parity"))
				ok = set_parity(value, &ti);
			else if (g_str_equal(key, "XonXoff"))
				ok = set_xonxoff(value, &ti);
			else if (g_str_equal(key, "RtsCts"))
				ok = set_rtscts(value, &ti);
			else if (g_str_equal(key, "Local"))
				ok = set_local(value, &ti);
			else if (g_str_equal(key, "Read"))
				ok = set_read(value, &ti);

			if (ok == FALSE)
				return -1;
		}
	}

	fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (fd < 0)
		return -1;

	tcflush(fd, TCIOFLUSH);
	tcsetattr(fd, TCSANOW, &ti);

	return fd;
}
예제 #2
0
serial::err
serial_port_x86::open(void)
{
    disable_interrupt_mode();

    set_baud_rate(m_baud);
    set_parity_mode(m_parity);
    set_data_size(m_data_size);
    set_stop_bits(m_stop_bits);
    enable_fifo();

    enable_interrupt_mode(m_interrupt_mode);

    return serial::success;
}