1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

linux: Speed fields may not be present in kernel termios structures.

This commit is contained in:
Martin Ling 2014-01-03 13:38:06 +01:00
parent bd791fe121
commit 5cea279a85
3 changed files with 18 additions and 9 deletions

View File

@ -107,6 +107,10 @@ AC_TYPE_SIZE_T
# Check for specific termios structures.
AC_CHECK_TYPE([struct termios2], [AC_DEFINE(HAVE_TERMIOS2, 1)], [], [[#include <linux/termios.h>]])
AC_CHECK_TYPE([struct termiox], [AC_DEFINE(HAVE_TERMIOX, 1)], [], [[#include <linux/termios.h>]])
AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed],
[AC_DEFINE(HAVE_TERMIOS_SPEED, 1)], [], [[#include <linux/termios.h>]])
AC_CHECK_MEMBERS([struct termios2.c_ispeed, struct termios2.c_ospeed],
[AC_DEFINE(HAVE_TERMIOS2_SPEED, 1)], [], [[#include <linux/termios.h>]])
AC_SUBST(MAKEFLAGS, '--no-print-directory')
AC_SUBST(AM_LIBTOOLFLAGS, '--silent')

View File

@ -33,8 +33,6 @@
* TCSETX/TCGETX ioctls used with struct termiox, others do not.
*/
#if defined(__linux__) && !defined(__ANDROID__)
#include <linux/termios.h>
#include "linux_termios.h"
@ -65,6 +63,7 @@ int get_termios_size(void)
#endif
}
#ifdef USE_TERMIOS_SPEED
int get_termios_speed(void *data)
{
#ifdef HAVE_TERMIOS2
@ -89,6 +88,7 @@ void set_termios_speed(void *data, int speed)
term->c_cflag |= BOTHER;
term->c_ispeed = term->c_ospeed = speed;
}
#endif
#ifdef HAVE_TERMIOX
int get_termiox_size(void)
@ -125,5 +125,3 @@ void set_termiox_flow(void *data, int rts, int cts, int dtr, int dsr)
termx->x_cflag |= DSRXON;
}
#endif
#endif

View File

@ -70,6 +70,11 @@
#define TIOCOUTQ FIONWRITE
#endif
/* Non-standard baudrates are not available everywhere. */
#if defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED)
#define USE_TERMIOS_SPEED
#endif
#include "libserialport.h"
struct sp_port {
@ -1458,7 +1463,7 @@ enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout)
#endif
}
#ifdef __linux__
#ifdef USE_TERMIOS_SPEED
static enum sp_return get_baudrate(int fd, int *baudrate)
{
void *data;
@ -1511,6 +1516,7 @@ static enum sp_return set_baudrate(int fd, int baudrate)
RETURN_OK();
}
#endif /* USE_TERMIOS_SPEED */
#ifdef USE_TERMIOX
static enum sp_return get_flow(int fd, struct port_data *data)
@ -1568,7 +1574,6 @@ static enum sp_return set_flow(int fd, struct port_data *data)
RETURN_OK();
}
#endif /* USE_TERMIOX */
#endif /* __linux__ */
static enum sp_return get_config(struct sp_port *port, struct port_data *data,
struct sp_port_config *config)
@ -1705,7 +1710,7 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data,
if (i == NUM_STD_BAUDRATES) {
#ifdef __APPLE__
config->baudrate = (int)data->term.c_ispeed;
#elif defined(__linux__)
#elif defined(USE_TERMIOS_SPEED)
TRY(get_baudrate(port->fd, &config->baudrate));
#else
config->baudrate = -1;
@ -1788,7 +1793,7 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data,
baud_nonstd = B0;
#endif
#ifdef __linux__
#ifdef USE_TERMIOS_SPEED
int baud_nonstd = 0;
#endif
@ -1955,7 +1960,7 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data,
if (cfsetspeed(&data->term, B9600) < 0)
RETURN_FAIL("cfsetspeed() failed");
baud_nonstd = config->baudrate;
#elif defined(__linux__)
#elif defined(USE_TERMIOS_SPEED)
baud_nonstd = 1;
#else
RETURN_ERROR(SP_ERR_SUPP, "Non-standard baudrate not supported");
@ -2151,8 +2156,10 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data,
RETURN_FAIL("cfsetspeed() failed");
}
#elif defined(__linux__)
#ifdef USE_TERMIOS_SPEED
if (baud_nonstd)
TRY(set_baudrate(port->fd, config->baudrate));
#endif
#ifdef USE_TERMIOX
if (data->termiox_supported)
TRY(set_flow(port->fd, data));