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:
parent
bd791fe121
commit
5cea279a85
@ -107,6 +107,10 @@ AC_TYPE_SIZE_T
|
|||||||
# Check for specific termios structures.
|
# Check for specific termios structures.
|
||||||
AC_CHECK_TYPE([struct termios2], [AC_DEFINE(HAVE_TERMIOS2, 1)], [], [[#include <linux/termios.h>]])
|
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_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(MAKEFLAGS, '--no-print-directory')
|
||||||
AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
|
AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
|
||||||
|
@ -33,8 +33,6 @@
|
|||||||
* TCSETX/TCGETX ioctls used with struct termiox, others do not.
|
* TCSETX/TCGETX ioctls used with struct termiox, others do not.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__linux__) && !defined(__ANDROID__)
|
|
||||||
|
|
||||||
#include <linux/termios.h>
|
#include <linux/termios.h>
|
||||||
#include "linux_termios.h"
|
#include "linux_termios.h"
|
||||||
|
|
||||||
@ -65,6 +63,7 @@ int get_termios_size(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_TERMIOS_SPEED
|
||||||
int get_termios_speed(void *data)
|
int get_termios_speed(void *data)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_TERMIOS2
|
#ifdef HAVE_TERMIOS2
|
||||||
@ -89,6 +88,7 @@ void set_termios_speed(void *data, int speed)
|
|||||||
term->c_cflag |= BOTHER;
|
term->c_cflag |= BOTHER;
|
||||||
term->c_ispeed = term->c_ospeed = speed;
|
term->c_ispeed = term->c_ospeed = speed;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOX
|
#ifdef HAVE_TERMIOX
|
||||||
int get_termiox_size(void)
|
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;
|
termx->x_cflag |= DSRXON;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
17
serialport.c
17
serialport.c
@ -70,6 +70,11 @@
|
|||||||
#define TIOCOUTQ FIONWRITE
|
#define TIOCOUTQ FIONWRITE
|
||||||
#endif
|
#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"
|
#include "libserialport.h"
|
||||||
|
|
||||||
struct sp_port {
|
struct sp_port {
|
||||||
@ -1458,7 +1463,7 @@ enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef USE_TERMIOS_SPEED
|
||||||
static enum sp_return get_baudrate(int fd, int *baudrate)
|
static enum sp_return get_baudrate(int fd, int *baudrate)
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
@ -1511,6 +1516,7 @@ static enum sp_return set_baudrate(int fd, int baudrate)
|
|||||||
|
|
||||||
RETURN_OK();
|
RETURN_OK();
|
||||||
}
|
}
|
||||||
|
#endif /* USE_TERMIOS_SPEED */
|
||||||
|
|
||||||
#ifdef USE_TERMIOX
|
#ifdef USE_TERMIOX
|
||||||
static enum sp_return get_flow(int fd, struct port_data *data)
|
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();
|
RETURN_OK();
|
||||||
}
|
}
|
||||||
#endif /* USE_TERMIOX */
|
#endif /* USE_TERMIOX */
|
||||||
#endif /* __linux__ */
|
|
||||||
|
|
||||||
static enum sp_return get_config(struct sp_port *port, struct port_data *data,
|
static enum sp_return get_config(struct sp_port *port, struct port_data *data,
|
||||||
struct sp_port_config *config)
|
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) {
|
if (i == NUM_STD_BAUDRATES) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
config->baudrate = (int)data->term.c_ispeed;
|
config->baudrate = (int)data->term.c_ispeed;
|
||||||
#elif defined(__linux__)
|
#elif defined(USE_TERMIOS_SPEED)
|
||||||
TRY(get_baudrate(port->fd, &config->baudrate));
|
TRY(get_baudrate(port->fd, &config->baudrate));
|
||||||
#else
|
#else
|
||||||
config->baudrate = -1;
|
config->baudrate = -1;
|
||||||
@ -1788,7 +1793,7 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data,
|
|||||||
|
|
||||||
baud_nonstd = B0;
|
baud_nonstd = B0;
|
||||||
#endif
|
#endif
|
||||||
#ifdef __linux__
|
#ifdef USE_TERMIOS_SPEED
|
||||||
int baud_nonstd = 0;
|
int baud_nonstd = 0;
|
||||||
#endif
|
#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)
|
if (cfsetspeed(&data->term, B9600) < 0)
|
||||||
RETURN_FAIL("cfsetspeed() failed");
|
RETURN_FAIL("cfsetspeed() failed");
|
||||||
baud_nonstd = config->baudrate;
|
baud_nonstd = config->baudrate;
|
||||||
#elif defined(__linux__)
|
#elif defined(USE_TERMIOS_SPEED)
|
||||||
baud_nonstd = 1;
|
baud_nonstd = 1;
|
||||||
#else
|
#else
|
||||||
RETURN_ERROR(SP_ERR_SUPP, "Non-standard baudrate not supported");
|
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");
|
RETURN_FAIL("cfsetspeed() failed");
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
#ifdef USE_TERMIOS_SPEED
|
||||||
if (baud_nonstd)
|
if (baud_nonstd)
|
||||||
TRY(set_baudrate(port->fd, config->baudrate));
|
TRY(set_baudrate(port->fd, config->baudrate));
|
||||||
|
#endif
|
||||||
#ifdef USE_TERMIOX
|
#ifdef USE_TERMIOX
|
||||||
if (data->termiox_supported)
|
if (data->termiox_supported)
|
||||||
TRY(set_flow(port->fd, data));
|
TRY(set_flow(port->fd, data));
|
||||||
|
Loading…
Reference in New Issue
Block a user