nidas
v1.2-1520
|
#include <SerialPort.h>
Public Member Functions | |
SerialPort () | |
SerialPort (const SerialPort &) | |
Copy constructor. More... | |
SerialPort (const std::string &name) | |
Constructor, given a device name. More... | |
SerialPort (const std::string &name, int fd) throw (IOException) | |
For serial port that is already open (stdin for example). More... | |
virtual | ~SerialPort () |
close the file descriptor if is is open. More... | |
Termios & | termios () |
Writable reference to the SerialPort's Termios. More... | |
const Termios & | getTermios () const |
Readonly reference to Termios. More... | |
void | applyTermios () throw (IOException) |
Apply the Termios settings to an opened serial port. More... | |
const std::string & | getName () const |
Get device name of the SerialPort. More... | |
void | setName (const std::string &val) |
Set device name of the SerialPort. More... | |
virtual int | open (int mode=O_RDONLY) throw (IOException) |
open the serial port. More... | |
void | close () |
close the file descriptor. More... | |
int | getFd () const |
int | getModemStatus () throw (IOException) |
Get the current state of the modem bits. More... | |
void | setModemStatus (int val) throw (IOException) |
Set the current state of the modem bits. More... | |
void | clearModemBits (int val) throw (IOException) |
Clear the indicated modem bits. More... | |
void | setModemBits (int val) throw (IOException) |
Set the indicated modem bits. More... | |
bool | getCarrierDetect () throw (IOException) |
void | setBlocking (bool val) throw (IOException) |
bool | getBlocking () throw (IOException) |
void | drain () throw (IOException) |
Do a tcdrain() system call on the device. More... | |
void | flushInput () throw (IOException) |
Do a tcflush() system call on the device. More... | |
void | flushOutput () throw (IOException) |
Do a tcflush() system call on the device. More... | |
void | flushBoth () throw (IOException) |
int | timeoutOrEOF () const |
virtual int | readUntil (char *buf, int len, char term) throw (IOException) |
Read bytes until either the term character is read, or len-1 number of characters have been read. More... | |
virtual int | readLine (char *buf, int len) throw (IOException) |
Do a readUntil with a newline terminator. More... | |
virtual int | read (char *buf, int len) throw (IOException) |
virtual char | readchar () throw (IOException) |
Do a buffered read and return character read. More... | |
virtual int | write (const void *buf, int len) throw (IOException) |
Static Public Member Functions | |
static std::string | modemFlagsToString (int modem) |
static int | createPtyLink (const std::string &linkname) throw (IOException) |
Static utility that creates a pseudo-terminal, returning the file descriptor of the master side and creating a symbolic link with the given name to the slave side. More... | |
Private Types | |
enum | state { OK, TIMEOUT_OR_EOF } |
Private Member Functions | |
SerialPort & | operator= (const SerialPort &) |
No assignment. More... | |
Private Attributes | |
Termios | _termios |
int | _fd |
std::string | _name |
enum nidas::util::SerialPort::state | _state |
char * | _savep |
char * | _savebuf |
int | _savelen |
int | _savealloc |
bool | _blocking |
|
private |
SerialPort::SerialPort | ( | ) |
SerialPort::SerialPort | ( | const SerialPort & | x | ) |
Copy constructor.
The attributes of the port are copied, but if the original is opened, the copy will not be opened.
SerialPort::SerialPort | ( | const std::string & | name | ) |
Constructor, given a device name.
The device is NOT opened, mainly just to avoid throwing an exception in the constructor. Perhaps that should be changed.
SerialPort::SerialPort | ( | const std::string & | name, |
int | fd | ||
) | |||
throw | ( | IOException | |
) |
For serial port that is already open (stdin for example).
|
virtual |
void SerialPort::applyTermios | ( | ) | ||
throw | ( | IOException | ||
) |
Apply the Termios settings to an opened serial port.
References _fd, _name, _termios, and nidas::util::Termios::apply().
void SerialPort::clearModemBits | ( | int | val | ) | |
throw | ( | IOException | |||
) |
Clear the indicated modem bits.
Referenced by nidas::dynld::isff::SE_GOESXmtr::tosleep(), and nidas::dynld::isff::SE_GOESXmtr::wakeup().
void SerialPort::close | ( | ) |
close the file descriptor.
References _fd, getName(), and ILOG.
Referenced by Garmin::run(), GPS_SetClock::run(), and ~SerialPort().
|
static |
Static utility that creates a pseudo-terminal, returning the file descriptor of the master side and creating a symbolic link with the given name to the slave side.
linkname,: | Name of symbolic link to be created that links to the slave side of the pseudo-terminal. If a symbolic link already exists with that name it will be removed and re-created. If linkname already exists and it isn't a symbolic link, an error will be returned. |
Note: the symbolic link should be deleted when the file descriptor to the master pseudo-terminal is closed. Otherwise, because of the way the system recycles pseudo-terminal devices, the link may at some time point to a different pseudo-terminal, probably created by a different process, like sshd. Opening and reading/writing to the symbolic link would then effect the other process, if the open was permitted.
References fd.
Referenced by SensorSimApp::main(), TeeTTy::run(), and TeeI2C::run().
void SerialPort::drain | ( | ) | ||
throw | ( | IOException | ||
) |
void SerialPort::flushBoth | ( | ) | ||
throw | ( | IOException | ||
) |
Referenced by nidas::dynld::isff::GOESXmtr::open(), and openPort().
void SerialPort::flushInput | ( | ) | ||
throw | ( | IOException | ||
) |
void SerialPort::flushOutput | ( | ) | ||
throw | ( | IOException | ||
) |
bool SerialPort::getBlocking | ( | ) | ||
throw | ( | IOException | ||
) |
bool SerialPort::getCarrierDetect | ( | ) | ||
throw | ( | IOException | ||
) |
References getModemStatus().
|
inline |
References _fd.
Referenced by GPS_SetClock::run(), TeeTTy::run(), Receiver::run(), and Csat3Sim::run().
int SerialPort::getModemStatus | ( | ) | ||
throw | ( | IOException | ||
) |
Get the current state of the modem bits.
Do "man tty_ioctl" from Linux for more information. These macros are useful for checking/setting the value of of individual bits:
Referenced by getCarrierDetect(), openPort(), ModemLineSetter::run(), ModemLineMonitor::run(), nidas::dynld::isff::SE_GOESXmtr::tosleep(), and nidas::dynld::isff::SE_GOESXmtr::wakeup().
|
inline |
Get device name of the SerialPort.
References _name.
Referenced by close(), nidas::dynld::isff::SimGOESXmtr::printStatus(), Garmin::readMessage(), GPS_SetClock::run(), TeeTTy::run(), and Csat3Sim::run().
|
inline |
Readonly reference to Termios.
References _termios.
Referenced by nidas::dynld::isff::SE_GOESXmtr::getXmtrClockDelay().
|
static |
Referenced by openPort(), ModemLineSetter::run(), and ModemLineMonitor::run().
|
virtual |
open the serial port.
The current Termios settings are also applied to the port.
References ILOG.
Referenced by nidas::dynld::isff::GOESXmtr::open(), openPort(), Garmin::run(), GPS_SetClock::run(), and TeeTTy::run().
|
private |
No assignment.
|
virtual |
References len.
Referenced by readchar(), TeeTTy::run(), Receiver::run(), and Csat3Sim::run().
|
virtual |
Do a buffered read and return character read.
If '\0' is read, then do a check of timeoutOrEOF() to see if the basic read returned 0.
References _savealloc, _savebuf, _savelen, _savep, and read().
|
virtual |
|
virtual |
Read bytes until either the term character is read, or len-1 number of characters have been read.
buf will be null terminated.
References len.
Referenced by Garmin::readMessage().
void SerialPort::setBlocking | ( | bool | val | ) | |
throw | ( | IOException | |||
) |
Referenced by openPort().
void SerialPort::setModemBits | ( | int | val | ) | |
throw | ( | IOException | |||
) |
Set the indicated modem bits.
Referenced by nidas::dynld::isff::SE_GOESXmtr::wakeup().
void SerialPort::setModemStatus | ( | int | val | ) | |
throw | ( | IOException | |||
) |
Set the current state of the modem bits.
Referenced by ModemLineSetter::run().
|
inline |
|
inline |
Writable reference to the SerialPort's Termios.
If the SerialPort is open, the user should call applyTermios() for any modifications to take effect.
References _termios.
Referenced by openPort(), Garmin::run(), GPS_SetClock::run(), TeeTTy::run(), and nidas::dynld::isff::SE_GOESXmtr::SE_GOESXmtr().
|
inline |
References _state, and TIMEOUT_OR_EOF.
|
virtual |
|
private |
Referenced by getBlocking().
|
private |
Referenced by applyTermios(), close(), drain(), flushBoth(), flushInput(), flushOutput(), getBlocking(), getFd(), and getModemStatus().
|
private |
Referenced by applyTermios(), drain(), flushBoth(), flushInput(), flushOutput(), getBlocking(), getModemStatus(), getName(), and setName().
|
private |
Referenced by readchar().
|
private |
Referenced by readchar(), and ~SerialPort().
|
private |
Referenced by readchar().
|
private |
Referenced by readchar().
|
private |
Referenced by timeoutOrEOF().
|
private |
Referenced by applyTermios(), getTermios(), and termios().