mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
support non standard bauds on mac and a new option to send/clear(manually) break
This commit is contained in:
parent
3a1fd79fcb
commit
625f6781af
3 changed files with 32 additions and 7 deletions
|
|
@ -103,6 +103,8 @@ In session, the following key sequences are intercepted as tio commands:
|
||||||
List available key commands
|
List available key commands
|
||||||
.IP "\fBctrl-t b"
|
.IP "\fBctrl-t b"
|
||||||
Send serial break (triggers SysRq on Linux, etc.)
|
Send serial break (triggers SysRq on Linux, etc.)
|
||||||
|
.IP "\fBctrl-t B"
|
||||||
|
Send serial break and clear manually
|
||||||
.IP "\fBctrl-t c"
|
.IP "\fBctrl-t c"
|
||||||
Show configuration (baudrate, databits, etc.)
|
Show configuration (baudrate, databits, etc.)
|
||||||
.IP "\fBctrl-t e"
|
.IP "\fBctrl-t e"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#define KEY_QUESTION 0x3f
|
#define KEY_QUESTION 0x3f
|
||||||
#define KEY_B 0x62
|
#define KEY_B 0x62
|
||||||
|
#define KEY_SHIFT_B 0x42
|
||||||
#define KEY_C 0x63
|
#define KEY_C 0x63
|
||||||
#define KEY_E 0x65
|
#define KEY_E 0x65
|
||||||
#define KEY_H 0x68
|
#define KEY_H 0x68
|
||||||
|
|
|
||||||
36
src/tty.c
36
src/tty.c
|
|
@ -44,6 +44,10 @@
|
||||||
#include "tio/log.h"
|
#include "tio/log.h"
|
||||||
#include "tio/error.h"
|
#include "tio/error.h"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <IOKit/serial/ioss.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS2
|
#ifdef HAVE_TERMIOS2
|
||||||
extern int setspeed2(int fd, int baudrate);
|
extern int setspeed2(int fd, int baudrate);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -61,6 +65,8 @@ static bool map_o_cr_nl = false;
|
||||||
static bool map_o_nl_crnl = false;
|
static bool map_o_nl_crnl = false;
|
||||||
static bool map_o_del_bs = false;
|
static bool map_o_del_bs = false;
|
||||||
|
|
||||||
|
static bool break_state = false;
|
||||||
|
|
||||||
#define tio_printf(format, args...) \
|
#define tio_printf(format, args...) \
|
||||||
{ \
|
{ \
|
||||||
if (tainted) putchar('\n'); \
|
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("Key commands:");
|
||||||
tio_printf(" ctrl-t ? List available key commands");
|
tio_printf(" ctrl-t ? List available key commands");
|
||||||
tio_printf(" ctrl-t b Send break");
|
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 c Show configuration");
|
||||||
tio_printf(" ctrl-t e Toggle local echo mode");
|
tio_printf(" ctrl-t e Toggle local echo mode");
|
||||||
tio_printf(" ctrl-t h Toggle hexadecimal 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:
|
case KEY_B:
|
||||||
tcsendbreak(fd, 0);
|
tcsendbreak(fd, 0);
|
||||||
|
break_state = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_SHIFT_B:
|
||||||
|
break_state = !break_state;
|
||||||
|
ioctl(fd, break_state ? TIOCSBRK : TIOCCBRK, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_C:
|
case KEY_C:
|
||||||
|
|
@ -366,7 +379,7 @@ void tty_configure(void)
|
||||||
AUTOCONF_BAUDRATE_CASES
|
AUTOCONF_BAUDRATE_CASES
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_TERMIOS2
|
#if defined HAVE_TERMIOS2 || __APPLE__
|
||||||
standard_baudrate = false;
|
standard_baudrate = false;
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
|
|
@ -671,6 +684,13 @@ int tty_connect(void)
|
||||||
first = false;
|
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 */
|
/* Activate new port settings */
|
||||||
status = tcsetattr(fd, TCSANOW, &tio);
|
status = tcsetattr(fd, TCSANOW, &tio);
|
||||||
if (status == -1)
|
if (status == -1)
|
||||||
|
|
@ -679,16 +699,17 @@ int tty_connect(void)
|
||||||
goto error_tcsetattr;
|
goto error_tcsetattr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS2
|
|
||||||
if (!standard_baudrate)
|
if (!standard_baudrate)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_TERMIOS2
|
||||||
if (setspeed2(fd, option.baudrate) != 0)
|
if (setspeed2(fd, option.baudrate) != 0)
|
||||||
{
|
|
||||||
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
|
|
||||||
goto error_setspeed2;
|
goto error_setspeed2;
|
||||||
}
|
#elif defined __APPLE__
|
||||||
}
|
speed_t speed = option.baudrate;
|
||||||
|
if (ioctl(fd, IOSSIOSPEED, &speed) == -1)
|
||||||
|
goto error_setspeed2;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
maxfd = MAX(fd, STDIN_FILENO) + 1; /* Maximum bit entry (fd) to test */
|
maxfd = MAX(fd, STDIN_FILENO) + 1; /* Maximum bit entry (fd) to test */
|
||||||
|
|
||||||
|
|
@ -827,8 +848,9 @@ int tty_connect(void)
|
||||||
|
|
||||||
return TIO_SUCCESS;
|
return TIO_SUCCESS;
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS2
|
#if defined HAVE_TERMIOS2 || defined __APPLE__
|
||||||
error_setspeed2:
|
error_setspeed2:
|
||||||
|
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
error_tcsetattr:
|
error_tcsetattr:
|
||||||
error_tcgetattr:
|
error_tcgetattr:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue