mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
Add command to toggle RTS
This commit is contained in:
@ -64,7 +64,7 @@ here.
|
||||
|
||||
: Quit the program _without_ reseting 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,11 @@ 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.
|
||||
|
||||
**C-backslash**
|
||||
|
||||
: Generate a break sequence on the serial line. A break sequence is
|
||||
@ -83,7 +88,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**
|
||||
|
32
picocom.c
32
picocom.c
@ -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:
|
||||
|
105
term.c
105
term.c
@ -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,105 @@ term_lower_dtr(int fd)
|
||||
return rval;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int
|
||||
term_raise_rts(int fd)
|
||||
{
|
||||
int rval, r, i;
|
||||
|
||||
rval = 0;
|
||||
|
||||
do { /* dummy */
|
||||
|
||||
i = term_find(fd);
|
||||
if ( i < 0 ) {
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
{
|
||||
int opins = TIOCM_RTS;
|
||||
|
||||
r = ioctl(fd, TIOCMBIS, &opins);
|
||||
if ( r < 0 ) {
|
||||
term_errno = TERM_ERTSUP;
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
r = tcsetattr(fd, TCSANOW, &term.currtermios[i]);
|
||||
if ( r < 0 ) {
|
||||
/* FIXME: perhaps try to update currtermios */
|
||||
term_errno = TERM_ESETATTR;
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
#endif /* of __linux__ */
|
||||
} while (0);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int
|
||||
term_lower_rts(int fd)
|
||||
{
|
||||
int rval, r, i;
|
||||
|
||||
rval = 0;
|
||||
|
||||
do { /* dummy */
|
||||
|
||||
i = term_find(fd);
|
||||
if ( i < 0 ) {
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
{
|
||||
int opins = TIOCM_RTS;
|
||||
|
||||
r = ioctl(fd, TIOCMBIC, &opins);
|
||||
if ( r < 0 ) {
|
||||
term_errno = TERM_ERTSDOWN;
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
struct termios tio;
|
||||
|
||||
r = tcgetattr(fd, &tio);
|
||||
if ( r < 0 ) {
|
||||
term_errno = TERM_EGETATTR;
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
term.currtermios[i] = tio;
|
||||
|
||||
cfsetospeed(&tio, B0);
|
||||
cfsetispeed(&tio, B0);
|
||||
|
||||
r = tcsetattr(fd, TCSANOW, &tio);
|
||||
if ( r < 0 ) {
|
||||
term_errno = TERM_ESETATTR;
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* of __linux__ */
|
||||
} while (0);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int
|
||||
|
24
term.h
24
term.h
@ -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
|
||||
|
Reference in New Issue
Block a user