mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add support for hexidecimal mode
A new key command 'ctrl-t h' is introduced which toggles between hexidecial mode and normal mode. When in hexidecimal mode data received will be printed in hexidecimal.
This commit is contained in:
parent
7ae62d6030
commit
3457446a04
3 changed files with 47 additions and 1 deletions
|
|
@ -74,6 +74,8 @@ List available key commands
|
||||||
Send serial break (triggers SysRq on Linux, etc.)
|
Send serial break (triggers SysRq on Linux, etc.)
|
||||||
.IP "\fBctrl-t c"
|
.IP "\fBctrl-t c"
|
||||||
Show configuration (baudrate, databits, etc.)
|
Show configuration (baudrate, databits, etc.)
|
||||||
|
.IP "\fBctrl-t h"
|
||||||
|
Toggle hexidecimal mode
|
||||||
.IP "\fBctrl-t l"
|
.IP "\fBctrl-t l"
|
||||||
Clear screen
|
Clear screen
|
||||||
.IP "\fBctrl-t q"
|
.IP "\fBctrl-t q"
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,16 @@
|
||||||
#define KEY_QUESTION 0x3f
|
#define KEY_QUESTION 0x3f
|
||||||
#define KEY_B 0x62
|
#define KEY_B 0x62
|
||||||
#define KEY_C 0x63
|
#define KEY_C 0x63
|
||||||
|
#define KEY_H 0x68
|
||||||
#define KEY_L 0x6C
|
#define KEY_L 0x6C
|
||||||
#define KEY_Q 0x71
|
#define KEY_Q 0x71
|
||||||
#define KEY_S 0x73
|
#define KEY_S 0x73
|
||||||
#define KEY_T 0x74
|
#define KEY_T 0x74
|
||||||
#define KEY_CTRL_T 0x14
|
#define KEY_CTRL_T 0x14
|
||||||
|
|
||||||
|
#define NORMAL 0
|
||||||
|
#define HEX 1
|
||||||
|
|
||||||
void stdout_configure(void);
|
void stdout_configure(void);
|
||||||
void stdout_restore(void);
|
void stdout_restore(void);
|
||||||
void tty_configure(void);
|
void tty_configure(void);
|
||||||
|
|
|
||||||
42
src/tty.c
42
src/tty.c
|
|
@ -47,6 +47,8 @@ static unsigned long rx_total = 0, tx_total = 0;
|
||||||
static bool connected = false;
|
static bool connected = false;
|
||||||
static bool tainted = false;
|
static bool tainted = false;
|
||||||
static int fd;
|
static int fd;
|
||||||
|
static bool print_mode = NORMAL;
|
||||||
|
static void (*print)(char c);
|
||||||
|
|
||||||
#define tio_printf(format, args...) \
|
#define tio_printf(format, args...) \
|
||||||
{ \
|
{ \
|
||||||
|
|
@ -55,6 +57,16 @@ static int fd;
|
||||||
tainted = false; \
|
tainted = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_hex(char c)
|
||||||
|
{
|
||||||
|
printf("%02x ", (unsigned char) c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_normal(char c)
|
||||||
|
{
|
||||||
|
putchar(c);
|
||||||
|
}
|
||||||
|
|
||||||
void handle_command_sequence(char input_char, char previous_char, char *output_char, bool *forward)
|
void handle_command_sequence(char input_char, char previous_char, char *output_char, bool *forward)
|
||||||
{
|
{
|
||||||
char unused_char;
|
char unused_char;
|
||||||
|
|
@ -78,16 +90,19 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
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 c Show configuration");
|
tio_printf(" ctrl-t c Show configuration");
|
||||||
|
tio_printf(" ctrl-t h Toggle hexidecimal mode");
|
||||||
tio_printf(" ctrl-t l Clear screen");
|
tio_printf(" ctrl-t l Clear screen");
|
||||||
tio_printf(" ctrl-t q Quit");
|
tio_printf(" ctrl-t q Quit");
|
||||||
tio_printf(" ctrl-t s Show statistics");
|
tio_printf(" ctrl-t s Show statistics");
|
||||||
tio_printf(" ctrl-t t Send ctrl-t key code");
|
tio_printf(" ctrl-t t Send ctrl-t key code");
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_B:
|
case KEY_B:
|
||||||
tcsendbreak(fd, 0);
|
tcsendbreak(fd, 0);
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_C:
|
case KEY_C:
|
||||||
tio_printf("Configuration:");
|
tio_printf("Configuration:");
|
||||||
tio_printf(" TTY device: %s", option.tty_device);
|
tio_printf(" TTY device: %s", option.tty_device);
|
||||||
|
|
@ -101,23 +116,45 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
tio_printf(" Log file: %s", option.log_filename);
|
tio_printf(" Log file: %s", option.log_filename);
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KEY_H:
|
||||||
|
/* Toggle hexidecimal printing mode */
|
||||||
|
if (print_mode == NORMAL)
|
||||||
|
{
|
||||||
|
print = print_hex;
|
||||||
|
print_mode = HEX;
|
||||||
|
tio_printf("Switched to hexidecimal mode");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print = print_normal;
|
||||||
|
print_mode = NORMAL;
|
||||||
|
tio_printf("Switched to normal mode");
|
||||||
|
}
|
||||||
|
*forward = false;
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_L:
|
case KEY_L:
|
||||||
status = system("clear");
|
status = system("clear");
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
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);
|
||||||
|
|
||||||
case KEY_S:
|
case KEY_S:
|
||||||
/* Show tx/rx statistics upon ctrl-t s sequence */
|
/* Show tx/rx statistics upon ctrl-t s sequence */
|
||||||
tio_printf("Statistics:");
|
tio_printf("Statistics:");
|
||||||
tio_printf(" Sent %lu bytes, received %lu bytes", tx_total, rx_total);
|
tio_printf(" Sent %lu bytes, received %lu bytes", tx_total, rx_total);
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_T:
|
case KEY_T:
|
||||||
/* Send ctrl-t key code upon ctrl-t t sequence */
|
/* Send ctrl-t key code upon ctrl-t t sequence */
|
||||||
*output_char = KEY_CTRL_T;
|
*output_char = KEY_CTRL_T;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Ignore unknown ctrl-t escaped keys */
|
/* Ignore unknown ctrl-t escaped keys */
|
||||||
*forward = false;
|
*forward = false;
|
||||||
|
|
@ -162,6 +199,9 @@ void stdout_configure(void)
|
||||||
tio_printf("tio v%s", VERSION);
|
tio_printf("tio v%s", VERSION);
|
||||||
tio_printf("Press ctrl-t q to quit");
|
tio_printf("Press ctrl-t q to quit");
|
||||||
|
|
||||||
|
/* At start use normal print function */
|
||||||
|
print = print_normal;
|
||||||
|
|
||||||
/* Make sure we restore old stdout settings on exit */
|
/* Make sure we restore old stdout settings on exit */
|
||||||
atexit(&stdout_restore);
|
atexit(&stdout_restore);
|
||||||
}
|
}
|
||||||
|
|
@ -459,7 +499,7 @@ int tty_connect(void)
|
||||||
rx_total++;
|
rx_total++;
|
||||||
|
|
||||||
/* Print received tty character to stdout */
|
/* Print received tty character to stdout */
|
||||||
putchar(input_char);
|
print(input_char);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
/* Write to log */
|
/* Write to log */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue