Added autodetection of available baud rates

Various platforms supports different baud rates.

To avoid adding platform specific handling generic baud rate detection
tests are introduced in the configure script. Successfully detected baud
rates are automatically enabled. This applies to both the C code and the
bash completion script.

Note:
Baud rates below 57600 are defined by POSIX-1 and supported by most
platforms so only baud rate 57600 and above are tested.
This commit is contained in:
Martin Lund 2016-05-26 08:59:18 +02:00
parent f4cba8ebfb
commit 8eb0e6d874
5 changed files with 70 additions and 0 deletions

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ src/include/config.h.in~
src/include/stamp-h1 src/include/stamp-h1
*.swp *.swp
/tio-* /tio-*
/src/bash-completion/tio

View file

@ -25,6 +25,23 @@ fi
AC_SUBST([BASH_COMPLETION_DIR]) AC_SUBST([BASH_COMPLETION_DIR])
AM_CONDITIONAL([ENABLE_BASH_COMPLETION],[test "x$with_bash_completion_dir" != "xno"]) AM_CONDITIONAL([ENABLE_BASH_COMPLETION],[test "x$with_bash_completion_dir" != "xno"])
# Check for available terminal I/O speeds
AC_CHECK_DECL([B57600], [AC_SUBST([B57600],["57600"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B115200], [AC_SUBST([B115200],["115200"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B230400], [AC_SUBST([B230400],["230400"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B460800], [AC_SUBST([B460800],["460800"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B500000], [AC_SUBST([B500000],["500000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B576000], [AC_SUBST([B576000],["576000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B921600], [AC_SUBST([B921600],["921600"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B1000000], [AC_SUBST([B1000000],["1000000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B1152000], [AC_SUBST([B1152000],["1152000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B1500000], [AC_SUBST([B1500000],["1500000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B2000000], [AC_SUBST([B2000000],["2000000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B2500000], [AC_SUBST([B2500000],["2500000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B3000000], [AC_SUBST([B3000000],["3000000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B3500000], [AC_SUBST([B3500000],["3500000"])], [], [[#include <termios.h>]])
AC_CHECK_DECL([B4000000], [AC_SUBST([B4000000],["4000000"])], [], [[#include <termios.h>]])
AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([man/Makefile]) AC_CONFIG_FILES([man/Makefile])

View file

@ -14,6 +14,28 @@ tio_SOURCES = tty.c \
include/tio/error.h include/tio/error.h
if ENABLE_BASH_COMPLETION if ENABLE_BASH_COMPLETION
CLEANFILES = bash-completion/tio
do_subst = sed -e 's/57600 /$(B57600) /g' \
-e 's/115200 /$(B115200) /g' \
-e 's/230400 /$(B230400) /g' \
-e 's/460800 /$(B460800) /g' \
-e 's/500000 /$(B500000) /g' \
-e 's/576000 /$(B576000) /g' \
-e 's/921600 /$(B921600) /g' \
-e 's/1000000 /$(B1000000) /g' \
-e 's/1152000 /$(B1152000) /g' \
-e 's/1500000 /$(B1500000) /g' \
-e 's/2000000 /$(B2000000) /g' \
-e 's/2500000 /$(B2500000) /g' \
-e 's/3000000 /$(B3000000) /g' \
-e 's/3500000 /$(B3500000) /g' \
-e 's/4000000/$(B4000000)/g'
bash-completion/tio: bash-completion/tio.in
$(do_subst) < bash-completion/tio.in > bash-completion/tio
bashcompletiondir=@BASH_COMPLETION_DIR@ bashcompletiondir=@BASH_COMPLETION_DIR@
dist_bashcompletion_DATA=bash-completion/tio dist_bashcompletion_DATA=bash-completion/tio
endif endif

View file

@ -211,51 +211,81 @@ void tty_configure(void)
case 38400: case 38400:
baudrate = B38400; baudrate = B38400;
break; break;
#ifdef HAVE_DECL_B57600
case 57600: case 57600:
baudrate = B57600; baudrate = B57600;
break; break;
#endif
#ifdef HAVE_DECL_B115200
case 115200: case 115200:
baudrate = B115200; baudrate = B115200;
break; break;
#endif
#ifdef HAVE_DECL_B230400
case 230400: case 230400:
baudrate = B230400; baudrate = B230400;
break; break;
#endif
#ifdef HAVE_DECL_B460800
case 460800: case 460800:
baudrate = B460800; baudrate = B460800;
break; break;
#endif
#ifdef HAVE_DECL_B500000
case 500000: case 500000:
baudrate = B500000; baudrate = B500000;
break; break;
#endif
#ifdef HAVE_DECL_B576000
case 576000: case 576000:
baudrate = B576000; baudrate = B576000;
break; break;
#endif
#ifdef HAVE_DECL_B921600
case 921600: case 921600:
baudrate = B921600; baudrate = B921600;
break; break;
#endif
#ifdef HAVE_DECL_B1000000
case 1000000: case 1000000:
baudrate = B1000000; baudrate = B1000000;
break; break;
#endif
#ifdef HAVE_DECL_B1152000
case 1152000: case 1152000:
baudrate = B1152000; baudrate = B1152000;
break; break;
#endif
#ifdef HAVE_DECL_B1500000
case 1500000: case 1500000:
baudrate = B1500000; baudrate = B1500000;
break; break;
#endif
#ifdef HAVE_DECL_B2000000
case 2000000: case 2000000:
baudrate = B2000000; baudrate = B2000000;
break; break;
#endif
#ifdef HAVE_DECL_B2500000
case 2500000: case 2500000:
baudrate = B2500000; baudrate = B2500000;
break; break;
#endif
#ifdef HAVE_DECL_B3000000
case 3000000: case 3000000:
baudrate = B3000000; baudrate = B3000000;
break; break;
#endif
#ifdef HAVE_DECL_B3500000
case 3500000: case 3500000:
baudrate = B3500000; baudrate = B3500000;
break; break;
#endif
#ifdef HAVE_DECL_B4000000
case 4000000: case 4000000:
baudrate = B4000000; baudrate = B4000000;
break; break;
#endif
default: default:
error_printf("Invalid baud rate"); error_printf("Invalid baud rate");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);