mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
Improvements for exit-after and initstring
Treat initstring as if entered manually at the terminal. Do not set select(1) timeout if exit-after is negative.
This commit is contained in:
42
picocom.1
42
picocom.1
@ -1,6 +1,6 @@
|
||||
.\" Automatically generated by Pandoc 1.16.0.2
|
||||
.\"
|
||||
.TH "PICOCOM" "1" "2017-12-12" "Picocom 2.3a" "User Commands"
|
||||
.TH "PICOCOM" "1" "2017-12-14" "Picocom 2.3a" "User Commands"
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
@ -351,13 +351,25 @@ If local\-echo mode is is enabled (see \f[B]\-\-echo\f[] option and
|
||||
.RE
|
||||
.TP
|
||||
.B \f[B]\-\-initstring\f[] | \f[B]\-t\f[]
|
||||
Send the provided string after opening the serial port.
|
||||
This feature is useful for example if the serial device needs some
|
||||
Send the provided string after opening and configuring the serial port.
|
||||
The init string is sent exactly as if it was input at the terminal, and
|
||||
thus obeys the \f[B]\-\-omap\f[] output mapping, the \f[B]\-\-echo\f[]
|
||||
local\-echo setting, and the \f[B]\-emap\f[] local\-echo mapping.
|
||||
This feature is useful, for example, if the serial device needs some
|
||||
special magic strings to start responding.
|
||||
Use $(echo \-e ...) or xxd to generate special characters like a CR or
|
||||
binary data.
|
||||
Note, that the initial string is not sent if \f[B]\-\-noinit\f[] is set.
|
||||
Use \f[B]echo(1)\f[] or \f[B]xxd(1)\f[] to generate special characters
|
||||
like a CR or binary data.
|
||||
Example:
|
||||
.RS
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
picocom\ \-t\ "$(echo\ \-e\ \[aq]\\r\\nATZ\\r\\n\[aq])"\ /dev/ttsyS0
|
||||
\f[]
|
||||
.fi
|
||||
.PP
|
||||
Note, that the init string is not sent if \f[B]\-\-noinit\f[] is set.
|
||||
(Default: empty).
|
||||
.RE
|
||||
.TP
|
||||
.B \f[B]\-\-lower\-rts\f[]
|
||||
@ -376,6 +388,22 @@ Only supported in Linux and OSX.
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
.B \f[B]\-\-exit\-aftrer\f[] | \f[B]\-x\f[]
|
||||
Exit picocom after remaining idle for the specified time (in
|
||||
milliseconds).
|
||||
Picocom is considered idle if: Nothing is read (received) from the
|
||||
serial port, AND there is nothing to write (send) to the serial port,
|
||||
AND nothing is read from the terminal.
|
||||
If \f[B]\-\-exit\-after\f[] is set to zero, then picocom exits after
|
||||
opening and configuring the serial port, after sending the init string
|
||||
(if any, see option \f[B]\-\-initstring\f[]), and imediatelly when it
|
||||
becomes idle.
|
||||
When exiting with \f[B]\-\-exit\-after\f[], picocom observes the
|
||||
\f[B]\-\-noreset\f[] setting as usual.
|
||||
(Default: not set).
|
||||
.RS
|
||||
.RE
|
||||
.TP
|
||||
.B \f[B]\-\-help\f[] | \f[B]\-h\f[]
|
||||
Print a short help message describing the command\-line options.
|
||||
Picocom\[aq]s version, ompile\-time options, and enabled features are
|
||||
@ -552,7 +580,7 @@ Download the latest release from:
|
||||
<https://github.com/npat-efault/picocom/releases>
|
||||
.SH COPYRIGHT
|
||||
.PP
|
||||
Copyright (c) 2004\-2016 Nick Patavalis
|
||||
Copyright (c) 2004\-2017 Nick Patavalis
|
||||
.PP
|
||||
This file is part of Picocom.
|
||||
.PP
|
||||
|
40
picocom.c
40
picocom.c
@ -1113,7 +1113,6 @@ loop(void)
|
||||
int r, n;
|
||||
unsigned char c;
|
||||
|
||||
tty_q.len = 0;
|
||||
state = ST_TRANSPARENT;
|
||||
|
||||
while ( ! sig_exit ) {
|
||||
@ -1127,8 +1126,10 @@ loop(void)
|
||||
if ( tty_q.len ) {
|
||||
FD_SET(tty_fd, &wrset);
|
||||
} else {
|
||||
msec2tv(&tv, opts.exit_after);
|
||||
ptv = &tv;
|
||||
if ( opts.exit_after >= 0 ) {
|
||||
msec2tv(&tv, opts.exit_after);
|
||||
ptv = &tv;
|
||||
}
|
||||
}
|
||||
|
||||
r = select(tty_fd + 1, &rdset, &wrset, NULL, ptv);
|
||||
@ -1682,12 +1683,6 @@ main(int argc, char *argv[])
|
||||
opts.flow, /* flow control. */
|
||||
1, /* local or modem */
|
||||
!opts.noreset); /* hup-on-close. */
|
||||
|
||||
if (opts.initstring) {
|
||||
write(tty_fd, opts.initstring, strlen(opts.initstring));
|
||||
free(opts.initstring);
|
||||
opts.initstring = NULL;
|
||||
}
|
||||
}
|
||||
if ( r < 0 )
|
||||
fatal("failed to add device %s: %s",
|
||||
@ -1732,6 +1727,33 @@ main(int argc, char *argv[])
|
||||
KEYC(opts.escape), KEYC(KEY_HELP));
|
||||
#endif
|
||||
fd_printf(STO, "Terminal ready\r\n");
|
||||
|
||||
/* Prime output buffer with initstring */
|
||||
tty_q.len = 0;
|
||||
if ( ! opts.noinit ) {
|
||||
char *cp;
|
||||
int n;
|
||||
|
||||
for (cp = opts.initstring; cp && *cp != '\0'; cp++) {
|
||||
if (tty_q.len + M_MAXMAP <= TTY_Q_SZ) {
|
||||
n = do_map((char *)tty_q.buff + tty_q.len,
|
||||
opts.omap, *cp);
|
||||
tty_q.len += n;
|
||||
/* Echo initstring if local-echo is enabled */
|
||||
if ( opts.lecho )
|
||||
map_and_write(STO, opts.emap, *cp);
|
||||
} else {
|
||||
fatal("initstring too long!");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Free initstirng, no longer needed */
|
||||
if (opts.initstring) {
|
||||
free(opts.initstring);
|
||||
opts.initstring = NULL;
|
||||
}
|
||||
|
||||
/* Enter main processing loop */
|
||||
loop();
|
||||
|
||||
#ifdef LINENOISE
|
||||
|
Reference in New Issue
Block a user