1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Merge pull request #45 from planteen/master

Add command to toggle RTS. 

This is a new command that parallels the command for toggling DTR. Toggling RTS is useful for troubleshooting flow control signals. It is also useful for embedded hardware which is configured so RTS controls an external component (such as a relay, FET, or enable line). Toggling RTS is supported if the flow control mode is "none" or "xon/xoff" (not supported under RTS/CTS flow control for obvious reasons). The TIOCMBIC and TIOCMBIS ioctls() on TIOCM_RTS under Linux still succeed if the flow control is RTS/CTS, but the actual state on the RTS line does not change.
This commit is contained in:
Nick Patavalis
2016-10-15 19:22:27 +03:00
committed by GitHub
4 changed files with 145 additions and 16 deletions

View File

@ -62,9 +62,9 @@ here.
**C-q**
: Quit the program _without_ reseting the serial port, regardless of
: Quit the program _without_ resetting the serial port, regardless of
the **--noreset** option.
**C-p**
: Pulse the DTR line. Lower it for 1 sec, and then raise it again.
@ -74,6 +74,12 @@ here.
: Toggle the DTR line. If DTR is up, then lower it. If it is down,
then raise it.
**C-g**
: Toggle the RTS line. If RTS is up, then lower it. If it is down,
then raise it. Not supported if the flow control mode is RTS/CTS.
Only supported in Linux.
**C-backslash**
: Generate a break sequence on the serial line. A break sequence is
@ -83,7 +89,7 @@ here.
**C-b**
: Set baurdate. Prompts you to enter a baudrate numerically (in bps)
: Set baudrate. Prompts you to enter a baudrate numerically (in bps)
and configures the serial port accordingly.
**C-u**
@ -295,7 +301,7 @@ the same, only a single value is shown. Example:
*** baud: 9600
This behavioir was intriduced in picocom 2.0. Older releases displayed
This behavior was introduced in picocom 2.0. Older releases displayed
only the option values, not the actual serial-port settings
corresponding to them.
@ -316,7 +322,7 @@ programs for this purpose are:
The name of, and the command-line options to, the program to be used
for transmitting files are given by the **--send-cmd**
option. Similarly the program to receive files, and its argumets, are
option. Similarly the program to receive files, and its arguments, are
given by the **--receive-cmd** option. For example, in order to start
a picocom session that uses **sz(1)** to transmit files, and **rz(1)**
to receive files, you have to say something like this:
@ -343,7 +349,7 @@ with support for the linenoise library. Pressing **C-c** at this
prompt will cancel the file transfer command and return to normal
picocom operation. After entering a filename (and / or additional
transmission or reception program arguments) and assuming you have not
canceled the operation by pressing **C-c**, picocom will start the the
canceled the operation by pressing **C-c**, picocom will start the
external program as specified by the **--send-cmd**, or
**--receive-cmd** option, and with any filenames and additional
arguments you may have supplied. The standard input and output of the
@ -360,7 +366,7 @@ the serial port.
# INPUT, OUTPUT, AND ECHO MAPPING
Using the **--imap**, **--omap**, and **--emap** options you can make
picocom map (tranlate, replace) certain special characters after being
picocom map (translate, replace) certain special characters after being
read from the serial port (with **--imap**), before being written to
the serial port (with **--omap**), and before being locally echoed to
the terminal (standard output) if local echo is enabled (with
@ -382,7 +388,7 @@ For example the command:
will:
- Replace every CR (carriage return, 0x0d) caracter with LF (line
- Replace every CR (carriage return, 0x0d) character with LF (line
feed, 0x0a) and every DEL (delete, 0x7f) character with BS
(backspace, 0x08) before writing it to the serial port.

View File

@ -84,7 +84,8 @@ const char *flow_str[] = {
#define KEY_EXIT CKEY('x') /* exit picocom */
#define KEY_QUIT CKEY('q') /* exit picocom without reseting port */
#define KEY_PULSE CKEY('p') /* pulse DTR */
#define KEY_TOGGLE CKEY('t') /* toggle DTR */
#define KEY_TOG_DTR CKEY('t') /* toggle DTR */
#define KEY_TOG_RTS CKEY('g') /* toggle RTS */
#define KEY_BAUD CKEY('b') /* set baudrate */
#define KEY_BAUD_UP CKEY('u') /* increase baudrate (up) */
#define KEY_BAUD_DN CKEY('d') /* decrase baudrate (down) */
@ -669,7 +670,7 @@ stopbits_next (int bits)
}
void
show_status (int dtr_up)
show_status (int dtr_up, int rts_up)
{
int baud, bits, stopbits, mctl;
enum flowcntrl_e flow;
@ -715,12 +716,18 @@ show_status (int dtr_up)
mctl = term_get_mctl(tty_fd);
if (mctl >= 0 && mctl != MCTL_UNAVAIL) {
if ( ((mctl & MCTL_DTR) ? 1 : 0) == dtr_up )
if ( ((mctl & MCTL_DTR) ? 1 : 0) == dtr_up )
fd_printf(STO, "*** dtr: %s\r\n", dtr_up ? "up" : "down");
else
fd_printf(STO, "*** dtr: %s (%s)\r\n",
dtr_up ? "up" : "down",
(mctl & MCTL_DTR) ? "up" : "down");
if ( ((mctl & MCTL_RTS) ? 1 : 0) == rts_up )
fd_printf(STO, "*** rts: %s\r\n", rts_up ? "up" : "down");
else
fd_printf(STO, "*** rts: %s (%s)\r\n",
rts_up ? "up" : "down",
(mctl & MCTL_RTS) ? "up" : "down");
fd_printf(STO, "*** mctl: ");
fd_printf(STO, "DTR:%c DSR:%c DCD:%c RTS:%c CTS:%c RI:%c\r\n",
(mctl & MCTL_DTR) ? '1' : '0',
@ -731,6 +738,7 @@ show_status (int dtr_up)
(mctl & MCTL_RI) ? '1' : '0');
} else {
fd_printf(STO, "*** dtr: %s\r\n", dtr_up ? "up" : "down");
fd_printf(STO, "*** rts: %s\r\n", rts_up ? "up" : "down");
}
}
@ -763,7 +771,9 @@ show_keys()
fd_printf(STO, "*** [C-%c] : Pulse DTR\r\n",
KEYC(KEY_PULSE));
fd_printf(STO, "*** [C-%c] : Toggle DTR\r\n",
KEYC(KEY_TOGGLE));
KEYC(KEY_TOG_DTR));
fd_printf(STO, "*** [C-%c] : Toggle RTS\r\n",
KEYC(KEY_TOG_RTS));
fd_printf(STO, "*** [C-%c] : Send break\r\n",
KEYC(KEY_BREAK));
fd_printf(STO, "*** [C-%c] : Toggle local echo\r\n",
@ -900,6 +910,7 @@ int
do_command (unsigned char c)
{
static int dtr_up = 0;
static int rts_up = 0;
int newbaud, newflow, newparity, newbits, newstopbits;
const char *xfr_cmd;
char *fname;
@ -915,7 +926,7 @@ do_command (unsigned char c)
term_erase(tty_fd);
return 1;
case KEY_STATUS:
show_status(dtr_up);
show_status(dtr_up, rts_up);
break;
case KEY_HELP:
case KEY_KEYS:
@ -926,7 +937,7 @@ do_command (unsigned char c)
if ( term_pulse_dtr(tty_fd) < 0 )
fd_printf(STO, "*** FAILED\r\n");
break;
case KEY_TOGGLE:
case KEY_TOG_DTR:
if ( dtr_up )
r = term_lower_dtr(tty_fd);
else
@ -935,6 +946,15 @@ do_command (unsigned char c)
fd_printf(STO, "\r\n*** DTR: %s ***\r\n",
dtr_up ? "up" : "down");
break;
case KEY_TOG_RTS:
if ( rts_up )
r = term_lower_rts(tty_fd);
else
r = term_raise_rts(tty_fd);
if ( r >= 0 ) rts_up = ! rts_up;
fd_printf(STO, "\r\n*** RTS: %s ***\r\n",
rts_up ? "up" : "down");
break;
case KEY_BAUD:
case KEY_BAUD_UP:
case KEY_BAUD_DN:

83
term.c
View File

@ -100,7 +100,9 @@ static const char * const term_err_str[] = {
[TERM_EDTRUP] = "Cannot raise DTR",
[TERM_EMCTL] = "Cannot get mctl status",
[TERM_EDRAIN] = "Cannot drain the device",
[TERM_EBREAK] = "Cannot send break sequence"
[TERM_EBREAK] = "Cannot send break sequence",
[TERM_ERTSDOWN] = "Cannot lower RTS",
[TERM_ERTSUP] = "Cannot raise RTS"
};
static char term_err_buff[1024];
@ -137,6 +139,8 @@ term_strerror (int terrnum, int errnum)
case TERM_EDTRDOWN:
case TERM_EDTRUP:
case TERM_EMCTL:
case TERM_ERTSDOWN:
case TERM_ERTSUP:
snprintf(term_err_buff, sizeof(term_err_buff),
"%s", term_err_str[terrnum]);
rval = term_err_buff;
@ -1437,6 +1441,83 @@ term_lower_dtr(int fd)
return rval;
}
/***************************************************************************/
int
term_raise_rts(int fd)
{
int rval, i;
rval = 0;
do { /* dummy */
i = term_find(fd);
if ( i < 0 ) {
rval = -1;
break;
}
#ifdef __linux__
{
int r;
int opins = TIOCM_RTS;
r = ioctl(fd, TIOCMBIS, &opins);
if ( r < 0 ) {
term_errno = TERM_ERTSUP;
rval = -1;
break;
}
}
#else
term_errno = TERM_ERTSUP;
rval = -1;
#endif /* of __linux__ */
} while (0);
return rval;
}
/***************************************************************************/
int
term_lower_rts(int fd)
{
int rval, i;
rval = 0;
do { /* dummy */
i = term_find(fd);
if ( i < 0 ) {
rval = -1;
break;
}
#ifdef __linux__
{
int r;
int opins = TIOCM_RTS;
r = ioctl(fd, TIOCMBIC, &opins);
if ( r < 0 ) {
term_errno = TERM_ERTSDOWN;
rval = -1;
break;
}
}
#else
term_errno = TERM_ERTSDOWN;
rval = -1;
#endif /* of __linux__ */
} while (0);
return rval;
}
/***************************************************************************/
int

24
term.h
View File

@ -60,6 +60,8 @@
* F term_pulse_dtr - pulse the DTR line a device
* F term_lower_dtr - lower the DTR line of a device
* F term_raise_dtr - raise the DTR line of a device
* F term_lower_rts - lower the RTS line of a device
* F term_raise_rts - raise the RTS line of a device
* F term_get_mctl - Get modem control signals status
* F term_drain - drain the output from the terminal buffer
* F term_flush - discard terminal input and output queue contents
@ -142,7 +144,9 @@ enum term_errno_e {
TERM_EDTRUP,
TERM_EMCTL,
TERM_EDRAIN, /* see errno */
TERM_EBREAK
TERM_EBREAK,
TERM_ERTSDOWN,
TERM_ERTSUP
};
/* E parity_e
@ -605,6 +609,24 @@ int term_lower_dtr (int fd);
*/
int term_raise_dtr (int fd);
/* F term_lower_rts
*
* Lowers the RTS line of the device associated with the managed
* filedes "fd".
*
* Returns negative on failure, non negative on success.
*/
int term_lower_rts (int fd);
/* F term_raise_rts
*
* Raises the RTS line of the device associated with the managed
* filedes "fd".
*
* Returns negative on failure, non negative on success.
*/
int term_raise_rts (int fd);
/* F term_get_mctl
*
* Get the status of the modem control lines of the serial port