From a8103b898376d3fe1dd747656229473eeebce47a Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Tue, 17 May 2016 16:08:19 +0200 Subject: [PATCH] Added simple tx/rx statistics command (ctrl-t s) To display the total number of bytes transmitted/received simply perform the 'ctrl-t s' command sequence. This feature can be useful when eg. trying to detect non-printable characters. --- man/tio.1 | 2 ++ src/include/tio/tty.h | 3 ++- src/tty.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/man/tio.1 b/man/tio.1 index 5e4e1d7..953ecf5 100644 --- a/man/tio.1 +++ b/man/tio.1 @@ -63,6 +63,8 @@ Display help. In session, the following key sequences are intercepted as tio commands: .IP "\fBctrl-t q" Quit +.IP "\fBctrl-t s" +Show session statistics (total number of bytes transmitted/received) .IP "\fBctrl-t t" Send ctrl-t key code diff --git a/src/include/tio/tty.h b/src/include/tio/tty.h index 9324dfd..cab663e 100644 --- a/src/include/tio/tty.h +++ b/src/include/tio/tty.h @@ -22,9 +22,10 @@ #ifndef TTY_H #define TTY_H -#define KEY_CTRL_T 0x14 #define KEY_Q 0x71 +#define KEY_S 0x73 #define KEY_T 0x74 +#define KEY_CTRL_T 0x14 void configure_stdout(void); void restore_stdout(void); diff --git a/src/tty.c b/src/tty.c index 845334f..9687eda 100644 --- a/src/tty.c +++ b/src/tty.c @@ -40,6 +40,7 @@ #include "tio/error.h" static struct termios new_stdout, old_stdout, old_tio; +static long rx_total = 0, tx_total = 0; static bool connected = false; static bool tainted = false; static int fd; @@ -244,6 +245,9 @@ int connect_tty(void) /* Input from tty device ready */ if (read(fd, &input_char, 1) > 0) { + /* Update receive statistics */ + rx_total++; + /* Print received tty character to stdout */ putchar(input_char); fflush(stdout); @@ -253,6 +257,7 @@ int connect_tty(void) log_write(input_char); tainted = true; + } else { /* Error reading - device is likely unplugged */ @@ -289,6 +294,11 @@ int connect_tty(void) /* Send ctrl-t key code upon ctrl-t t sequence */ output_char = KEY_CTRL_T; break; + case KEY_S: + /* Show tx/rx statistics upon ctrl-t s sequence */ + color_printf("[tio %s] Sent %ld bytes, received %ld bytes", current_time(), tx_total, rx_total); + forward = false; + break; default: /* Ignore unknown ctrl-t escaped keys */ forward = false; @@ -306,6 +316,9 @@ int connect_tty(void) /* Write to log */ if (option.log) log_write(output_char); + + /* Update transmit statistics */ + tx_total++; } /* Save previous key */