mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
term.[ch]: Added term_get_mctl() function
Returns the status of modem-control lines (DTR, DSR, DCD, etc...).
This commit is contained in:
40
term.c
40
term.c
@ -80,6 +80,7 @@ static const char * const term_err_str[] = {
|
||||
[TERM_EFLOW] = "Invalid flowcontrol mode",
|
||||
[TERM_EDTRDOWN] = "Cannot lower DTR",
|
||||
[TERM_EDTRUP] = "Cannot raise DTR",
|
||||
[TERM_EMCTL] = "Cannot get mctl status",
|
||||
[TERM_EDRAIN] = "Cannot drain the device",
|
||||
[TERM_EBREAK] = "Cannot send break sequence"
|
||||
};
|
||||
@ -117,6 +118,7 @@ term_strerror (int terrnum, int errnum)
|
||||
case TERM_EFLOW:
|
||||
case TERM_EDTRDOWN:
|
||||
case TERM_EDTRUP:
|
||||
case TERM_EMCTL:
|
||||
snprintf(term_err_buff, sizeof(term_err_buff),
|
||||
"%s", term_err_str[terrnum]);
|
||||
rval = term_err_buff;
|
||||
@ -1419,6 +1421,44 @@ term_lower_dtr(int fd)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int
|
||||
term_get_mctl (int fd)
|
||||
{
|
||||
int mctl, i;
|
||||
|
||||
do { /* dummy */
|
||||
|
||||
i = term_find(fd);
|
||||
if ( i < 0 ) {
|
||||
mctl = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
{
|
||||
int r, pmctl;
|
||||
|
||||
r = ioctl(fd, TIOCMGET, &pmctl);
|
||||
if (r < 0) {
|
||||
mctl = -1;
|
||||
break;
|
||||
}
|
||||
mctl = 0;
|
||||
if (pmctl & TIOCM_DTR) mctl |= MCTL_DTR;
|
||||
if (pmctl & TIOCM_DSR) mctl |= MCTL_DSR;
|
||||
if (pmctl & TIOCM_CD) mctl |= MCTL_DCD;
|
||||
if (pmctl & TIOCM_RTS) mctl |= MCTL_RTS;
|
||||
if (pmctl & TIOCM_CTS) mctl |= MCTL_CTS;
|
||||
if (pmctl & TIOCM_RI) mctl |= MCTL_RI;
|
||||
}
|
||||
#else
|
||||
mctl = MCTL_UNAVAIL;
|
||||
#endif
|
||||
} while(0);
|
||||
|
||||
return mctl;
|
||||
}
|
||||
|
||||
int
|
||||
term_drain(int fd)
|
||||
{
|
||||
|
27
term.h
27
term.h
@ -60,6 +60,7 @@
|
||||
* 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_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
|
||||
* F term_break - generate a break condition on a device
|
||||
@ -139,6 +140,7 @@ enum term_errno_e {
|
||||
TERM_EFLOW,
|
||||
TERM_EDTRDOWN,
|
||||
TERM_EDTRUP,
|
||||
TERM_EMCTL,
|
||||
TERM_EDRAIN, /* see errno */
|
||||
TERM_EBREAK
|
||||
};
|
||||
@ -178,6 +180,20 @@ enum flowcntrl_e {
|
||||
FC_OTHER
|
||||
};
|
||||
|
||||
/*
|
||||
* C MCTL_xxx
|
||||
*
|
||||
* Modem control line bits. Used against the return value of
|
||||
* term_get_mctl().
|
||||
*/
|
||||
#define MCTL_DTR (1<<1) /* O: Data Terminal Ready */
|
||||
#define MCTL_DSR (1<<2) /* I: Data Set Ready */
|
||||
#define MCTL_DCD (1<<3) /* I: Data Carrier Detect */
|
||||
#define MCTL_RTS (1<<4) /* O: Request To Send */
|
||||
#define MCTL_CTS (1<<5) /* I: Clear To Send */
|
||||
#define MCTL_RI (1<<6) /* I: Ring Indicator */
|
||||
#define MCTL_UNAVAIL (1<<0) /* MCTL lines (status) not available */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/*
|
||||
@ -589,6 +605,17 @@ int term_lower_dtr (int fd);
|
||||
*/
|
||||
int term_raise_dtr (int fd);
|
||||
|
||||
/* F term_get_mctl
|
||||
*
|
||||
* Get the status of the modem control lines of the serial port
|
||||
* (terminal) associated with the managed filedes "fd".
|
||||
*
|
||||
* On error (fd is not managed) return a negative. If the feature is
|
||||
* not available returns MCTL_UNAVAIL. Otherwise returns a word that
|
||||
* can be checked against the MCTL_* flags.
|
||||
*/
|
||||
int term_get_mctl (int fd);
|
||||
|
||||
/* F term_drain
|
||||
*
|
||||
* Drains (flushes) the output queue of the device associated with the
|
||||
|
Reference in New Issue
Block a user