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:
Robert Snell 2022-07-09 21:22:43 -04:00
parent dbdb84743f
commit 944ee9173b
7 changed files with 98 additions and 6 deletions

View file

@ -124,6 +124,14 @@ static int data_handler(void *user, const char *section, const char *name,
{
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"))
{
option.dtr_pulse_duration = atoi(value);

View file

@ -56,6 +56,8 @@ struct option_t option =
.parity = "none",
.output_delay = 0,
.dtr_pulse_duration = 100,
.eol_delay = 0,
.upcase = false,
.no_autoconnect = false,
.log = false,
.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(" -f, --flow hard|soft|none Flow control (default: none)\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, --eol-delay <ms> EOL output delay (default: 0)\n");
printf(" --dtr-pulse-duration <ms> DTR pulse duration (default: 100)\n");
printf(" -n, --no-autoconnect Disable automatic connect\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(" -S, --socket <socket> Redirect I/O to file or network socket\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(" -h, --help Display help\n");
printf("\n");
@ -172,6 +176,8 @@ void options_print()
tio_printf(" Local echo: %s", option.local_echo ? "enabled" : "disabled");
tio_printf(" Timestamp: %s", timestamp_state_to_string(option.timestamp));
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(" Auto connect: %s", option.no_autoconnect ? "disabled" : "enabled");
if (option.map[0] != 0)
@ -202,6 +208,8 @@ void options_parse(int argc, char *argv[])
{"stopbits", required_argument, 0, 's' },
{"parity", required_argument, 0, 'p' },
{"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 },
{"no-autoconnect", no_argument, 0, 'n' },
{"local-echo", no_argument, 0, 'e' },
@ -224,7 +232,7 @@ void options_parse(int argc, char *argv[])
int option_index = 0;
/* 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 */
if (c == -1)
@ -266,6 +274,10 @@ void options_parse(int argc, char *argv[])
option.output_delay = string_to_long(optarg);
break;
case 'O':
option.eol_delay = string_to_long(optarg);
break;
case OPT_DTR_PULSE_DURATION:
option.dtr_pulse_duration = string_to_long(optarg);
break;
@ -341,6 +353,10 @@ void options_parse(int argc, char *argv[])
option.hex_mode = true;
break;
case 'U':
option.upcase = true;
break;
case 'v':
printf("tio v%s\n", VERSION);
printf("Copyright (c) 2014-2022 Martin Lund\n");

View file

@ -49,6 +49,8 @@ struct option_t
char *parity;
int output_delay;
int dtr_pulse_duration;
int eol_delay;
bool upcase;
bool no_autoconnect;
bool log;
bool log_strip;

View file

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <limits.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;
if (option.output_delay)
if (option.output_delay || option.eol_delay )
{
// Write byte by byte with output delay
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);
if (retval < 0)
{
@ -159,8 +165,15 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
break;
}
bytes_written += retval;
if ( option.eol_delay && *(unsigned char*)buffer == '\r' )
{
delay( option.eol_delay );
}
fsync(fd);
delay(option.output_delay);
if ( option.output_delay )
{
delay(option.output_delay);
}
}
}
else
@ -171,6 +184,14 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
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
memcpy(tty_buffer_write_ptr, buffer, 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 t Send ctrl-t key code");
tio_printf(" ctrl-t T Toggle line timestamp mode");
tio_printf(" ctrl-t U Toggle upcase");
tio_printf(" ctrl-t v Show version");
break;
@ -375,6 +397,17 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
}
break;
case KEY_U:
if ( option.upcase == true )
{
option.upcase = false;
}
else
{
option.upcase = true;
}
break;
case KEY_V:
tio_printf("tio v%s", VERSION);
break;
@ -596,6 +629,12 @@ void tty_configure(void)
{
tio.c_cflag &= ~PARENB;
}
else if ( strcmp("mark", option.parity) == 0)
{
tio.c_cflag &= ~PARENB;
tio.c_cflag |= PARODD;
tio.c_cflag |= CMSPAR;
}
else
{
error_printf("Invalid parity");

View file

@ -34,6 +34,7 @@
#define KEY_T 0x74
#define KEY_SHIFT_T 0x54
#define KEY_CTRL_T 0x14
#define KEY_U 0x55
#define KEY_V 0x76
#define KEY_D 0x64
#define KEY_SHIFT_D 0x44