/* DisplayTerminalSettings - Display the settings of a terminal Copyright (C) 2004 Frank Sorenson (frank@tuxrocks.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include int DisplayTermFlags_I(tcflag_t Flags) { if (Flags & IGNBRK) printf("IGNBRK "); if (Flags & BRKINT) printf("BRKINT "); if (Flags & IGNPAR) printf("IGNPAR "); if (Flags & PARMRK) printf("PARMRK "); if (Flags & INPCK) printf("INPCK "); if (Flags & ISTRIP) printf("ISTRIP "); if (Flags & INLCR) printf("INLCR "); if (Flags & IGNCR) printf("IGNCR "); if (Flags & ICRNL) printf("CRNL "); if (Flags & IUCLC) printf("IUCLC "); if (Flags & IXON) printf("IXON "); if (Flags & IXANY) printf("IXANY "); if (Flags & IXOFF) printf("IXOFF "); if (Flags & IMAXBEL) printf("IMAXBEL "); return(0); } int DisplayTermFlags_O(tcflag_t Flags) { if (Flags & OPOST) printf("OPOST "); if (Flags & OLCUC) printf("OLCUC "); if (Flags & ONLCR) printf("ONLCR "); if (Flags & OCRNL) printf("OCRNL "); if (Flags & ONOCR) printf("ONOCR "); if (Flags & ONLRET) printf("ONLRET "); if (Flags & OFILL) printf("OFILL "); if (Flags & OFDEL) printf("OFDEL "); if (Flags & NLDLY) printf("NLDLY "); if (Flags & CRDLY) printf("CRDLY "); if (Flags & TABDLY) printf("TABDLY "); if (Flags & BSDLY) printf("BSDLY "); if (Flags & VTDLY) printf("VTDLY "); if (Flags & FFDLY) printf("FFDLY "); return(0); } int DisplayTermFlags_C(tcflag_t Flags) { if (Flags & CSIZE) { printf("CSIZE "); if (Flags & CS5 & CSIZE) printf("CS5 "); if (Flags & CS6 & CSIZE) printf("CS6 "); if (Flags & CS7 & CSIZE) printf("CS7 "); if (Flags & CS8 & CSIZE) printf("CS8 "); } if (Flags & CSTOPB) printf("CSTOPB "); if (Flags & CREAD) printf("CREAD "); if (Flags & PARENB) printf("PARENB "); if (Flags & PARODD) printf("PARODD "); if (Flags & HUPCL) printf("HUPCL "); if (Flags & CLOCAL) printf("CLOCAL "); if (Flags & CIBAUD) printf("CIBAUD "); if (Flags & CRTSCTS) printf("CRTSCTS "); return(0); } int DisplayTermFlags_L(tcflag_t Flags) { if (Flags & ISIG) printf("ISIG "); if (Flags & ICANON) printf("ICANON "); if (Flags & XCASE) printf("XCASE "); if (Flags & ECHO) printf("ECHO "); if (Flags & ECHOE) printf("ECHOE "); if (Flags & ECHOK) printf("ECHOK "); if (Flags & ECHONL) printf("ECHONL "); if (Flags & ECHOCTL) printf("ECHOCTL "); if (Flags & ECHOPRT) printf("ECHOPRT "); if (Flags & ECHOKE) printf("ECHOKE "); if (Flags & FLUSHO) printf("FLUSHO "); if (Flags & NOFLSH) printf("NOFLSH "); if (Flags & TOSTOP) printf("TOSTOP "); if (Flags & PENDIN) printf("PENDIN "); if (Flags & IEXTEN) printf("IEXTEN "); return(0); } int GetTermSettings(int Port) { struct termios termios; int Result; Result = tcgetattr(Port, &termios); printf("iflag = 0x%X: ", termios.c_iflag); DisplayTermFlags_I(termios.c_iflag); printf("\n"); printf("oflag = 0x%X: ", termios.c_oflag); DisplayTermFlags_O(termios.c_oflag); printf("\n"); printf("cflag = 0x%X: ", termios.c_cflag); DisplayTermFlags_C(termios.c_cflag); printf("\n"); printf("lflag = 0x%X: ", termios.c_lflag); DisplayTermFlags_L(termios.c_lflag); printf("\n"); return(0); } int main (int argc, char *argv[]) { int Port; if (argc == 1) Port = open("/dev/ttyS0", O_RDWR | O_NOCTTY); else Port = open(argv[1], O_RDWR | O_NOCTTY); if (Port == -1) { printf("An error occurred while opening the port\n"); exit(-1); } GetTermSettings(Port); close (Port); return(0); }