Merge branch 'osx-baudrate' of https://github.com/robey/tio into robey-osx-baudrate

This commit is contained in:
Martin Lund 2022-02-16 05:24:35 +01:00
commit 7ffeeccdf5
4 changed files with 70 additions and 6 deletions

View file

@ -11,8 +11,15 @@ version_date = '2022-02-15'
# Test for dynamic baudrate configuration interface # Test for dynamic baudrate configuration interface
compiler = meson.get_compiler('c') compiler = meson.get_compiler('c')
enable_setspeed2 = false enable_setspeed2 = false
if compiler.check_header('asm-generic/ioctls.h') enable_iossiospeed = false
enable_setspeed2 = compiler.has_header_symbol('asm-generic/ioctls.h', 'TCGETS2') if host_machine.system() != 'darwin'
if compiler.check_header('asm-generic/ioctls.h')
enable_setspeed2 = compiler.has_header_symbol('asm-generic/ioctls.h', 'TCGETS2')
endif
else
if compiler.check_header('IOKit/serial/ioss.h')
enable_iossiospeed = compiler.has_header_symbol('IOKit/serial/ioss.h', 'IOSSIOSPEED')
endif
endif endif
# Test for supported baudrates # Test for supported baudrates

28
src/iossiospeed.c Normal file
View file

@ -0,0 +1,28 @@
/*
* tio - a simple TTY terminal I/O application
*
* Copyright (c) 2017 Martin Lund
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <sys/ioctl.h>
#include <IOKit/serial/ioss.h>
int iossiospeed(int fd, int baudrate)
{
return ioctl(fd, IOSSIOSPEED, (char *)&baudrate);
}

View file

@ -20,6 +20,11 @@ if enable_setspeed2
tio_c_args += '-DHAVE_TERMIOS2' tio_c_args += '-DHAVE_TERMIOS2'
endif endif
if enable_iossiospeed
tio_sources += 'iossiospeed.c'
tio_c_args += '-DHAVE_IOSSIOSPEED'
endif
executable('tio', executable('tio',
tio_sources, tio_sources,
c_args: tio_c_args, c_args: tio_c_args,

View file

@ -49,6 +49,10 @@
extern int setspeed2(int fd, int baudrate); extern int setspeed2(int fd, int baudrate);
#endif #endif
#ifdef HAVE_IOSSIOSPEED
extern int iossiospeed(int fd, int baudrate);
#endif
#ifdef __APPLE__ #ifdef __APPLE__
#define PATH_SERIAL_DEVICES "/dev/" #define PATH_SERIAL_DEVICES "/dev/"
#else #else
@ -347,7 +351,7 @@ void tty_configure(void)
BAUDRATE_CASES BAUDRATE_CASES
default: default:
#ifdef HAVE_TERMIOS2 #if defined (HAVE_TERMIOS2) || defined (HAVE_IOSSIOSPEED)
standard_baudrate = false; standard_baudrate = false;
break; break;
#else #else
@ -647,6 +651,15 @@ int tty_connect(void)
if (tcgetattr(fd, &tio_old) < 0) if (tcgetattr(fd, &tio_old) < 0)
goto error_tcgetattr; goto error_tcgetattr;
#ifdef HAVE_IOSSIOSPEED
if (!standard_baudrate)
{
/* OS X wants these fields left alone. We'll set baudrate with iossiospeed below. */
tio.c_ispeed = tio_old.c_ispeed;
tio.c_ospeed = tio_old.c_ospeed;
}
#endif
/* Make sure we restore tty settings on exit */ /* Make sure we restore tty settings on exit */
if (first) if (first)
{ {
@ -668,7 +681,18 @@ int tty_connect(void)
if (setspeed2(fd, option.baudrate) != 0) if (setspeed2(fd, option.baudrate) != 0)
{ {
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno)); error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
goto error_setspeed2; goto error_setspeed;
}
}
#endif
#ifdef HAVE_IOSSIOSPEED
if (!standard_baudrate)
{
if (iossiospeed(fd, option.baudrate) != 0)
{
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
goto error_setspeed;
} }
} }
#endif #endif
@ -815,8 +839,8 @@ int tty_connect(void)
return TIO_SUCCESS; return TIO_SUCCESS;
#ifdef HAVE_TERMIOS2 #if defined (HAVE_TERMIOS2) || defined (HAVE_IOSSIOSPEED)
error_setspeed2: error_setspeed:
#endif #endif
error_tcsetattr: error_tcsetattr:
error_tcgetattr: error_tcgetattr: