00001 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef _SG_SERIAL_HXX
00028 #define _SG_SERIAL_HXX
00029 
00030 
00031 #ifndef __cplusplus
00032 # error This library requires C++
00033 #endif
00034 
00035 #include <simgear/compiler.h>
00036 
00037 #include <string>
00038 
00039 #include <simgear/serial/serial.hxx>
00040 
00041 #include "iochannel.hxx"
00042 
00043 using std::string;
00044 
00048 class SGSerial : public SGIOChannel {
00049 
00050     string device;
00051     string baud;
00052     SGSerialPort port;
00053 
00054     char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
00055     int save_len;
00056 
00057 public:
00058 
00071     SGSerial( const string& device_name, const string& baud_rate );
00072 
00074     ~SGSerial();
00075 
00076     
00077     bool open( const SGProtocolDir d );
00078 
00079     
00080     int read( char *buf, int length );
00081 
00082     
00083     int readline( char *buf, int length );
00084 
00085     
00086     int write( const char *buf, const int length );
00087 
00088     
00089     int writestring( const char *str );
00090 
00091     
00092     bool close();
00093 
00095     inline string get_device() const { return device; }
00096 
00098     inline string get_baud() const { return baud; }
00099 };
00100 
00101 
00102 #endif // _SG_SERIAL_HXX
00103 
00104