mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Additional commands: EOL delay, lower to upper translation, added mark parity
Added command line options: -O, --eol-delay to have a separate delay for end of line -U, --upper to enable translation of lower case alpha to upper case Added ability to set mark parity. Added ctrl-t U key sequence to allow enable/disable lower case alpha to upper case during a session. Updated Man page with command line options, ctrl-t sequences and configuration file options. Updated README.md, with above information.
This commit is contained in:
parent
dbdb84743f
commit
944ee9173b
7 changed files with 98 additions and 6 deletions
13
README.md
13
README.md
|
|
@ -36,7 +36,9 @@ when used in combination with [tmux](https://tmux.github.io).
|
||||||
* Local echo support
|
* Local echo support
|
||||||
* Remap special characters (nl, cr-nl, bs, etc.)
|
* Remap special characters (nl, cr-nl, bs, etc.)
|
||||||
* Line timestamps
|
* Line timestamps
|
||||||
* Support for delayed output
|
* Support for delayed output per transmitted character
|
||||||
|
* Support for delayed output per line
|
||||||
|
* Support for translation of lower case to upper case
|
||||||
* Hexadecimal mode
|
* Hexadecimal mode
|
||||||
* Log to file
|
* Log to file
|
||||||
* Autogeneration of log filename
|
* Autogeneration of log filename
|
||||||
|
|
@ -66,6 +68,13 @@ The command-line interface is straightforward as reflected in the output from
|
||||||
-s, --stopbits 1|2 Stop bits (default: 1)
|
-s, --stopbits 1|2 Stop bits (default: 1)
|
||||||
-p, --parity odd|even|none Parity (default: none)
|
-p, --parity odd|even|none Parity (default: none)
|
||||||
-o, --output-delay <ms> Character output delay (default: 0)
|
-o, --output-delay <ms> Character output delay (default: 0)
|
||||||
|
-O, --eol-delay <ms> EOL output delay (default: 0)
|
||||||
|
--dtr-pulse-duration <ms> DTR pulse duration (default: 100)
|
||||||
|
-n, --no-autoconnect Disable automatic connect
|
||||||
|
-e, --local-echo Enable local echo
|
||||||
|
-t, --timestamp Enable line timestamp
|
||||||
|
--timestamp-format <format> Set timestamp format (default: 24hour)
|
||||||
|
-L, --list-devices List available serial devices
|
||||||
--dtr-pulse-duration <ms> DTR pulse duration (default: 100)
|
--dtr-pulse-duration <ms> DTR pulse duration (default: 100)
|
||||||
-n, --no-autoconnect Disable automatic connect
|
-n, --no-autoconnect Disable automatic connect
|
||||||
-e, --local-echo Enable local echo
|
-e, --local-echo Enable local echo
|
||||||
|
|
@ -79,6 +88,7 @@ The command-line interface is straightforward as reflected in the output from
|
||||||
-c, --color 0..255|none|list Colorize tio text (default: 15)
|
-c, --color 0..255|none|list Colorize tio text (default: 15)
|
||||||
-S, --socket <socket> Redirect I/O to file or network socket
|
-S, --socket <socket> Redirect I/O to file or network socket
|
||||||
-x, --hexadecimal Enable hexadecimal mode
|
-x, --hexadecimal Enable hexadecimal mode
|
||||||
|
-U, --upper Enable translation of lower case to upper
|
||||||
-v, --version Display version
|
-v, --version Display version
|
||||||
-h, --help Display help
|
-h, --help Display help
|
||||||
|
|
||||||
|
|
@ -137,6 +147,7 @@ ctrl-t ? to list the available key commands.
|
||||||
[20:19:12.041] ctrl-t s Show statistics
|
[20:19:12.041] ctrl-t s Show statistics
|
||||||
[20:19:12.041] ctrl-t t Send ctrl-t key code
|
[20:19:12.041] ctrl-t t Send ctrl-t key code
|
||||||
[20:19:12.041] ctrl-t T Toggle line timestamp mode
|
[20:19:12.041] ctrl-t T Toggle line timestamp mode
|
||||||
|
[20:19:12.041] ctrl-t U Toggle lower case alpha to upper case
|
||||||
[20:19:12.041] ctrl-t v Show version
|
[20:19:12.041] ctrl-t v Show version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
17
man/tio.1.in
17
man/tio.1.in
|
|
@ -34,7 +34,7 @@ Set flow control (default: none).
|
||||||
|
|
||||||
Set stop bits (default: 1).
|
Set stop bits (default: 1).
|
||||||
.TP
|
.TP
|
||||||
.BR \-p ", " "\-\-parity odd" | even | none
|
.BR \-p ", " "\-\-parity odd" | even | none | mark
|
||||||
|
|
||||||
Set parity (default: none).
|
Set parity (default: none).
|
||||||
.TP
|
.TP
|
||||||
|
|
@ -42,6 +42,15 @@ Set parity (default: none).
|
||||||
|
|
||||||
Set output delay [ms] inserted between each sent character (default: 0).
|
Set output delay [ms] inserted between each sent character (default: 0).
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR \-O ", " "\-\-eol\-delay " \fI<ms>
|
||||||
|
|
||||||
|
Set EOL delay [ms] inserted between each sent line (default: 0).
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR \-U ", " \-\-upcase"
|
||||||
|
|
||||||
|
Convert any entered lower case alpha to upper case (default: disabled)
|
||||||
.TP
|
.TP
|
||||||
.BR " \-\-dtr\-pulse\-duration " \fI<ms>
|
.BR " \-\-dtr\-pulse\-duration " \fI<ms>
|
||||||
|
|
||||||
|
|
@ -209,6 +218,8 @@ Toggle DTR
|
||||||
Pulse DTR
|
Pulse DTR
|
||||||
.IP "\fBctrl-t r"
|
.IP "\fBctrl-t r"
|
||||||
Toggle RTS
|
Toggle RTS
|
||||||
|
.IP "\fBctrl-t U"
|
||||||
|
Toggle upcase
|
||||||
.IP "\fBctrl-t v"
|
.IP "\fBctrl-t v"
|
||||||
Show version
|
Show version
|
||||||
|
|
||||||
|
|
@ -262,6 +273,10 @@ Set stop bits
|
||||||
Set parity
|
Set parity
|
||||||
.IP "\fBoutput-delay"
|
.IP "\fBoutput-delay"
|
||||||
Set output delay
|
Set output delay
|
||||||
|
.IP "\fBeol-delay"
|
||||||
|
Set EOL delay
|
||||||
|
.IP "\fBupcase"
|
||||||
|
Set translation of alpha from lower to upper case
|
||||||
.IP "\fBdtr-pulse-duration"
|
.IP "\fBdtr-pulse-duration"
|
||||||
Set DTR pulse duration
|
Set DTR pulse duration
|
||||||
.IP "\fBno-autoconnect"
|
.IP "\fBno-autoconnect"
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,14 @@ static int data_handler(void *user, const char *section, const char *name,
|
||||||
{
|
{
|
||||||
option.output_delay = atoi(value);
|
option.output_delay = atoi(value);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(name, "eol-delay"))
|
||||||
|
{
|
||||||
|
option.eol_delay = atoi(value);
|
||||||
|
}
|
||||||
|
else if ( !strcmp(name, "upcase"))
|
||||||
|
{
|
||||||
|
option.upcase = true;
|
||||||
|
}
|
||||||
else if (!strcmp(name, "dtr-pulse-duration"))
|
else if (!strcmp(name, "dtr-pulse-duration"))
|
||||||
{
|
{
|
||||||
option.dtr_pulse_duration = atoi(value);
|
option.dtr_pulse_duration = atoi(value);
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ struct option_t option =
|
||||||
.parity = "none",
|
.parity = "none",
|
||||||
.output_delay = 0,
|
.output_delay = 0,
|
||||||
.dtr_pulse_duration = 100,
|
.dtr_pulse_duration = 100,
|
||||||
|
.eol_delay = 0,
|
||||||
|
.upcase = false,
|
||||||
.no_autoconnect = false,
|
.no_autoconnect = false,
|
||||||
.log = false,
|
.log = false,
|
||||||
.log_filename = NULL,
|
.log_filename = NULL,
|
||||||
|
|
@ -79,8 +81,9 @@ void print_help(char *argv[])
|
||||||
printf(" -d, --databits 5|6|7|8 Data bits (default: 8)\n");
|
printf(" -d, --databits 5|6|7|8 Data bits (default: 8)\n");
|
||||||
printf(" -f, --flow hard|soft|none Flow control (default: none)\n");
|
printf(" -f, --flow hard|soft|none Flow control (default: none)\n");
|
||||||
printf(" -s, --stopbits 1|2 Stop bits (default: 1)\n");
|
printf(" -s, --stopbits 1|2 Stop bits (default: 1)\n");
|
||||||
printf(" -p, --parity odd|even|none Parity (default: none)\n");
|
printf(" -p, --parity odd|even|none|mark Parity (default: none)\n");
|
||||||
printf(" -o, --output-delay <ms> Output delay (default: 0)\n");
|
printf(" -o, --output-delay <ms> Output delay (default: 0)\n");
|
||||||
|
printf(" -O, --eol-delay <ms> EOL output delay (default: 0)\n");
|
||||||
printf(" --dtr-pulse-duration <ms> DTR pulse duration (default: 100)\n");
|
printf(" --dtr-pulse-duration <ms> DTR pulse duration (default: 100)\n");
|
||||||
printf(" -n, --no-autoconnect Disable automatic connect\n");
|
printf(" -n, --no-autoconnect Disable automatic connect\n");
|
||||||
printf(" -e, --local-echo Enable local echo\n");
|
printf(" -e, --local-echo Enable local echo\n");
|
||||||
|
|
@ -94,6 +97,7 @@ void print_help(char *argv[])
|
||||||
printf(" -c, --color 0..255|none|list Colorize tio text (default: 15)\n");
|
printf(" -c, --color 0..255|none|list Colorize tio text (default: 15)\n");
|
||||||
printf(" -S, --socket <socket> Redirect I/O to file or network socket\n");
|
printf(" -S, --socket <socket> Redirect I/O to file or network socket\n");
|
||||||
printf(" -x, --hexadecimal Enable hexadecimal mode\n");
|
printf(" -x, --hexadecimal Enable hexadecimal mode\n");
|
||||||
|
printf(" -U, --upcase Translate lower case alpha to upper case\n");
|
||||||
printf(" -v, --version Display version\n");
|
printf(" -v, --version Display version\n");
|
||||||
printf(" -h, --help Display help\n");
|
printf(" -h, --help Display help\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
@ -172,6 +176,8 @@ void options_print()
|
||||||
tio_printf(" Local echo: %s", option.local_echo ? "enabled" : "disabled");
|
tio_printf(" Local echo: %s", option.local_echo ? "enabled" : "disabled");
|
||||||
tio_printf(" Timestamp: %s", timestamp_state_to_string(option.timestamp));
|
tio_printf(" Timestamp: %s", timestamp_state_to_string(option.timestamp));
|
||||||
tio_printf(" Output delay: %d", option.output_delay);
|
tio_printf(" Output delay: %d", option.output_delay);
|
||||||
|
tio_printf(" EOL delay: %d", option.eol_delay);
|
||||||
|
tio_printf(" Upcase: %s", option.upcase ? "enabled" : "disabled");
|
||||||
tio_printf(" DTR pulse duration: %d", option.dtr_pulse_duration);
|
tio_printf(" DTR pulse duration: %d", option.dtr_pulse_duration);
|
||||||
tio_printf(" Auto connect: %s", option.no_autoconnect ? "disabled" : "enabled");
|
tio_printf(" Auto connect: %s", option.no_autoconnect ? "disabled" : "enabled");
|
||||||
if (option.map[0] != 0)
|
if (option.map[0] != 0)
|
||||||
|
|
@ -202,6 +208,8 @@ void options_parse(int argc, char *argv[])
|
||||||
{"stopbits", required_argument, 0, 's' },
|
{"stopbits", required_argument, 0, 's' },
|
||||||
{"parity", required_argument, 0, 'p' },
|
{"parity", required_argument, 0, 'p' },
|
||||||
{"output-delay", required_argument, 0, 'o' },
|
{"output-delay", required_argument, 0, 'o' },
|
||||||
|
{"eol-delay", required_argument, 0, 'O' },
|
||||||
|
{"upcase", no_argument, 0, 'U' },
|
||||||
{"dtr-pulse-duration", required_argument, 0, OPT_DTR_PULSE_DURATION },
|
{"dtr-pulse-duration", required_argument, 0, OPT_DTR_PULSE_DURATION },
|
||||||
{"no-autoconnect", no_argument, 0, 'n' },
|
{"no-autoconnect", no_argument, 0, 'n' },
|
||||||
{"local-echo", no_argument, 0, 'e' },
|
{"local-echo", no_argument, 0, 'e' },
|
||||||
|
|
@ -224,7 +232,7 @@ void options_parse(int argc, char *argv[])
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
/* Parse argument using getopt_long */
|
/* Parse argument using getopt_long */
|
||||||
c = getopt_long(argc, argv, "b:d:f:s:p:o:netLlS:m:c:xvh", long_options, &option_index);
|
c = getopt_long(argc, argv, "b:d:f:s:p:o:O:UnetLlS:m:c:xvh", long_options, &option_index);
|
||||||
|
|
||||||
/* Detect the end of the options */
|
/* Detect the end of the options */
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
|
|
@ -266,6 +274,10 @@ void options_parse(int argc, char *argv[])
|
||||||
option.output_delay = string_to_long(optarg);
|
option.output_delay = string_to_long(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'O':
|
||||||
|
option.eol_delay = string_to_long(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case OPT_DTR_PULSE_DURATION:
|
case OPT_DTR_PULSE_DURATION:
|
||||||
option.dtr_pulse_duration = string_to_long(optarg);
|
option.dtr_pulse_duration = string_to_long(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
@ -341,6 +353,10 @@ void options_parse(int argc, char *argv[])
|
||||||
option.hex_mode = true;
|
option.hex_mode = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'U':
|
||||||
|
option.upcase = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("tio v%s\n", VERSION);
|
printf("tio v%s\n", VERSION);
|
||||||
printf("Copyright (c) 2014-2022 Martin Lund\n");
|
printf("Copyright (c) 2014-2022 Martin Lund\n");
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ struct option_t
|
||||||
char *parity;
|
char *parity;
|
||||||
int output_delay;
|
int output_delay;
|
||||||
int dtr_pulse_duration;
|
int dtr_pulse_duration;
|
||||||
|
int eol_delay;
|
||||||
|
bool upcase;
|
||||||
bool no_autoconnect;
|
bool no_autoconnect;
|
||||||
bool log;
|
bool log;
|
||||||
bool log_strip;
|
bool log_strip;
|
||||||
|
|
|
||||||
43
src/tty.c
43
src/tty.c
|
|
@ -24,6 +24,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
@ -146,11 +147,16 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t bytes_written = 0;
|
ssize_t bytes_written = 0;
|
||||||
|
|
||||||
if (option.output_delay)
|
if (option.output_delay || option.eol_delay )
|
||||||
{
|
{
|
||||||
// Write byte by byte with output delay
|
// Write byte by byte with output delay
|
||||||
for (size_t i=0; i<count; i++)
|
for (size_t i=0; i<count; i++)
|
||||||
{
|
{
|
||||||
|
// convert alpha to upper case
|
||||||
|
if ( option.upcase )
|
||||||
|
{
|
||||||
|
*(unsigned char*)buffer = toupper(*(unsigned char*)buffer);
|
||||||
|
}
|
||||||
ssize_t retval = write(fd, buffer, 1);
|
ssize_t retval = write(fd, buffer, 1);
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -159,8 +165,15 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytes_written += retval;
|
bytes_written += retval;
|
||||||
|
if ( option.eol_delay && *(unsigned char*)buffer == '\r' )
|
||||||
|
{
|
||||||
|
delay( option.eol_delay );
|
||||||
|
}
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
delay(option.output_delay);
|
if ( option.output_delay )
|
||||||
|
{
|
||||||
|
delay(option.output_delay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -171,6 +184,14 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
tty_flush(fd);
|
tty_flush(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert lower case to upper case, in situ
|
||||||
|
if ( option.upcase )
|
||||||
|
{
|
||||||
|
for ( size_t i = 0; i<count; i++ )
|
||||||
|
{
|
||||||
|
*((unsigned char*)buffer+i) = toupper(*((unsigned char*)buffer+i));
|
||||||
|
}
|
||||||
|
}
|
||||||
// Copy bytes to tty write buffer
|
// Copy bytes to tty write buffer
|
||||||
memcpy(tty_buffer_write_ptr, buffer, count);
|
memcpy(tty_buffer_write_ptr, buffer, count);
|
||||||
tty_buffer_write_ptr += count;
|
tty_buffer_write_ptr += count;
|
||||||
|
|
@ -266,6 +287,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
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");
|
||||||
tio_printf(" ctrl-t T Toggle line timestamp mode");
|
tio_printf(" ctrl-t T Toggle line timestamp mode");
|
||||||
|
tio_printf(" ctrl-t U Toggle upcase");
|
||||||
tio_printf(" ctrl-t v Show version");
|
tio_printf(" ctrl-t v Show version");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -375,6 +397,17 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KEY_U:
|
||||||
|
if ( option.upcase == true )
|
||||||
|
{
|
||||||
|
option.upcase = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
option.upcase = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_V:
|
case KEY_V:
|
||||||
tio_printf("tio v%s", VERSION);
|
tio_printf("tio v%s", VERSION);
|
||||||
break;
|
break;
|
||||||
|
|
@ -596,6 +629,12 @@ void tty_configure(void)
|
||||||
{
|
{
|
||||||
tio.c_cflag &= ~PARENB;
|
tio.c_cflag &= ~PARENB;
|
||||||
}
|
}
|
||||||
|
else if ( strcmp("mark", option.parity) == 0)
|
||||||
|
{
|
||||||
|
tio.c_cflag &= ~PARENB;
|
||||||
|
tio.c_cflag |= PARODD;
|
||||||
|
tio.c_cflag |= CMSPAR;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error_printf("Invalid parity");
|
error_printf("Invalid parity");
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#define KEY_T 0x74
|
#define KEY_T 0x74
|
||||||
#define KEY_SHIFT_T 0x54
|
#define KEY_SHIFT_T 0x54
|
||||||
#define KEY_CTRL_T 0x14
|
#define KEY_CTRL_T 0x14
|
||||||
|
#define KEY_U 0x55
|
||||||
#define KEY_V 0x76
|
#define KEY_V 0x76
|
||||||
#define KEY_D 0x64
|
#define KEY_D 0x64
|
||||||
#define KEY_SHIFT_D 0x44
|
#define KEY_SHIFT_D 0x44
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue