From 5b8f33bd78d89c17dee0e4fb89965e2880a3c594 Mon Sep 17 00:00:00 2001 From: Attila Veghelyi Date: Thu, 29 Sep 2022 15:42:44 +0200 Subject: [PATCH 1/2] Add bit reverse order feature --- src/tty.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/tty.c b/src/tty.c index a3f674c..d5fb7af 100644 --- a/src/tty.c +++ b/src/tty.c @@ -84,6 +84,7 @@ #define KEY_H 0x68 #define KEY_L 0x6C #define KEY_SHIFT_L 0x4C +#define KEY_M 0x6D #define KEY_P 0x70 #define KEY_Q 0x71 #define KEY_S 0x73 @@ -126,6 +127,7 @@ static bool map_o_cr_nl = false; static bool map_o_nl_crnl = false; static bool map_o_del_bs = false; static bool map_o_ltu = false; +static bool map_o_msblsb = false; static char hex_chars[2]; static unsigned char hex_char_index = 0; static char tty_buffer[BUFSIZ*2]; @@ -410,6 +412,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c tio_printf(" ctrl-%c h Toggle hexadecimal mode", option.prefix_key); tio_printf(" ctrl-%c l Clear screen", option.prefix_key); tio_printf(" ctrl-%c L Show line states", option.prefix_key); + tio_printf(" ctrl-%c m Toggle MSB to LSB bit order", option.prefix_key); tio_printf(" ctrl-%c p Pulse serial port line", option.prefix_key); tio_printf(" ctrl-%c q Quit", option.prefix_key); tio_printf(" ctrl-%c s Show statistics", option.prefix_key); @@ -498,6 +501,20 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c printf("\033c"); break; + case KEY_M: + /* Toggle bit order */ + if (!map_o_msblsb) + { + map_o_msblsb = true; + tio_printf("Switched to reverse bit order"); + } + else + { + map_o_msblsb = false; + tio_printf("Switched to normal bit order"); + } + break; + case KEY_Q: /* Exit upon ctrl-t q sequence */ exit(EXIT_SUCCESS); @@ -860,6 +877,10 @@ void tty_configure(void) { map_o_ltu = true; } + else if (strcmp(token, "MSB2LSB") == 0) + { + map_o_msblsb = true; + } else { printf("Error: Unknown mapping flag %s\n", token); @@ -1219,8 +1240,19 @@ int tty_connect(void) } } + /* Convert MSB to LSB bit order */ + if (map_o_msblsb) + { + char ch = input_char; + input_char = 0; + for (int j = 0; j < 8; ++j) + { + input_char |= ((1 << j) & ch) ? (1 << (7 - j)) : 0; + } + } + /* Map input character */ - if ((input_char == '\n') && (map_i_nl_crnl)) + if ((input_char == '\n') && (map_i_nl_crnl) && (!map_o_msblsb)) { print('\r'); print('\n'); From 49249692686c01f5eb16a0c8b747107a6fa5c927 Mon Sep 17 00:00:00 2001 From: Attila Veghelyi Date: Thu, 29 Sep 2022 17:33:35 +0200 Subject: [PATCH 2/2] Complete bit reorder feature for release --- man/tio.1.in | 2 ++ man/tio.1.txt | 2 ++ src/bash-completion/tio.in | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/man/tio.1.in b/man/tio.1.in index ac03318..936ab5c 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -167,6 +167,8 @@ Map DEL to BS on output Map NL to CR-NL on output .IP "\fBOLTU" Map lowercase characters to uppercase on output +.IP "\fBMSB2LSB" +Map MSB bit order to LSB on output .P If defining more than one flag, the flags must be comma separated. .RE diff --git a/man/tio.1.txt b/man/tio.1.txt index 0399b63..3e03611 100644 --- a/man/tio.1.txt +++ b/man/tio.1.txt @@ -131,6 +131,8 @@ OPTIONS OLTU Map lowercase characters to uppercase on output + MSB2LSB Map MSB bit order to LSB on output + If defining more than one flag, the flags must be comma separated. -x, --hexadecimal diff --git a/src/bash-completion/tio.in b/src/bash-completion/tio.in index ca115e6..7e110f6 100644 --- a/src/bash-completion/tio.in +++ b/src/bash-completion/tio.in @@ -94,7 +94,7 @@ _tio() return 0 ;; -m | --map) - COMPREPLY=( $(compgen -W "ICRNL IGNCR INLCR INLCRNL OCRNL ODELBS ONLCRNL" -- ${cur}) ) + COMPREPLY=( $(compgen -W "ICRNL IGNCR INLCR INLCRNL OCRNL ODELBS ONLCRNL MSB2LSB" -- ${cur}) ) return 0 ;; -t | --timestamp)