platform/posix: exit on none existing uart device, terminate if uart is unplugged

This commit is contained in:
Dirk Helbig 2025-03-04 12:39:55 +01:00
parent 683d7c6847
commit 7bab55ed9a

View File

@ -145,11 +145,11 @@ static void btstack_uart_block_posix_process_read(btstack_data_source_t *ds) {
} }
if (bytes_read == 0){ if (bytes_read == 0){
log_error("read zero bytes\n"); log_error("read zero bytes\n");
return; exit(EXIT_FAILURE);
} }
if (bytes_read < 0) { if (bytes_read < 0) {
log_error("read returned error\n"); log_error("read returned error\n");
return; exit(EXIT_FAILURE);
} }
btstack_uart_block_read_bytes_len -= bytes_read; btstack_uart_block_read_bytes_len -= bytes_read;
@ -311,12 +311,12 @@ static int btstack_uart_posix_open(void){
int fd = open(device_name, flags); int fd = open(device_name, flags);
if (fd == -1) { if (fd == -1) {
log_error("Unable to open port %s", device_name); log_error("Unable to open port %s", device_name);
return -1; exit(EXIT_FAILURE);
} }
if (tcgetattr(fd, &btstack_uart_block_termios) < 0) { if (tcgetattr(fd, &btstack_uart_block_termios) < 0) {
log_error("Couldn't get term attributes"); log_error("Couldn't get term attributes");
return -1; exit(EXIT_FAILURE);
} }
cfmakeraw(&btstack_uart_block_termios); // make raw cfmakeraw(&btstack_uart_block_termios); // make raw
@ -339,7 +339,7 @@ static int btstack_uart_posix_open(void){
if(tcsetattr(fd, TCSANOW, &btstack_uart_block_termios) < 0) { if(tcsetattr(fd, TCSANOW, &btstack_uart_block_termios) < 0) {
log_error("Couldn't set term attributes"); log_error("Couldn't set term attributes");
return -1; exit(EXIT_FAILURE);
} }
// store fd in data source // store fd in data source
@ -347,7 +347,7 @@ static int btstack_uart_posix_open(void){
// also set baudrate // also set baudrate
if (btstack_uart_posix_set_baudrate(baudrate) < 0){ if (btstack_uart_posix_set_baudrate(baudrate) < 0){
return -1; exit(EXIT_FAILURE);
} }
// set up data_source // set up data_source