From fca5429ae7e00ad155796912ae66711d1ff8c944 Mon Sep 17 00:00:00 2001 From: arichi Date: Mon, 13 May 2019 23:52:23 +0800 Subject: [PATCH 1/5] Flush every local echo char Flush stdout at every char in case it happens to be buffered. --- src/tty.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tty.c b/src/tty.c index bee6f9f..9706789 100644 --- a/src/tty.c +++ b/src/tty.c @@ -535,6 +535,7 @@ static void optional_local_echo(char c) if (!option.local_echo) return; print(c); + fflush(stdout); if (option.log) log_write(c); } From a84f762106c2b546f2a02165c1f2a7fdc12f02b4 Mon Sep 17 00:00:00 2001 From: Sylvain LAFRASSE Date: Fri, 24 May 2019 10:46:02 +0200 Subject: [PATCH 2/5] Resolved tio/tio#84: Added timestamps in log file if enabled. --- src/tty.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tty.c b/src/tty.c index bee6f9f..1ada628 100644 --- a/src/tty.c +++ b/src/tty.c @@ -548,6 +548,7 @@ int tty_connect(void) static bool first = true; int status; time_t next_timestamp = 0; + char* now = NULL; /* Open tty device */ #ifdef __APPLE__ @@ -641,7 +642,19 @@ int tty_connect(void) /* Print timestamp on new line, if desired. */ if (next_timestamp && input_char != '\n' && input_char != '\r') { - fprintf(stdout, ANSI_COLOR_GRAY "[%s] " ANSI_COLOR_RESET, current_time()); + now = current_time(); + fprintf(stdout, ANSI_COLOR_GRAY "[%s] " ANSI_COLOR_RESET, now); + if (option.log) + { + log_write('['); + while (*now != '\0') + { + log_write(*now); + ++now; + } + log_write(']'); + log_write(' '); + } next_timestamp = 0; } From 04d92740f58a3d3651c2e7a69870ec756a6c55db Mon Sep 17 00:00:00 2001 From: George Stark Date: Thu, 19 Sep 2019 15:13:38 +0300 Subject: [PATCH 3/5] add serial lines manual control --- man/tio.1 | 6 +++++ src/include/tio/tty.h | 3 +++ src/tty.c | 52 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/man/tio.1 b/man/tio.1 index 566e22c..cdb0295 100644 --- a/man/tio.1 +++ b/man/tio.1 @@ -117,6 +117,12 @@ Quit Show TX/RX statistics .IP "\fBctrl-t t" Send ctrl-t key code +.IP "\fBctrl-t L" +Show lines state (DTR, RTS, CTS, DSR, DCD, RI) +.IP "\fBctrl-t d" +Toggle DTR +.IP "\fBctrl-t r" +Toggle RTS .IP "\fBctrl-t v" Show version diff --git a/src/include/tio/tty.h b/src/include/tio/tty.h index 6226263..44a80a4 100644 --- a/src/include/tio/tty.h +++ b/src/include/tio/tty.h @@ -34,6 +34,9 @@ #define KEY_SHIFT_T 0x54 #define KEY_CTRL_T 0x14 #define KEY_V 0x76 +#define KEY_D 0x64 +#define KEY_R 0x72 +#define KEY_SHIFT_L 0x4C #define NORMAL 0 #define HEX 1 diff --git a/src/tty.c b/src/tty.c index bee6f9f..ae6f1a9 100644 --- a/src/tty.c +++ b/src/tty.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -69,7 +70,7 @@ static bool map_o_del_bs = false; static void print_hex(char c) { - printf("%02x ", (unsigned char) c); + printf("%02x ", (unsigned char)c); } static void print_normal(char c) @@ -77,10 +78,36 @@ static void print_normal(char c) putchar(c); } +static void toggle_line(const char *line_name, int mask) +{ + int state; + + if (ioctl(fd, TIOCMGET, &state) < 0) + { + error_printf("Could not get line state: %s", strerror(errno)); + } + else + { + if (state & mask) + { + state &= ~mask; + tio_printf("set %s to LOW", line_name); + } + else + { + state |= mask; + tio_printf("set %s to HIGH", line_name); + } + if (ioctl(fd, TIOCMSET, &state) < 0) + error_printf("Could not set line state: %s", strerror(errno)); + } +} + void handle_command_sequence(char input_char, char previous_char, char *output_char, bool *forward) { char unused_char; bool unused_bool; + int state; /* Ignore unused arguments */ if (output_char == NULL) @@ -109,9 +136,32 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c tio_printf(" ctrl-t s Show statistics"); tio_printf(" ctrl-t t Send ctrl-t key code"); tio_printf(" ctrl-t T Toggle timestamps"); + tio_printf(" ctrl-t L Show lines"); + tio_printf(" ctrl-t d Toggle DTR"); + tio_printf(" ctrl-t r Toggle RTS"); tio_printf(" ctrl-t v Show version"); break; + case KEY_SHIFT_L: + if (ioctl(fd, TIOCMGET, &state) < 0) + error_printf("Could not get line state: %s", strerror(errno)); + tio_printf("Lines state:"); + + tio_printf(" DTR: %s", (state & TIOCM_DTR) ? "HIGH" : "LOW"); + tio_printf(" RTS: %s", (state & TIOCM_RTS) ? "HIGH" : "LOW"); + tio_printf(" CTS: %s", (state & TIOCM_CTS) ? "HIGH" : "LOW"); + tio_printf(" DSR: %s", (state & TIOCM_DSR) ? "HIGH" : "LOW"); + tio_printf(" DCD: %s", (state & TIOCM_CD) ? "HIGH" : "LOW"); + tio_printf(" RI : %s", (state & TIOCM_RI) ? "HIGH" : "LOW"); + break; + case KEY_D: + toggle_line("DTR", TIOCM_DTR); + break; + + case KEY_R: + toggle_line("RTS", TIOCM_RTS); + break; + case KEY_B: tcsendbreak(fd, 0); break; From 5217d9842bb7b24fa553b4ce7456b73269ae2fe5 Mon Sep 17 00:00:00 2001 From: George Stark Date: Thu, 19 Sep 2019 17:39:01 +0300 Subject: [PATCH 4/5] dont show line state if ioctl failed --- src/tty.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tty.c b/src/tty.c index ae6f1a9..3b40e08 100644 --- a/src/tty.c +++ b/src/tty.c @@ -144,9 +144,11 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c case KEY_SHIFT_L: if (ioctl(fd, TIOCMGET, &state) < 0) + { error_printf("Could not get line state: %s", strerror(errno)); + break; + } tio_printf("Lines state:"); - tio_printf(" DTR: %s", (state & TIOCM_DTR) ? "HIGH" : "LOW"); tio_printf(" RTS: %s", (state & TIOCM_RTS) ? "HIGH" : "LOW"); tio_printf(" CTS: %s", (state & TIOCM_CTS) ? "HIGH" : "LOW"); From 4d4ee466f777724766ff8c5dd4fb6335a5053210 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Tue, 8 Oct 2019 22:05:07 -0400 Subject: [PATCH 5/5] Disable line buffering in stdout In order for local echo to work properly, we have to either call fflush(stdout) after every character or just disable line buffering. This change uses setbuf(stdout, NULL) to do the latter. Closes #92 --- src/tty.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tty.c b/src/tty.c index bee6f9f..afef44b 100644 --- a/src/tty.c +++ b/src/tty.c @@ -234,6 +234,10 @@ void stdout_configure(void) { int status; + /* Disable line buffering in stdout. This is necessary if we + * want things like local echo to work correctly. */ + setbuf(stdout, NULL); + /* Save current stdout settings */ if (tcgetattr(STDOUT_FILENO, &stdout_old) < 0) {