return sizeof(struct termiox);
}
-int get_termiox_flow(void *data)
+int get_termiox_flow(void *data, int *rts, int *cts, int *dtr, int *dsr)
{
struct termiox *termx = (struct termiox *) data;
int flags = 0;
- if (termx->x_cflag & RTSXOFF)
- flags |= RTS_FLOW;
- if (termx->x_cflag & CTSXON)
- flags |= CTS_FLOW;
- if (termx->x_cflag & DTRXOFF)
- flags |= DTR_FLOW;
- if (termx->x_cflag & DSRXON)
- flags |= DSR_FLOW;
+ *rts = (termx->x_cflag & RTSXOFF);
+ *cts = (termx->x_cflag & CTSXON);
+ *dtr = (termx->x_cflag & DTRXOFF);
+ *dsr = (termx->x_cflag & DSRXON);
return flags;
}
-void set_termiox_flow(void *data, int flags)
+void set_termiox_flow(void *data, int rts, int cts, int dtr, int dsr)
{
struct termiox *termx = (struct termiox *) data;
termx->x_cflag &= ~(RTSXOFF | CTSXON | DTRXOFF | DSRXON);
- if (flags & RTS_FLOW)
+ if (rts)
termx->x_cflag |= RTSXOFF;
- if (flags & CTS_FLOW)
+ if (cts)
termx->x_cflag |= CTSXON;
- if (flags & DTR_FLOW)
+ if (dtr)
termx->x_cflag |= DTRXOFF;
- if (flags & DSR_FLOW)
+ if (dsr)
termx->x_cflag |= DSRXON;
}
#endif
#define TIOCOUTQ FIONWRITE
#endif
-#ifndef _WIN32
-#include "linux_termios.h"
-#endif
-
#include "libserialport.h"
struct sp_port {
struct termios term;
int controlbits;
int termiox_supported;
- int flow;
+ int rts_flow;
+ int cts_flow;
+ int dtr_flow;
+ int dsr_flow;
#endif
};
}
#ifdef USE_TERMIOX
-static enum sp_return get_flow(int fd, int *flow)
+static enum sp_return get_flow(int fd, struct port_data *data)
{
- void *data;
+ void *termx;
- TRACE("%d, %p", fd, flow);
+ TRACE("%d, %p", fd, data);
DEBUG("Getting advanced flow control");
- if (!(data = malloc(get_termiox_size())))
+ if (!(termx = malloc(get_termiox_size())))
RETURN_ERROR(SP_ERR_MEM, "termiox malloc failed");
- if (ioctl(fd, TCGETX, data) < 0) {
- free(data);
+ if (ioctl(fd, TCGETX, termx) < 0) {
+ free(termx);
RETURN_FAIL("getting termiox failed");
}
- *flow = get_termiox_flow(data);
+ get_termiox_flow(termx, &data->rts_flow, &data->cts_flow,
+ &data->dtr_flow, &data->dsr_flow);
- free(data);
+ free(termx);
RETURN_OK();
}
-static enum sp_return set_flow(int fd, int flow)
+static enum sp_return set_flow(int fd, struct port_data *data)
{
- void *data;
+ void *termx;
- TRACE("%d, %d", fd, flow);
+ TRACE("%d, %p", fd, data);
DEBUG("Getting advanced flow control");
- if (!(data = malloc(get_termiox_size())))
+ if (!(termx = malloc(get_termiox_size())))
RETURN_ERROR(SP_ERR_MEM, "termiox malloc failed");
- if (ioctl(fd, TCGETX, data) < 0) {
- free(data);
+ if (ioctl(fd, TCGETX, termx) < 0) {
+ free(termx);
RETURN_FAIL("getting termiox failed");
}
DEBUG("Setting advanced flow control");
- set_termiox_flow(data, flow);
+ set_termiox_flow(termx, data->rts_flow, data->cts_flow,
+ data->dtr_flow, data->dsr_flow);
- if (ioctl(fd, TCSETX, data) < 0) {
- free(data);
+ if (ioctl(fd, TCSETX, termx) < 0) {
+ free(termx);
RETURN_FAIL("setting termiox failed");
}
- free(data);
+ free(termx);
RETURN_OK();
}
RETURN_FAIL("TIOCMGET ioctl failed");
#ifdef USE_TERMIOX
- int ret = get_flow(port->fd, &data->flow);
+ int ret = get_flow(port->fd, data);
if (ret == SP_ERR_FAIL && errno == EINVAL)
data->termiox_supported = 0;
config->rts = SP_RTS_FLOW_CONTROL;
config->cts = SP_CTS_FLOW_CONTROL;
} else {
- if (data->termiox_supported && data->flow & RTS_FLOW)
+ if (data->termiox_supported && data->rts_flow)
config->rts = SP_RTS_FLOW_CONTROL;
else
config->rts = (data->controlbits & TIOCM_RTS) ? SP_RTS_ON : SP_RTS_OFF;
- config->cts = (data->termiox_supported && data->flow & CTS_FLOW) ?
+ config->cts = (data->termiox_supported && data->cts_flow) ?
SP_CTS_FLOW_CONTROL : SP_CTS_IGNORE;
}
- if (data->termiox_supported && data->flow & DTR_FLOW)
+ if (data->termiox_supported && data->dtr_flow)
config->dtr = SP_DTR_FLOW_CONTROL;
else
config->dtr = (data->controlbits & TIOCM_DTR) ? SP_DTR_ON : SP_DTR_OFF;
- config->dsr = (data->termiox_supported && data->flow & DSR_FLOW) ?
+ config->dsr = (data->termiox_supported && data->dsr_flow) ?
SP_DSR_FLOW_CONTROL : SP_DSR_IGNORE;
if (data->term.c_iflag & IXOFF) {
if (config->rts >= 0 || config->cts >= 0) {
if (data->termiox_supported) {
- data->flow &= ~(RTS_FLOW | CTS_FLOW);
+ data->rts_flow = data->cts_flow = 0;
switch (config->rts) {
case SP_RTS_OFF:
case SP_RTS_ON:
RETURN_FAIL("Setting RTS signal level failed");
break;
case SP_RTS_FLOW_CONTROL:
- data->flow |= RTS_FLOW;
+ data->rts_flow = 1;
break;
default:
break;
}
if (config->cts == SP_CTS_FLOW_CONTROL)
- data->flow |= CTS_FLOW;
+ data->cts_flow = 1;
- if (data->flow & (RTS_FLOW | CTS_FLOW))
+ if (data->rts_flow && data->cts_flow)
data->term.c_iflag |= CRTSCTS;
else
data->term.c_iflag &= ~CRTSCTS;
if (config->dtr >= 0 || config->dsr >= 0) {
if (data->termiox_supported) {
- data->flow &= ~(DTR_FLOW | DSR_FLOW);
+ data->dtr_flow = data->dsr_flow = 0;
switch (config->dtr) {
case SP_DTR_OFF:
case SP_DTR_ON:
RETURN_FAIL("Setting DTR signal level failed");
break;
case SP_DTR_FLOW_CONTROL:
- data->flow |= DTR_FLOW;
+ data->dtr_flow = 1;
break;
default:
break;
}
if (config->dsr == SP_DSR_FLOW_CONTROL)
- data->flow |= DSR_FLOW;
+ data->dsr_flow = 1;
} else {
/* DTR/DSR flow control not supported. */
if (config->dtr == SP_DTR_FLOW_CONTROL || config->dsr == SP_DSR_FLOW_CONTROL)
TRY(set_baudrate(port->fd, config->baudrate));
#ifdef USE_TERMIOX
if (data->termiox_supported)
- TRY(set_flow(port->fd, data->flow));
+ TRY(set_flow(port->fd, data));
#endif
#endif