Added key command for showing session settings

A new key command "ctrl-t i" is added to allow the user to display the
various session settings information (baudrate, databits, log file, etc.).

This is usefull in case you have a running session but have forgotten
what the settings are.
This commit is contained in:
Martin Lund 2016-05-18 15:29:09 +02:00
parent d180b9f336
commit ffe87bc566
5 changed files with 40 additions and 9 deletions

View file

@ -61,6 +61,8 @@ Display help.
.PP .PP
.TP 16n .TP 16n
In session, the following key sequences are intercepted as tio commands: In session, the following key sequences are intercepted as tio commands:
.IP "\fBctrl-t i"
Show session settings information (baudrate, databits, etc.)
.IP "\fBctrl-t q" .IP "\fBctrl-t q"
Quit Quit
.IP "\fBctrl-t s" .IP "\fBctrl-t s"
@ -70,11 +72,11 @@ Send ctrl-t key code
.SH "EXAMPLES" .SH "EXAMPLES"
.TP .TP
The most common use is without options. For example: A typical use is without options. For example:
tio /dev/ttyUSB0 tio /dev/ttyUSB0
.TP .TP
Which corresponds to: Which corresponds to the commonly used options:
tio \-b 115200 \-d 8 \-f none \-s 1 \-p none /dev/ttyUSB0 tio \-b 115200 \-d 8 \-f none \-s 1 \-p none /dev/ttyUSB0
.TP .TP

View file

@ -36,6 +36,11 @@ struct option_t
bool no_autoconnect; bool no_autoconnect;
int output_delay; int output_delay;
struct termios tio; struct termios tio;
int baudrate;
int databits;
char *flow;
int stopbits;
char *parity;
}; };
extern struct option_t option; extern struct option_t option;

View file

@ -22,6 +22,7 @@
#ifndef TTY_H #ifndef TTY_H
#define TTY_H #define TTY_H
#define KEY_I 0x69
#define KEY_Q 0x71 #define KEY_Q 0x71
#define KEY_S 0x73 #define KEY_S 0x73
#define KEY_T 0x74 #define KEY_T 0x74

View file

@ -39,6 +39,12 @@ struct option_t option =
"", // Log filename "", // Log filename
false, // No autoconnect false, // No autoconnect
0, // No output delay 0, // No output delay
{},
115200, // Baudrate
8, // Databits
"none", // Flow
1, // Stopbits
"none" // Parity
}; };
void print_options_help(char *argv[]) void print_options_help(char *argv[])
@ -65,8 +71,6 @@ void parse_options(int argc, char *argv[])
{ {
int c; int c;
int baudrate; int baudrate;
int databits;
int stopbits;
if (argc == 1) if (argc == 1)
{ {
@ -122,7 +126,7 @@ void parse_options(int argc, char *argv[])
break; break;
case 'b': case 'b':
baudrate = atoi(optarg); option.baudrate = baudrate = atoi(optarg);
switch (baudrate) switch (baudrate)
{ {
case 0: case 0:
@ -223,9 +227,9 @@ void parse_options(int argc, char *argv[])
break; break;
case 'd': case 'd':
databits = atoi(optarg); option.databits = atoi(optarg);
option.tio.c_cflag &= ~CSIZE; option.tio.c_cflag &= ~CSIZE;
switch (databits) switch (option.databits)
{ {
case 5: case 5:
option.tio.c_cflag |= CS5; option.tio.c_cflag |= CS5;
@ -246,6 +250,8 @@ void parse_options(int argc, char *argv[])
break; break;
case 'f': case 'f':
option.flow = optarg;
if (strcmp("hard", optarg) == 0) if (strcmp("hard", optarg) == 0)
{ {
option.tio.c_cflag |= CRTSCTS; option.tio.c_cflag |= CRTSCTS;
@ -269,8 +275,8 @@ void parse_options(int argc, char *argv[])
break; break;
case 's': case 's':
stopbits = atoi(optarg); option.stopbits = atoi(optarg);
switch (stopbits) switch (option.stopbits)
{ {
case 1: case 1:
option.tio.c_cflag &= ~CSTOPB; option.tio.c_cflag &= ~CSTOPB;
@ -285,6 +291,8 @@ void parse_options(int argc, char *argv[])
break; break;
case 'p': case 'p':
option.parity = optarg;
if (strcmp("odd", optarg) == 0) if (strcmp("odd", optarg) == 0)
{ {
option.tio.c_cflag |= PARENB; option.tio.c_cflag |= PARENB;

View file

@ -62,6 +62,21 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
{ {
switch (input_char) switch (input_char)
{ {
case KEY_I:
if (tainted)
putchar('\n');
color_printf("[tio %s] TTY device: %s", current_time(), option.tty_device);
color_printf("[tio %s] Baudrate: %d", current_time(), option.baudrate);
color_printf("[tio %s] Databits: %d", current_time(), option.databits);
color_printf("[tio %s] Flow: %s", current_time(), option.flow);
color_printf("[tio %s] Stopbits: %d", current_time(), option.stopbits);
color_printf("[tio %s] Parity: %s", current_time(), option.parity);
color_printf("[tio %s] Output delay: %d", current_time(), option.output_delay);
if (option.log)
color_printf("[tio %s] Log file: %s", current_time(), option.log_filename);
tainted = false;
*forward = false;
break;
case KEY_Q: case KEY_Q:
/* Exit upon ctrl-t q sequence */ /* Exit upon ctrl-t q sequence */
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);