simgear  3.5.0 [next] git://gitorious.org/fg/simgear.git
SimGear - Simulator Construction Tools
SGSerial Class Reference

#include <sg_serial.hxx>

Inheritance diagram for SGSerial:
SGIOChannel

Public Member Functions

 SGSerial (const std::string &device_name, const std::string &baud_rate)
 
 ~SGSerial ()
 
bool close ()
 
virtual bool eof () const
 
string get_baud () const
 
string get_device () const
 
SGProtocolDir get_dir () const
 
SGChannelType get_type () const
 
bool isvalid () const
 
bool open (const SGProtocolDir d)
 
int read (char *buf, int length)
 
int readline (char *buf, int length)
 
void set_dir (const SGProtocolDir d)
 
void set_type (SGChannelType t)
 
void set_valid (const bool v)
 
int write (const char *buf, const int length)
 
int writestring (const char *str)
 

Private Attributes

std::string baud
 
std::string device
 
SGSerialPort port
 
char save_buf [2 *SG_IO_MAX_MSG_SIZE]
 
int save_len
 

Detailed Description

A serial I/O class based on SGIOChannel.

Definition at line 46 of file sg_serial.hxx.

Constructor & Destructor Documentation

SGSerial::SGSerial ( const std::string &  device_name,
const std::string &  baud_rate 
)

Create an instance of SGSerial. This creates an instance of the SGSerial class. You need to provide the serial device name and desired baud rate. For Unix style systems, device names will be similar to /dev/ttyS0''. For DOS style systems you may want to use something similar toCOM1:''. As with the SGFile class, device is not opened immediately, but instead will be opened when the open() method is called.

Parameters
device_namename of serial device
baud_ratespeed of communication

Definition at line 38 of file sg_serial.cxx.

SGSerial::~SGSerial ( )

Destructor

Definition at line 47 of file sg_serial.cxx.

Member Function Documentation

bool SGSerial::close ( void  )
virtual

The close() method is modeled after the close() Unix system call and will close an open device. You should call this method when you are done using your IO class, before it is destructed.

Returns
result of close

Reimplemented from SGIOChannel.

Definition at line 153 of file sg_serial.cxx.

bool SGIOChannel::eof ( ) const
virtualinherited

The eof() method returns true if end of file has been reached in a context where that makes sense. Otherwise it returns false.

Returns
result of eof check

Reimplemented in SGFile.

Definition at line 76 of file iochannel.cxx.

string SGSerial::get_baud ( ) const
inline
Returns
the baud rate

Definition at line 96 of file sg_serial.hxx.

string SGSerial::get_device ( ) const
inline
Returns
the serial port device name

Definition at line 93 of file sg_serial.hxx.

SGProtocolDir SGIOChannel::get_dir ( ) const
inlineinherited

Definition at line 158 of file iochannel.hxx.

Referenced by SGFile::open(), and SGSocketUDP::open().

SGChannelType SGIOChannel::get_type ( ) const
inlineinherited

Definition at line 155 of file iochannel.hxx.

bool SGIOChannel::isvalid ( ) const
inlineinherited
bool SGSerial::open ( const SGProtocolDir  d)
virtual

Open a channel.

Parameters
dchannel communication "direction" Direction can be one of:
  • SG_IO_IN - data will be flowing into this object to the application.
  • SG_IO_OUT - data will be flowing out of this object from the application.
  • SG_IO_BI - data will be flowing in both directions.
  • SG_IO_NONE - data will not be flowing in either direction. This is here for the sake of completeness.
Returns
result of open

Reimplemented from SGIOChannel.

Definition at line 52 of file sg_serial.cxx.

int SGSerial::read ( char *  buf,
int  length 
)
virtual

The read() method is modeled after the read() Unix system call. You must provide a pointer to a character buffer that has enough allocated space for your potential read. You can also specify the maximum number of bytes allowed for this particular read. The actual number of bytes read is returned. You are responsible to ensure that the size of buf is large enough to accomodate your input message

Parameters
bufa char pointer to your input buffer
lengthmax number of bytes to read
Returns
number of bytes read

Reimplemented from SGIOChannel.

Definition at line 75 of file sg_serial.cxx.

int SGSerial::readline ( char *  buf,
int  length 
)
virtual

The readline() method is similar to read() except that it will stop at the first end of line encountered in the input buffer.

Parameters
bufa char pointer to your input buffer
lengthmax number of bytes to read
Returns
number of bytes read

Reimplemented from SGIOChannel.

Definition at line 96 of file sg_serial.cxx.

void SGIOChannel::set_dir ( const SGProtocolDir  d)
inlineinherited

Definition at line 157 of file iochannel.hxx.

Referenced by SGFile::open(), open(), SGSocketUDP::open(), and SGSocket::open().

void SGIOChannel::set_type ( SGChannelType  t)
inlineinherited

Definition at line 154 of file iochannel.hxx.

Referenced by SGFile::SGFile(), SGSerial(), and SGSocket::SGSocket().

void SGIOChannel::set_valid ( const bool  v)
inlineinherited

Definition at line 160 of file iochannel.hxx.

Referenced by SGSocketUDP::open(), and SGSocketUDP::SGSocketUDP().

int SGSerial::write ( const char *  buf,
const int  length 
)
virtual

The write() method is modeled after the write() Unix system call and is analogous to the read() method. You provide a pointer to a buffer of data, and then length of that data to be written out. The number of bytes written is returned.

Parameters
bufa char pointer to your output buffer
lengthnumber of bytes to write
Returns
number of bytes written

Reimplemented from SGIOChannel.

Definition at line 134 of file sg_serial.cxx.

Referenced by writestring().

int SGSerial::writestring ( const char *  str)
virtual

The writestring() method is a simple wrapper that will calculate the length of a null terminated character array and write it to the output channel.

Parameters
bufa char pointer to your output buffer
Returns
number of bytes written

Reimplemented from SGIOChannel.

Definition at line 146 of file sg_serial.cxx.

Member Data Documentation

std::string SGSerial::baud
private

Definition at line 49 of file sg_serial.hxx.

Referenced by get_baud(), open(), and SGSerial().

std::string SGSerial::device
private

Definition at line 48 of file sg_serial.hxx.

Referenced by get_device(), open(), SGSerial(), and write().

SGSerialPort SGSerial::port
private

Definition at line 50 of file sg_serial.hxx.

Referenced by close(), open(), read(), readline(), and write().

char SGSerial::save_buf[2 *SG_IO_MAX_MSG_SIZE]
private

Definition at line 52 of file sg_serial.hxx.

Referenced by read(), and readline().

int SGSerial::save_len
private

Definition at line 53 of file sg_serial.hxx.

Referenced by read(), and readline().


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