Debug statements for termios struct.
#ifndef TERMIOS_DEBUG_H
#define TERMIOS_DEBUG_H
#include <termios.h>
void ptermios_iflag(struct termios *tty);
void ptermios_oflag(struct termios *tty);
void ptermios_cflag(struct termios *tty);
void ptermios_lflag(struct termios *tty);
void ptermios_cc(struct termios *tty);
void ptermios_modemlines(int fd);
void ptermios(struct termios *tty);
#endif /* TERMIOS_DEBUG_H */
#include <stdio.h>
#include <sys/ioctl.h>
#include "termios_dbg.h"
#define CHECK_BIT(var, pos) ((var) & (1<<(pos)))
void ptermios_iflag(struct termios *tty)
{
printf("c_iflag=0x%x\n", tty->c_iflag);
if (CHECK_BIT(tty->c_iflag, 0))
printf(" IGNBRK");
if (CHECK_BIT(tty->c_iflag, 1))
printf(" BRKINT");
if (CHECK_BIT(tty->c_iflag, 2))
printf(" IGNPAR");
if (CHECK_BIT(tty->c_iflag, 3))
printf(" PARMRK");
if (CHECK_BIT(tty->c_iflag, 4))
printf(" INPCK");
if (CHECK_BIT(tty->c_iflag, 5))
printf(" ISTRIP");
if (CHECK_BIT(tty->c_iflag, 6))
printf(" INLCR");
if (CHECK_BIT(tty->c_iflag, 7))
printf(" IGNCR");
if (CHECK_BIT(tty->c_iflag, 8))
printf(" ICRNL");
if (CHECK_BIT(tty->c_iflag, 9))
printf(" IUCLC");
if (CHECK_BIT(tty->c_iflag, 10))
printf(" IXON");
if (CHECK_BIT(tty->c_iflag, 11))
printf(" IXANY");
if (CHECK_BIT(tty->c_iflag, 12))
printf(" IXOFF");
if (CHECK_BIT(tty->c_iflag, 13))
printf(" IMAXBEL");
printf("\n");
}
void ptermios_oflag(struct termios *tty)
{
printf("c_oflag=0x%x\n", tty->c_oflag);
if (CHECK_BIT(tty->c_oflag, 0))
printf(" OPOST");
if (CHECK_BIT(tty->c_oflag, 1))
printf(" OLCUC");
if (CHECK_BIT(tty->c_oflag, 2))
printf(" ONLCR");
if (CHECK_BIT(tty->c_oflag, 3))
printf(" OCRNL");
if (CHECK_BIT(tty->c_oflag, 4))
printf(" ONOCR");
if (CHECK_BIT(tty->c_oflag, 5))
printf(" ONLRET");
if (CHECK_BIT(tty->c_oflag, 6))
printf(" OFILL");
if (CHECK_BIT(tty->c_oflag, 7))
printf(" OFDEL");
if ((tty->c_oflag & NLDLY) == NL0)
printf(" NL0");
if ((tty->c_oflag & NLDLY) == NL1)
printf(" NL1");
if ((tty->c_oflag & CRDLY) == CR0)
printf(" CR0");
if ((tty->c_oflag & CRDLY) == CR1)
printf(" CR1");
if ((tty->c_oflag & CRDLY) == CR2)
printf(" CR2");
if ((tty->c_oflag & CRDLY) == CR3)
printf(" CR3");
if ((tty->c_oflag & TABDLY) == TAB0)
printf(" TAB0");
if ((tty->c_oflag & TABDLY) == TAB1)
printf(" TAB1");
if ((tty->c_oflag & TABDLY) == TAB2)
printf(" TAB2");
if ((tty->c_oflag & TABDLY) == TAB3)
printf(" TAB3");
if ((tty->c_oflag & TABDLY) == XTABS)
printf(" XTABS");
if ((tty->c_oflag & BSDLY) == BS0)
printf(" BS0");
if ((tty->c_oflag & BSDLY) == BS1)
printf(" BS1");
if ((tty->c_oflag & VTDLY) == VT0)
printf(" VT0");
if ((tty->c_oflag & VTDLY) == VT1)
printf(" VT1");
if ((tty->c_oflag & FFDLY) == FF0)
printf(" FF0");
if ((tty->c_oflag & FFDLY) == FF1)
printf(" FF1");
printf("\n");
}
void ptermios_cflag(struct termios *tty)
{
printf("c_cflag=0x%x\n", tty->c_cflag);
if ((tty->c_cflag & CBAUD) == B0)
printf(" B0");
if ((tty->c_cflag & CBAUD) == B50)
printf(" B50");
if ((tty->c_cflag & CBAUD) == B75)
printf(" B75");
if ((tty->c_cflag & CBAUD) == B110)
printf(" B110");
if ((tty->c_cflag & CBAUD) == B134)
printf(" B134");
if ((tty->c_cflag & CBAUD) == B150)
printf(" B150");
if ((tty->c_cflag & CBAUD) == B200)
printf(" B200");
if ((tty->c_cflag & CBAUD) == B300)
printf(" B300");
if ((tty->c_cflag & CBAUD) == B600)
printf(" B600");
if ((tty->c_cflag & CBAUD) == B1200)
printf(" B1200");
if ((tty->c_cflag & CBAUD) == B1800)
printf(" B1800");
if ((tty->c_cflag & CBAUD) == B2400)
printf(" B2400");
if ((tty->c_cflag & CBAUD) == B4800)
printf(" B4800");
if ((tty->c_cflag & CBAUD) == B9600)
printf(" B9600");
if ((tty->c_cflag & CBAUD) == B19200)
printf(" B19200");
if ((tty->c_cflag & CBAUD) == B38400)
printf(" B38400");
if ((tty->c_cflag & CSIZE) == CS5)
printf(" CS5");
if ((tty->c_cflag & CSIZE) == CS6)
printf(" CS6");
if ((tty->c_cflag & CSIZE) == CS7)
printf(" CS7");
if ((tty->c_cflag & CSIZE) == CS8)
printf(" CS8");
if (CHECK_BIT(tty->c_cflag, 6))
printf(" CSTOPB");
if (CHECK_BIT(tty->c_cflag, 7))
printf(" CREAD");
if (CHECK_BIT(tty->c_cflag, 8))
printf(" PARENB");
if (CHECK_BIT(tty->c_cflag, 9))
printf(" PARODD");
if (CHECK_BIT(tty->c_cflag, 10))
printf(" HUPCL");
if (CHECK_BIT(tty->c_cflag, 11))
printf(" CLOCAL");
if (CHECK_BIT(tty->c_cflag, 31))
printf(" CRTSCTS");
printf("\n");
}
void ptermios_lflag(struct termios *tty)
{
printf("c_lflag=0x%x\n", tty->c_lflag);
if (CHECK_BIT(tty->c_lflag, 0))
printf(" ISIG");
if (CHECK_BIT(tty->c_lflag, 1))
printf(" ICANON");
if (CHECK_BIT(tty->c_lflag, 2))
printf(" XCASE");
if (CHECK_BIT(tty->c_lflag, 3))
printf(" ECHO");
if (CHECK_BIT(tty->c_lflag, 4))
printf(" ECHOE");
if (CHECK_BIT(tty->c_lflag, 5))
printf(" ECHOK");
if (CHECK_BIT(tty->c_lflag, 6))
printf(" ECHONL");
if (CHECK_BIT(tty->c_lflag, 7))
printf(" NOFLSH");
if (CHECK_BIT(tty->c_lflag, 8))
printf(" TOSTOP");
if (CHECK_BIT(tty->c_lflag, 9))
printf(" ECHOCTL");
if (CHECK_BIT(tty->c_lflag, 10))
printf(" ECHOPRT");
if (CHECK_BIT(tty->c_lflag, 11))
printf(" ECHOKE");
if (CHECK_BIT(tty->c_lflag, 12))
printf(" FLUSHO");
if (CHECK_BIT(tty->c_lflag, 14))
printf(" PENDIN");
if (CHECK_BIT(tty->c_lflag, 15))
printf(" IEXTEN");
printf("\n");
}
void ptermios_cc(struct termios *tty)
{
printf("VINTR=0x%x\n", tty->c_cc[VINTR]);
printf("VQUIT=0x%x\n", tty->c_cc[VQUIT]);
printf("VERASE=0x%x\n", tty->c_cc[VERASE]);
printf("VKILL=0x%x\n", tty->c_cc[VKILL]);
printf("VEOF=0x%x\n", tty->c_cc[VEOF]);
printf("VTIME=0x%x\n", tty->c_cc[VTIME]);
printf("VMIN=0x%x\n", tty->c_cc[VMIN]);
printf("VSWTC=0x%x\n", tty->c_cc[VSWTC]);
printf("VSTART=0x%x\n", tty->c_cc[VSTART]);
printf("VSTOP=0x%x\n", tty->c_cc[VSTOP]);
printf("VSUSP=0x%x\n", tty->c_cc[VSUSP]);
printf("VEOL=0x%x\n", tty->c_cc[VEOL]);
printf("VREPRINT=0x%x\n", tty->c_cc[VREPRINT]);
printf("VDISCARD=0x%x\n", tty->c_cc[VDISCARD]);
printf("VWERASE=0x%x\n", tty->c_cc[VWERASE]);
printf("VLNEXT=0x%x\n", tty->c_cc[VLNEXT]);
printf("VEOL2=0x%x\n", tty->c_cc[VEOL2]);
}
void ptermios_modemlines(int fd)
{
int controlbits;
if (ioctl(fd, TIOCMGET, &controlbits) == -1)
fprintf(stderr, "ptermios_modemlines: TIOCMGET\n");
printf("modem=0x%x\n", controlbits);
printf("%d\tDSR (data set ready/line enable)\n", CHECK_BIT(controlbits, 0) ? 1 : 0);
printf("%d\tDTR (data terminal ready)\n", CHECK_BIT(controlbits, 1) ? 1 : 0);
printf("%d\tRTS (request to send)\n", CHECK_BIT(controlbits, 2) ? 1 : 0);
printf("%d\tSecondary TXD (transmit)\n", CHECK_BIT(controlbits, 3) ? 1 : 0);
printf("%d\tSecondary RXD (receive)\n", CHECK_BIT(controlbits, 4) ? 1 : 0);
printf("%d\tCTS (clear to send)\n", CHECK_BIT(controlbits, 5) ? 1 : 0);
printf("%d\tDCD (data carrier detect)\n", CHECK_BIT(controlbits, 6) ? 1 : 0);
printf("%d\tTIOCM_CAR\n", CHECK_BIT(controlbits, 7) ? 1 : 0);
printf("%d\tRNG (ring)\n", CHECK_BIT(controlbits, 8) ? 1 : 0);
printf("%d\tTIOCM_RNG\n", CHECK_BIT(controlbits, 9) ? 1 : 0);
printf("%d\tDSR (data set ready)\n", CHECK_BIT(controlbits, 10) ? 1 : 0);
}
void ptermios(struct termios *tty)
{
ptermios_iflag(tty);
ptermios_oflag(tty);
ptermios_cflag(tty);
ptermios_lflag(tty);
ptermios_cc(tty);
}