From: Marc D. <ma...@us...> - 2005-02-15 19:04:39
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20751/src/System Modified Files: SerialDevice.linux.cpp Log Message: get and set control and local flags Index: SerialDevice.linux.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SerialDevice.linux.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SerialDevice.linux.cpp 14 Feb 2005 22:53:15 -0000 1.3 +++ SerialDevice.linux.cpp 15 Feb 2005 19:03:56 -0000 1.4 @@ -190,7 +190,7 @@ switch( parity ) { case SerialDevice::ParityEven: ios.c_cflag |= PARENB ; - ios.c_cflag &= ~PARODD ; + ios.c_cflag &= ~PARODD ; // unset odd break ; case SerialDevice::ParityOdd: ios.c_cflag |= PARENB ; @@ -234,7 +234,7 @@ } if ( SerialDevice::FlowControlHard == fcontrol ) { - ios.c_iflag &= ~(IXON|IXOFF); + ios.c_iflag &= ~(IXON|IXOFF); //unset software ios.c_cflag |= CRTSCTS; ios.c_cc[VSTART] = _POSIX_VDISABLE; ios.c_cc[VSTOP] = _POSIX_VDISABLE; @@ -257,8 +257,7 @@ throw IO::IOError(errno, "Could not get flow control", P_SOURCEINFO); } - if( (ios.c_iflag & IXON) && - (ios.c_iflag & IXOFF) && + if( ( (ios.c_iflag & IXON) || (ios.c_iflag & IXOFF) ) && (CTRL_Q == ios.c_cc[VSTART]) && (CTRL_S == ios.c_cc[VSTOP]) ) { return SerialDevice::FlowControlSoft; @@ -269,13 +268,12 @@ } SerialDevice::InputFlags SerialDevice::inputFlags() throw(IO::IOError) { - InputFlags flags; - struct termios ios; if( ::tcgetattr(this->nosHandle(), &ios) == -1 ) { throw IO::IOError(errno, "Could not get input mode", P_SOURCEINFO); } - + + InputFlags flags; if(ios.c_iflag & IGNBRK) flags = static_cast<InputFlags>(flags | IgnoreBreak); if(ios.c_iflag & IGNPAR) flags = static_cast<InputFlags>(flags | IgnoreParityError); if(ios.c_iflag & BRKINT) flags = static_cast<InputFlags>(flags | BreakInt); @@ -324,6 +322,82 @@ } } +SerialDevice::OutputFlags SerialDevice::outputFlags() throw(IO::IOError) { + struct termios ios ; + if( ::tcgetattr(this->nosHandle(), &ios) == -1 ) { + throw IO::IOError(errno, "Could not get output mode", P_SOURCEINFO); + } + + OutputFlags flags; + if(ios.c_oflag & OPOST) flags = static_cast<OutputFlags>(flags | Post); + if(ios.c_oflag & OLCUC) flags = static_cast<OutputFlags>(flags | LowerToUpper); + if(ios.c_oflag & ONLCR) flags = static_cast<OutputFlags>(flags | ONlToCr); + if(ios.c_oflag & OCRNL) flags = static_cast<OutputFlags>(flags | OCrToNl); + if(ios.c_oflag & ONOCR) flags = static_cast<OutputFlags>(flags | NoCrCol0); + if(ios.c_oflag & ONLRET) flags = static_cast<OutputFlags>(flags | NoCr); + if(ios.c_oflag & OFILL) flags = static_cast<OutputFlags>(flags | Fill); + if(ios.c_oflag & OFDEL) flags = static_cast<OutputFlags>(flags | FillDel); + return flags; +} + +void SerialDevice::setOutputFlags(SerialDevice::OutputFlags flags) throw(IO::IOError) { + int oflags = 0; + if(flags & Post) oflags |= OPOST; + if(flags & LowerToUpper) oflags |= OLCUC; + if(flags & ONlToCr) oflags |= ONLCR; + if(flags & OCrToNl) oflags |= OCRNL; + if(flags & NoCrCol0) oflags |= ONOCR; + if(flags & NoCr) oflags |= ONLRET; + if(flags & Fill) oflags |= OFILL; + if(flags & FillDel) oflags |= OFDEL; + + struct termios ios ; + if( ::tcgetattr(this->nosHandle(), &ios) == -1 ) { + throw IO::IOError(errno, "Could not set output mode", P_SOURCEINFO); + } + + ios.c_oflag = oflags; + + if( ::tcsetattr(this->nosHandle(), TCSANOW, &ios) == -1) { + throw IO::IOError(errno, "Could not set output mode", P_SOURCEINFO); + } +} + +SerialDevice::ControlFlags SerialDevice::controlFlags() throw(IO::IOError) { + struct termios ios; + if( ::tcgetattr(this->nosHandle(), &ios) == -1 ) { + throw IO::IOError(errno, "Could not get control mode", P_SOURCEINFO); + } + + ControlFlags flags; + if(ios.c_cflag & CSTOPB) flags = static_cast<ControlFlags>(flags | StopBits); + if(ios.c_cflag & CREAD) flags = static_cast<ControlFlags>(flags | Read); + if(ios.c_cflag & HUPCL) flags = static_cast<ControlFlags>(flags | HangUp); + if(ios.c_cflag & CLOCAL) flags = static_cast<ControlFlags>(flags | Local); + //if(ios.c_cflag & LOBLK) flags = static_cast<ControlFlags>(flags | BlockShell); + return flags; +} + +void SerialDevice::setControlFlags(SerialDevice::ControlFlags flags) throw(IO::IOError) { + int cflags = 0; + if(flags & StopBits) cflags |= CSTOPB; + if(flags & Read) cflags |= CREAD; + if(flags & HangUp) cflags |= HUPCL; + if(flags & Local) cflags |= CLOCAL; + //if(flags & BlockShell) cflags |= LOBLK; + + struct termios ios ; + if( ::tcgetattr(this->nosHandle(), &ios) == -1 ) { + throw IO::IOError(errno, "Could not set control mode", P_SOURCEINFO); + } + + ios.c_cflag |= (tcflag_t)cflags; + + if( ::tcsetattr(this->nosHandle(), TCSANOW, &ios) == -1) { + throw IO::IOError(errno, "Could not set control mode", P_SOURCEINFO); + } +} + void SerialDevice::put(const UInt8& byte) throw(IO::IOError) { this->write((const char*)(&byte), 1); } @@ -338,8 +412,8 @@ int mode; switch(fmode) { - case FlushInput: mode = TCIFLUSH; break; - case FlushOutput: mode = TCOFLUSH; break; + case Input: mode = TCIFLUSH; break; + case Output: mode = TCOFLUSH; break; default: mode = TCIOFLUSH; // FlushAll }; |