Add Pulse DTR command

MCUs like the ESP32 can be reset if the serial port DTR line is
pulsed for a short time.  You could just type CTRL-t d CTRL-t d
but that's a little awkward since you have to lift your finger
off the CTRL key to type the Ds.  Now you can just type CTRL-T D.

* Added new command "D" to pulse the DTR line.  I.E.  Toggle its
  state twice with a configurable duration between toggles.

* Added new config/command line option "--dtr-pulse-duration"
  to set the duration between the DTR state toggles.  The default
  is 100ms.
This commit is contained in:
George Joseph 2022-07-07 10:45:37 -06:00
parent a717631207
commit f24cee61e7
8 changed files with 42 additions and 0 deletions

View file

@ -16,6 +16,7 @@ _tio()
-s --stopbits \
-p --parity \
-o --output-delay \
--dtr-pulse-duration \
-n --no-autoconnect \
-e --local-echo \
-l --log \
@ -58,6 +59,10 @@ _tio()
COMPREPLY=( $(compgen -W "0 1 10 100" -- ${cur}) )
return 0
;;
--dtr-pulse-duration)
COMPREPLY=( $(compgen -W "10 50 100 500" -- ${cur}) )
return 0
;;
-n | --no-autoconnect)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0

View file

@ -124,6 +124,10 @@ static int data_handler(void *user, const char *section, const char *name,
{
option.output_delay = atoi(value);
}
else if (!strcmp(name, "dtr-pulse-duration"))
{
option.dtr_pulse_duration = atoi(value);
}
else if (!strcmp(name, "no-autoconnect"))
{
if (!strcmp(value, "enable"))

View file

@ -42,6 +42,7 @@ enum opt_t
OPT_TIMESTAMP_FORMAT,
OPT_LOG_FILE,
OPT_LOG_STRIP,
OPT_DTR_PULSE_DURATION,
};
/* Default options */
@ -54,6 +55,7 @@ struct option_t option =
.stopbits = 1,
.parity = "none",
.output_delay = 0,
.dtr_pulse_duration = 100,
.no_autoconnect = false,
.log = false,
.log_filename = NULL,
@ -79,6 +81,7 @@ void print_help(char *argv[])
printf(" -s, --stopbits 1|2 Stop bits (default: 1)\n");
printf(" -p, --parity odd|even|none Parity (default: none)\n");
printf(" -o, --output-delay <ms> 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");
printf(" -t, --timestamp Enable line timestamp\n");
@ -169,6 +172,7 @@ 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(" DTR pulse duration: %d", option.dtr_pulse_duration);
tio_printf(" Auto connect: %s", option.no_autoconnect ? "disabled" : "enabled");
if (option.map[0] != 0)
tio_printf(" Map flags: %s", option.map);
@ -198,6 +202,7 @@ void options_parse(int argc, char *argv[])
{"stopbits", required_argument, 0, 's' },
{"parity", required_argument, 0, 'p' },
{"output-delay", required_argument, 0, 'o' },
{"dtr-pulse-duration", required_argument, 0, OPT_DTR_PULSE_DURATION },
{"no-autoconnect", no_argument, 0, 'n' },
{"local-echo", no_argument, 0, 'e' },
{"timestamp", no_argument, 0, 't' },
@ -261,6 +266,10 @@ void options_parse(int argc, char *argv[])
option.output_delay = string_to_long(optarg);
break;
case OPT_DTR_PULSE_DURATION:
option.dtr_pulse_duration = string_to_long(optarg);
break;
case 'n':
option.no_autoconnect = true;
break;

View file

@ -48,6 +48,7 @@ struct option_t
int stopbits;
char *parity;
int output_delay;
int dtr_pulse_duration;
bool no_autoconnect;
bool log;
bool log_strip;

View file

@ -256,6 +256,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
tio_printf(" ctrl-t b Send break");
tio_printf(" ctrl-t c Show configuration");
tio_printf(" ctrl-t d Toggle DTR line");
tio_printf(" ctrl-t D Pulse DTR line");
tio_printf(" ctrl-t e Toggle local echo mode");
tio_printf(" ctrl-t h Toggle hexadecimal mode");
tio_printf(" ctrl-t l Clear screen");
@ -286,6 +287,12 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
toggle_line("DTR", TIOCM_DTR);
break;
case KEY_SHIFT_D:
toggle_line("DTR", TIOCM_DTR);
delay(option.dtr_pulse_duration);
toggle_line("DTR", TIOCM_DTR);
break;
case KEY_R:
toggle_line("RTS", TIOCM_RTS);
break;

View file

@ -36,6 +36,7 @@
#define KEY_CTRL_T 0x14
#define KEY_V 0x76
#define KEY_D 0x64
#define KEY_SHIFT_D 0x44
#define KEY_R 0x72
#define KEY_SHIFT_L 0x4C