GNU CommonC++
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ost::TTYStream Class Reference

TTY streams are used to represent serial connections that are fully "streamable" objects using C++ stream classes and friends. More...

#include <serial.h>

Inheritance diagram for ost::TTYStream:
ost::Serial ost::TTYSession ost::ttystream

Public Member Functions

 TTYStream (const char *filename, timeout_t to=0)
 Create and open a tty serial port.
 
virtual ~TTYStream ()
 End the tty stream and cleanup.
 
void setTimeout (timeout_t to)
 Set the timeout control.
 
void interactive (bool flag)
 Set tty mode to buffered or "interactive".
 
int sync (void)
 Flushes the stream input and out buffers, writes pending output.
 
bool isPending (Pending pend, timeout_t timeout=TIMEOUT_INF)
 Get the status of pending operations.
 
- Public Member Functions inherited from ost::Serial
virtual ~Serial ()
 The serial base class may be "thrown" as a result on an error, and the "catcher" may then choose to destory the object.
 
Serialoperator= (const Serial &from)
 Serial ports may also be duplecated by the assignment operator.
 
Error setSpeed (unsigned long speed)
 Set serial port speed for both input and output.
 
Error setCharBits (int bits)
 Set character size.
 
Error setParity (Parity parity)
 Set parity mode.
 
Error setStopBits (int bits)
 Set number of stop bits.
 
Error setFlowControl (Flow flow)
 Set flow control.
 
void toggleDTR (timeout_t millisec)
 Set the DTR mode off momentarily.
 
void sendBreak (void)
 Send the "break" signal.
 
Error getErrorNumber (void)
 Often used by a "catch" to fetch the last error of a thrown serial.
 
char * getErrorString (void)
 Often used by a "catch" to fetch the user set error string of a thrown serial.
 
int getBufferSize (void)
 Get the "buffer" size for buffered operations.
 
virtual bool isPending (Pending pend, timeout_t timeout=TIMEOUT_INF)
 Get the status of pending operations.
 

Protected Member Functions

 TTYStream ()
 This constructor is used to derive "ttystream", a more C++ style version of the TTYStream class.
 
void allocate (void)
 Used to allocate the buffer space needed for iostream operations.
 
void endStream (void)
 Used to terminate the buffer space and clean up the tty connection.
 
int underflow (void)
 This streambuf method is used to load the input buffer through the established tty serial port.
 
int uflow (void)
 This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode.
 
int overflow (int ch)
 This streambuf method is used to write the output buffer through the established tty port.
 
- Protected Member Functions inherited from ost::Serial
void open (const char *fname)
 Opens the serial device.
 
void close (void)
 Closes the serial device.
 
virtual int aRead (char *Data, const int Length)
 Reads from serial device.
 
virtual int aWrite (const char *Data, const int Length)
 Writes to serial device.
 
Error error (Error error, char *errstr=NULL)
 This service is used to throw all serial errors which usually occur during the serial constructor.
 
void error (char *err)
 This service is used to thow application defined serial errors where the application specific error code is a string.
 
void setError (bool enable)
 This method is used to turn the error handler on or off for "throwing" execptions by manipulating the thrown flag.
 
int setPacketInput (int size, unsigned char btimer=0)
 Set packet read mode and "size" of packet read buffer.
 
int setLineInput (char newline=13, char nl1=0)
 Set "line buffering" read mode and specifies the newline character to be used in seperating line records.
 
void restore (void)
 Restore serial device to the original settings at time of open.
 
void flushInput (void)
 Used to flush the input waiting queue.
 
void flushOutput (void)
 Used to flush any pending output data.
 
void waitOutput (void)
 Used to wait until all output has been sent.
 
void endSerial (void)
 Used as the default destructor for ending serial I/O services.
 
void initConfig (void)
 Used to initialize a newly opened serial file handle.
 
 Serial ()
 This allows later ttystream class to open and close a serial device.
 
 Serial (const char *name)
 A serial object may be constructed from a named file on the file system.
 

Protected Attributes

char * gbuf
 
char * pbuf
 
timeout_t timeout
 
- Protected Attributes inherited from ost::Serial
HANDLE dev
 
int bufsize
 

Friends

TTYStreamcrlf (TTYStream &)
 
TTYStreamlfcr (TTYStream &)
 

Additional Inherited Members

- Public Types inherited from ost::Serial
enum  Error {
  errSuccess = 0 , errOpenNoTty , errOpenFailed , errSpeedInvalid ,
  errFlowInvalid , errParityInvalid , errCharsizeInvalid , errStopbitsInvalid ,
  errOptionInvalid , errResourceFailure , errOutput , errInput ,
  errTimeout , errExtended
}
 
enum  Flow { flowNone , flowSoft , flowHard , flowBoth }
 
enum  Parity { parityNone , parityOdd , parityEven }
 
enum  Pending { pendingInput , pendingOutput , pendingError }
 
typedef enum Error Error
 
typedef enum Flow Flow
 
typedef enum Parity Parity
 
typedef enum Pending Pending
 

Detailed Description

TTY streams are used to represent serial connections that are fully "streamable" objects using C++ stream classes and friends.

The first application relevant serial I/O class is the TTYStream class. TTYStream offers a linearly buffered "streaming" I/O session with the serial device. Furthermore, traditional C++ "stream" operators (<< and

‍>) may be used with the serial device. A more "true" to ANSI C++ library

format "ttystream" is also available, and this supports an "open" method in which one can pass initial serial device parameters immediately following the device name in a single string, as in "/dev/tty3a:9600,7,e,1", as an example.

The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution context that will be used to perform actual I/O operations. This class is very anagolous to TCPSession.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m

streamable tty serial I/O class.

Constructor & Destructor Documentation

◆ TTYStream() [1/2]

ost::TTYStream::TTYStream ( )
protected

This constructor is used to derive "ttystream", a more C++ style version of the TTYStream class.

◆ TTYStream() [2/2]

ost::TTYStream::TTYStream ( const char *  filename,
timeout_t  to = 0 
)

Create and open a tty serial port.

Parameters
filenamechar name of device to open.
todefault timeout.

◆ ~TTYStream()

virtual ost::TTYStream::~TTYStream ( )
virtual

End the tty stream and cleanup.

Member Function Documentation

◆ allocate()

void ost::TTYStream::allocate ( void  )
protected

Used to allocate the buffer space needed for iostream operations.

This is based on MAX_INPUT.

◆ endStream()

void ost::TTYStream::endStream ( void  )
protected

Used to terminate the buffer space and clean up the tty connection.

This function is called by the destructor.

◆ interactive()

void ost::TTYStream::interactive ( bool  flag)

Set tty mode to buffered or "interactive".

When interactive, all streamed I/O is directly sent to the serial port immediately.

Parameters
flagbool set to true to make interactive.

◆ isPending()

bool ost::TTYStream::isPending ( Pending  pend,
timeout_t  timeout = TIMEOUT_INF 
)
virtual

Get the status of pending operations.

This can be used to examine if input or output is waiting, or if an error has occured on the serial device. If read buffer contains data then input is ready and if write buffer contains data it is first flushed then checked.

Returns
true if ready, false if timeout.
Parameters
pendready check to perform.
timeoutin milliseconds.

Reimplemented from ost::Serial.

◆ overflow()

int ost::TTYStream::overflow ( int  ch)
protected

This streambuf method is used to write the output buffer through the established tty port.

Parameters
chchar to push through.
Returns
char pushed through.

◆ setTimeout()

void ost::TTYStream::setTimeout ( timeout_t  to)
inline

Set the timeout control.

Parameters
totimeout to use.

◆ sync()

int ost::TTYStream::sync ( void  )

Flushes the stream input and out buffers, writes pending output.

Returns
0 on success.

◆ uflow()

int ost::TTYStream::uflow ( void  )
protected

This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode.

Also this method will handle proper use of buffers if not in interative mode.

Returns
char from tty serial port, EOF also possible.

◆ underflow()

int ost::TTYStream::underflow ( void  )
protected

This streambuf method is used to load the input buffer through the established tty serial port.

Returns
char from get buffer, EOF also possible.

Friends And Related Symbol Documentation

◆ crlf

TTYStream & crlf ( TTYStream )
friend

◆ lfcr

TTYStream & lfcr ( TTYStream )
friend

Member Data Documentation

◆ gbuf

char* ost::TTYStream::gbuf
protected

◆ pbuf

char * ost::TTYStream::pbuf
protected

◆ timeout

timeout_t ost::TTYStream::timeout
protected

The documentation for this class was generated from the following file: