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){
log_error("read zero bytes\n");
return;
exit(EXIT_FAILURE);
}
if (bytes_read < 0) {
log_error("read returned error\n");
return;
exit(EXIT_FAILURE);
}
btstack_uart_block_read_bytes_len -= bytes_read;
@ -176,13 +176,13 @@ static int btstack_uart_posix_set_baudrate(uint32_t baudrate){
case 9600: brate=B9600; break;
case 19200: brate=B19200; break;
case 38400: brate=B38400; break;
case 57600: brate=B57600; break;
case 115200: brate=B115200; break;
case 57600: brate=B57600; break;
case 115200: brate=B115200; break;
#ifdef B230400
case 230400: brate=B230400; break;
case 230400: brate=B230400; break;
#endif
#ifdef B460800
case 460800: brate=B460800; break;
case 460800: brate=B460800; break;
#endif
#ifdef B500000
case 500000: brate=B500000; break;
@ -191,7 +191,7 @@ static int btstack_uart_posix_set_baudrate(uint32_t baudrate){
case 576000: brate=B576000; break;
#endif
#ifdef B921600
case 921600: brate=B921600; break;
case 921600: brate=B921600; break;
#endif
#ifdef B1000000
case 1000000: brate=B1000000; break;
@ -311,12 +311,12 @@ static int btstack_uart_posix_open(void){
int fd = open(device_name, flags);
if (fd == -1) {
log_error("Unable to open port %s", device_name);
return -1;
exit(EXIT_FAILURE);
}
if (tcgetattr(fd, &btstack_uart_block_termios) < 0) {
log_error("Couldn't get term attributes");
return -1;
exit(EXIT_FAILURE);
}
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) {
log_error("Couldn't set term attributes");
return -1;
exit(EXIT_FAILURE);
}
// store fd in data source
@ -347,7 +347,7 @@ static int btstack_uart_posix_open(void){
// also set baudrate
if (btstack_uart_posix_set_baudrate(baudrate) < 0){
return -1;
exit(EXIT_FAILURE);
}
// set up data_source