support non standard bauds on mac and a new option to send/clear(manually) break

This commit is contained in:
amit verma 2021-03-14 18:41:34 +05:30
parent 3a1fd79fcb
commit 625f6781af
3 changed files with 32 additions and 7 deletions

View file

@ -103,6 +103,8 @@ In session, the following key sequences are intercepted as tio commands:
List available key commands
.IP "\fBctrl-t b"
Send serial break (triggers SysRq on Linux, etc.)
.IP "\fBctrl-t B"
Send serial break and clear manually
.IP "\fBctrl-t c"
Show configuration (baudrate, databits, etc.)
.IP "\fBctrl-t e"

View file

@ -24,6 +24,7 @@
#define KEY_QUESTION 0x3f
#define KEY_B 0x62
#define KEY_SHIFT_B 0x42
#define KEY_C 0x63
#define KEY_E 0x65
#define KEY_H 0x68

View file

@ -44,6 +44,10 @@
#include "tio/log.h"
#include "tio/error.h"
#ifdef __APPLE__
#include <IOKit/serial/ioss.h>
#endif
#ifdef HAVE_TERMIOS2
extern int setspeed2(int fd, int baudrate);
#endif
@ -61,6 +65,8 @@ static bool map_o_cr_nl = false;
static bool map_o_nl_crnl = false;
static bool map_o_del_bs = false;
static bool break_state = false;
#define tio_printf(format, args...) \
{ \
if (tainted) putchar('\n'); \
@ -135,6 +141,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
tio_printf("Key commands:");
tio_printf(" ctrl-t ? List available key commands");
tio_printf(" ctrl-t b Send break");
tio_printf(" ctrl-t B Send break and clear manually");
tio_printf(" ctrl-t c Show configuration");
tio_printf(" ctrl-t e Toggle local echo mode");
tio_printf(" ctrl-t h Toggle hexadecimal mode");
@ -173,6 +180,12 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
case KEY_B:
tcsendbreak(fd, 0);
break_state = false;
break;
case KEY_SHIFT_B:
break_state = !break_state;
ioctl(fd, break_state ? TIOCSBRK : TIOCCBRK, NULL);
break;
case KEY_C:
@ -366,7 +379,7 @@ void tty_configure(void)
AUTOCONF_BAUDRATE_CASES
default:
#ifdef HAVE_TERMIOS2
#if defined HAVE_TERMIOS2 || __APPLE__
standard_baudrate = false;
break;
#else
@ -671,6 +684,13 @@ int tty_connect(void)
first = false;
}
/* Initially set old speed instead of zero in case of non standard baudrate */
if (!standard_baudrate)
{
cfsetispeed(&tio, cfgetispeed(&tio_old));
cfsetospeed(&tio, cfgetospeed(&tio_old));
}
/* Activate new port settings */
status = tcsetattr(fd, TCSANOW, &tio);
if (status == -1)
@ -679,16 +699,17 @@ int tty_connect(void)
goto error_tcsetattr;
}
#ifdef HAVE_TERMIOS2
if (!standard_baudrate)
{
#ifdef HAVE_TERMIOS2
if (setspeed2(fd, option.baudrate) != 0)
{
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
goto error_setspeed2;
}
}
#elif defined __APPLE__
speed_t speed = option.baudrate;
if (ioctl(fd, IOSSIOSPEED, &speed) == -1)
goto error_setspeed2;
#endif
}
maxfd = MAX(fd, STDIN_FILENO) + 1; /* Maximum bit entry (fd) to test */
@ -827,8 +848,9 @@ int tty_connect(void)
return TIO_SUCCESS;
#ifdef HAVE_TERMIOS2
#if defined HAVE_TERMIOS2 || defined __APPLE__
error_setspeed2:
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
#endif
error_tcsetattr:
error_tcgetattr: