]> git.mxchange.org Git - simgear.git/blob - simgear/io/sg_serial.hxx
Remove warnings
[simgear.git] / simgear / io / sg_serial.hxx
1 /**
2  * \file sg_serial.hxx
3  * Serial I/O routines
4  */
5
6 // Written by Curtis Olson, started November 1999.
7 //
8 // Copyright (C) 1999  Curtis L. Olson - http://www.flightgear.org/~curt
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _SG_SERIAL_HXX
28 #define _SG_SERIAL_HXX
29
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35 #include <simgear/compiler.h>
36
37 #include <string>
38
39 // #ifdef SG_HAVE_STD_INCLUDES
40 // #  include <ctime>
41 // #else
42 // #  include <time.h>
43 // #endif
44
45 #include <simgear/serial/serial.hxx>
46
47 #include "iochannel.hxx"
48
49 SG_USING_STD(string);
50
51 /**
52  * A serial I/O class based on SGIOChannel.
53  */
54 class SGSerial : public SGIOChannel {
55
56     string device;
57     string baud;
58     SGSerialPort port;
59
60     char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
61     int save_len;
62
63 public:
64
65     /**
66      * Create an instance of SGSerial.
67      * This creates an instance of the SGSerial class. You need to
68      * provide the serial device name and desired baud rate.  For Unix
69      * style systems, device names will be similar to
70      * ``/dev/ttyS0''. For DOS style systems you may want to use
71      * something similar to ``COM1:''. As with the SGFile class,
72      * device is not opened immediately, but instead will be opened
73      * when the open() method is called.
74      * @param device_name name of serial device
75      * @param baud_rate speed of communication
76      */
77     SGSerial( const string& device_name, const string& baud_rate );
78
79     /** Destructor */
80     ~SGSerial();
81
82     // open the serial port based on specified direction
83     bool open( const SGProtocolDir d );
84
85     // read a block of data of specified size
86     int read( char *buf, int length );
87
88     // read a line of data, length is max size of input buffer
89     int readline( char *buf, int length );
90
91     // write data to port
92     int write( const char *buf, const int length );
93
94     // write null terminated string to port
95     int writestring( const char *str );
96
97     // close port
98     bool close();
99
100     /** @return the serial port device name */
101     inline string get_device() const { return device; }
102
103     /** @return the baud rate */
104     inline string get_baud() const { return baud; }
105 };
106
107
108 #endif // _SG_SERIAL_HXX
109
110