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

@ -32,6 +32,7 @@ when used in combination with [tmux](https://tmux.github.io).
* List available serial devices * List available serial devices
* Show RX/TX statistics * Show RX/TX statistics
* Toggle serial lines * Toggle serial lines
* Pulse the DTR line
* 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
@ -65,6 +66,7 @@ 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)
--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
-t, --timestamp Enable line timestamp -t, --timestamp Enable line timestamp
@ -125,6 +127,7 @@ ctrl-t ? to list the available key commands.
[20:19:12.040] ctrl-t b Send break [20:19:12.040] ctrl-t b Send break
[20:19:12.040] ctrl-t c Show configuration [20:19:12.040] ctrl-t c Show configuration
[20:19:12.040] ctrl-t d Toggle DTR line [20:19:12.040] ctrl-t d Toggle DTR line
[20:19:12.040] ctrl-t D Pulse DTR line
[20:19:12.040] ctrl-t e Toggle local echo mode [20:19:12.040] ctrl-t e Toggle local echo mode
[20:19:12.040] ctrl-t h Toggle hexadecimal mode [20:19:12.040] ctrl-t h Toggle hexadecimal mode
[20:19:12.040] ctrl-t l Clear screen [20:19:12.040] ctrl-t l Clear screen
@ -158,6 +161,7 @@ databits = 8
parity = none parity = none
stopbits = 1 stopbits = 1
color = 10 color = 10
dtr-pulse-duration = 50
[rpi3] [rpi3]
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0 tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0

View file

@ -41,6 +41,12 @@ Set parity (default: none).
.BR \-o ", " "\-\-output\-delay " \fI<ms> .BR \-o ", " "\-\-output\-delay " \fI<ms>
Set output delay [ms] inserted between each sent character (default: 0). Set output delay [ms] inserted between each sent character (default: 0).
.TP
.BR " \-\-dtr\-pulse\-duration " \fI<ms>
Set the duration [ms] of the DTR pulse (default: 100).
.TP .TP
.BR \-n ", " \-\-no\-autoconnect .BR \-n ", " \-\-no\-autoconnect
@ -199,6 +205,8 @@ Send ctrl-t key code
Show line states (DTR, RTS, CTS, DSR, DCD, RI) Show line states (DTR, RTS, CTS, DSR, DCD, RI)
.IP "\fBctrl-t d" .IP "\fBctrl-t d"
Toggle DTR Toggle DTR
.IP "\fBctrl-t D"
Pulse DTR
.IP "\fBctrl-t r" .IP "\fBctrl-t r"
Toggle RTS Toggle RTS
.IP "\fBctrl-t v" .IP "\fBctrl-t v"
@ -254,6 +262,8 @@ Set stop bits
Set parity Set parity
.IP "\fBoutput-delay" .IP "\fBoutput-delay"
Set output delay Set output delay
.IP "\fBdtr-pulse-duration"
Set DTR pulse duration
.IP "\fBno-autoconnect" .IP "\fBno-autoconnect"
Disable automatic connect Disable automatic connect
.IP "\fBlog" .IP "\fBlog"
@ -291,6 +301,7 @@ databits = 8
parity = none parity = none
stopbits = 1 stopbits = 1
color = 10 color = 10
dtr-pulse-duration = 50
.ec .ec
.fi .fi
.RE .RE

View file

@ -16,6 +16,7 @@ _tio()
-s --stopbits \ -s --stopbits \
-p --parity \ -p --parity \
-o --output-delay \ -o --output-delay \
--dtr-pulse-duration \
-n --no-autoconnect \ -n --no-autoconnect \
-e --local-echo \ -e --local-echo \
-l --log \ -l --log \
@ -58,6 +59,10 @@ _tio()
COMPREPLY=( $(compgen -W "0 1 10 100" -- ${cur}) ) COMPREPLY=( $(compgen -W "0 1 10 100" -- ${cur}) )
return 0 return 0
;; ;;
--dtr-pulse-duration)
COMPREPLY=( $(compgen -W "10 50 100 500" -- ${cur}) )
return 0
;;
-n | --no-autoconnect) -n | --no-autoconnect)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0 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); option.output_delay = atoi(value);
} }
else if (!strcmp(name, "dtr-pulse-duration"))
{
option.dtr_pulse_duration = atoi(value);
}
else if (!strcmp(name, "no-autoconnect")) else if (!strcmp(name, "no-autoconnect"))
{ {
if (!strcmp(value, "enable")) if (!strcmp(value, "enable"))

View file

@ -42,6 +42,7 @@ enum opt_t
OPT_TIMESTAMP_FORMAT, OPT_TIMESTAMP_FORMAT,
OPT_LOG_FILE, OPT_LOG_FILE,
OPT_LOG_STRIP, OPT_LOG_STRIP,
OPT_DTR_PULSE_DURATION,
}; };
/* Default options */ /* Default options */
@ -54,6 +55,7 @@ struct option_t option =
.stopbits = 1, .stopbits = 1,
.parity = "none", .parity = "none",
.output_delay = 0, .output_delay = 0,
.dtr_pulse_duration = 100,
.no_autoconnect = false, .no_autoconnect = false,
.log = false, .log = false,
.log_filename = NULL, .log_filename = NULL,
@ -79,6 +81,7 @@ void print_help(char *argv[])
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 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(" --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");
printf(" -t, --timestamp Enable line timestamp\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(" 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(" 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)
tio_printf(" Map flags: %s", option.map); tio_printf(" Map flags: %s", option.map);
@ -198,6 +202,7 @@ 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' },
{"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' },
{"timestamp", no_argument, 0, 't' }, {"timestamp", no_argument, 0, 't' },
@ -261,6 +266,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 OPT_DTR_PULSE_DURATION:
option.dtr_pulse_duration = string_to_long(optarg);
break;
case 'n': case 'n':
option.no_autoconnect = true; option.no_autoconnect = true;
break; break;

View file

@ -48,6 +48,7 @@ struct option_t
int stopbits; int stopbits;
char *parity; char *parity;
int output_delay; int output_delay;
int dtr_pulse_duration;
bool no_autoconnect; bool no_autoconnect;
bool log; bool log;
bool log_strip; 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 b Send break");
tio_printf(" ctrl-t c Show configuration"); tio_printf(" ctrl-t c Show configuration");
tio_printf(" ctrl-t d Toggle DTR line"); 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 e Toggle local echo mode");
tio_printf(" ctrl-t h Toggle hexadecimal mode"); tio_printf(" ctrl-t h Toggle hexadecimal mode");
tio_printf(" ctrl-t l Clear screen"); 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); toggle_line("DTR", TIOCM_DTR);
break; break;
case KEY_SHIFT_D:
toggle_line("DTR", TIOCM_DTR);
delay(option.dtr_pulse_duration);
toggle_line("DTR", TIOCM_DTR);
break;
case KEY_R: case KEY_R:
toggle_line("RTS", TIOCM_RTS); toggle_line("RTS", TIOCM_RTS);
break; break;

View file

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