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

Move cfset{i,o}speed() calls to set_baudrate().

This commit is contained in:
Martin Ling 2013-11-14 20:30:26 +00:00
parent a46f0960a2
commit cbf628c7fe

View File

@ -51,7 +51,6 @@ struct sp_port_data {
DCB dcb; DCB dcb;
#else #else
struct termios term; struct termios term;
speed_t baud;
int rts; int rts;
int dtr; int dtr;
#endif #endif
@ -563,69 +562,77 @@ static int set_baudrate(struct sp_port_data *data, int baudrate)
return SP_ERR_ARG; return SP_ERR_ARG;
} }
#else #else
speed_t baud;
switch (baudrate) { switch (baudrate) {
case 50: case 50:
data->baud = B50; baud = B50;
break; break;
case 75: case 75:
data->baud = B75; baud = B75;
break; break;
case 110: case 110:
data->baud = B110; baud = B110;
break; break;
case 134: case 134:
data->baud = B134; baud = B134;
break; break;
case 150: case 150:
data->baud = B150; baud = B150;
break; break;
case 200: case 200:
data->baud = B200; baud = B200;
break; break;
case 300: case 300:
data->baud = B300; baud = B300;
break; break;
case 600: case 600:
data->baud = B600; baud = B600;
break; break;
case 1200: case 1200:
data->baud = B1200; baud = B1200;
break; break;
case 1800: case 1800:
data->baud = B1800; baud = B1800;
break; break;
case 2400: case 2400:
data->baud = B2400; baud = B2400;
break; break;
case 4800: case 4800:
data->baud = B4800; baud = B4800;
break; break;
case 9600: case 9600:
data->baud = B9600; baud = B9600;
break; break;
case 19200: case 19200:
data->baud = B19200; baud = B19200;
break; break;
case 38400: case 38400:
data->baud = B38400; baud = B38400;
break; break;
case 57600: case 57600:
data->baud = B57600; baud = B57600;
break; break;
case 115200: case 115200:
data->baud = B115200; baud = B115200;
break; break;
case 230400: case 230400:
data->baud = B230400; baud = B230400;
break; break;
#if !defined(__APPLE__) && !defined(__OpenBSD__) #if !defined(__APPLE__) && !defined(__OpenBSD__)
case 460800: case 460800:
data->baud = B460800; baud = B460800;
break; break;
#endif #endif
default: default:
return SP_ERR_ARG; return SP_ERR_ARG;
} }
if (cfsetospeed(&data->term, baud) < 0)
return SP_ERR_FAIL;
if (cfsetispeed(&data->term, baud) < 0)
return SP_ERR_FAIL;
#endif #endif
return SP_OK; return SP_OK;
} }
@ -792,12 +799,6 @@ static int apply_config(struct sp_port *port, struct sp_port_data *data)
if (tcsetattr(port->fd, TCSADRAIN, &data->term) < 0) if (tcsetattr(port->fd, TCSADRAIN, &data->term) < 0)
return SP_ERR_FAIL; return SP_ERR_FAIL;
if (cfsetospeed(&data->term, data->baud) < 0)
return SP_ERR_FAIL;
if (cfsetispeed(&data->term, data->baud) < 0)
return SP_ERR_FAIL;
if (data->rts != -1) { if (data->rts != -1) {
controlbits = TIOCM_RTS; controlbits = TIOCM_RTS;
if (ioctl(port->fd, data->rts ? TIOCMBIS : TIOCMBIC, if (ioctl(port->fd, data->rts ? TIOCMBIS : TIOCMBIC,