mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-18 05:42:49 +00:00
posix: only get/set options once for open
This commit is contained in:
parent
cde6b088be
commit
79d9f1ed77
@ -237,20 +237,34 @@ static int btstack_uart_posix_set_baudrate(uint32_t baudrate){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void btstack_uart_posix_set_parity_option(struct termios * toptions, int parity){
|
||||||
|
if (parity){
|
||||||
|
// enable even parity
|
||||||
|
toptions->c_cflag |= PARENB;
|
||||||
|
} else {
|
||||||
|
// disable even parity
|
||||||
|
toptions->c_cflag &= ~PARENB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btstack_uart_posix_set_flowcontrol_option(struct termios * toptions, int flowcontrol){
|
||||||
|
if (flowcontrol) {
|
||||||
|
// with flow control
|
||||||
|
toptions->c_cflag |= CRTSCTS;
|
||||||
|
} else {
|
||||||
|
// no flow control
|
||||||
|
toptions->c_cflag &= ~CRTSCTS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int btstack_uart_posix_set_parity(int parity){
|
static int btstack_uart_posix_set_parity(int parity){
|
||||||
|
|
||||||
int fd = transport_data_source.fd;
|
int fd = transport_data_source.fd;
|
||||||
|
|
||||||
struct termios toptions;
|
struct termios toptions;
|
||||||
if (tcgetattr(fd, &toptions) < 0) {
|
if (tcgetattr(fd, &toptions) < 0) {
|
||||||
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (parity){
|
btstack_uart_posix_set_parity_option(&toptions, parity);
|
||||||
toptions.c_cflag |= PARENB; // enable even parity
|
|
||||||
} else {
|
|
||||||
toptions.c_cflag &= ~PARENB; // disable even parity
|
|
||||||
}
|
|
||||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||||
log_error("posix_set_parity: Couldn't set term attributes");
|
log_error("posix_set_parity: Couldn't set term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
@ -258,22 +272,15 @@ static int btstack_uart_posix_set_parity(int parity){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int btstack_uart_posix_set_flowcontrol(int flowcontrol){
|
static int btstack_uart_posix_set_flowcontrol(int flowcontrol){
|
||||||
|
|
||||||
int fd = transport_data_source.fd;
|
int fd = transport_data_source.fd;
|
||||||
|
|
||||||
struct termios toptions;
|
struct termios toptions;
|
||||||
if (tcgetattr(fd, &toptions) < 0) {
|
if (tcgetattr(fd, &toptions) < 0) {
|
||||||
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
log_error("btstack_uart_posix_set_parity: Couldn't get term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (flowcontrol) {
|
btstack_uart_posix_set_flowcontrol_option(&toptions, flowcontrol);
|
||||||
// with flow control
|
|
||||||
toptions.c_cflag |= CRTSCTS;
|
|
||||||
} else {
|
|
||||||
// no flow control
|
|
||||||
toptions.c_cflag &= ~CRTSCTS;
|
|
||||||
}
|
|
||||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||||
log_error("posix_set_flowcontrol: Couldn't set term attributes");
|
log_error("posix_set_flowcontrol: Couldn't set term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
@ -313,6 +320,12 @@ static int btstack_uart_posix_open(void){
|
|||||||
toptions.c_cc[VMIN] = 1;
|
toptions.c_cc[VMIN] = 1;
|
||||||
toptions.c_cc[VTIME] = 0;
|
toptions.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
|
// no parity
|
||||||
|
btstack_uart_posix_set_parity_option(&toptions, 0);
|
||||||
|
|
||||||
|
// flowcontrol
|
||||||
|
btstack_uart_posix_set_flowcontrol_option(&toptions, flowcontrol);
|
||||||
|
|
||||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||||
log_error("posix_open: Couldn't set term attributes");
|
log_error("posix_open: Couldn't set term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
@ -326,11 +339,6 @@ static int btstack_uart_posix_open(void){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// also set flow control
|
|
||||||
if (btstack_uart_posix_set_flowcontrol(flowcontrol) < 0){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up data_source
|
// set up data_source
|
||||||
btstack_run_loop_set_data_source_fd(&transport_data_source, fd);
|
btstack_run_loop_set_data_source_fd(&transport_data_source, fd);
|
||||||
btstack_run_loop_set_data_source_handler(&transport_data_source, &hci_transport_h5_process);
|
btstack_run_loop_set_data_source_handler(&transport_data_source, &hci_transport_h5_process);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user