nidas  v1.2-1520
Termios.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2006, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_UTIL_TERMIOS_H
28 #define NIDAS_UTIL_TERMIOS_H
29 
30 /*
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 */
36 #include <termios.h>
37 #include <sys/ioctl.h>
38 
39 #include "IOException.h"
40 
41 #include <string>
42 
43 namespace nidas { namespace util {
44 
48 class Termios {
49 
50 public:
51 
55  Termios();
56 
60  Termios(const struct termios*);
61 
65  Termios(int fd,const std::string& devname)
66  throw(IOException);
67 
68  virtual ~Termios() {}
69 
73  void apply(int fd,const std::string& devname)
74  throw(IOException);
75 
79  void set(const struct termios*);
80 
84  const struct termios* get();
85 
86  bool setBaudRate(int val);
87  int getBaudRate() const;
88 
89  enum parity { NONE, ODD, EVEN};
90 
91  void setParity(enum parity val);
92  parity getParity() const;
93  std::string getParityString() const;
94 
98  void setDataBits(int val);
99  int getDataBits() const;
100 
104  void setStopBits(int val);
105  int getStopBits() const;
106 
110  void setLocal(bool val);
111  bool getLocal() const;
112 
117  typedef enum flowcontrol flowcontrol;
118 
122  void setFlowControl(flowcontrol val);
123  flowcontrol getFlowControl() const;
124  std::string getFlowControlString() const;
125 
140  void setRaw(bool val);
141  bool getRaw() const;
142 
143  void setRawLength(unsigned char val);
144  unsigned char getRawLength() const;
145 
146  void setRawTimeout(unsigned char val);
147  unsigned char getRawTimeout() const;
148 
149  tcflag_t &iflag() { return _tio.c_iflag; }
150  tcflag_t &oflag() { return _tio.c_oflag; }
151  tcflag_t &cflag() { return _tio.c_cflag; }
152  tcflag_t &lflag() { return _tio.c_lflag; }
153  cc_t *cc() { return _tio.c_cc; }
154 
155  tcflag_t getIflag() const { return _tio.c_iflag; }
156  tcflag_t getOflag() const { return _tio.c_oflag; }
157 
158  static struct baudtable {
159  unsigned int cbaud;
160  int rate;
161  } bauds[];
162 
163  void setDefaultTermios();
164 
165 private:
166 
167  struct termios _tio;
168 
169  unsigned char _rawlen;
170 
171  unsigned char _rawtimeout;
172 };
173 
174 }} // namespace nidas namespace util
175 
176 #endif
Definition: Termios.h:89
Definition: Termios.h:89
int getStopBits() const
Definition: Termios.cc:248
unsigned char getRawTimeout() const
Definition: Termios.cc:362
Termios()
Default constructor: 9600 n81, no flow control, canonical input, output.
Definition: Termios.cc:78
tcflag_t getIflag() const
Definition: Termios.h:155
unsigned char getRawLength() const
Definition: Termios.cc:356
Definition: Termios.h:158
parity
Definition: Termios.h:89
tcflag_t & lflag()
Definition: Termios.h:152
std::string getFlowControlString() const
Definition: Termios.cc:376
void set(const struct termios *)
Set all Termios parameters from the contents of struct termios.
Definition: Termios.cc:115
void setDataBits(int val)
Set number of data bits to 5,6,7 or 8.
Definition: Termios.cc:209
bool getLocal() const
Definition: Termios.cc:267
unsigned char _rawtimeout
Definition: Termios.h:171
tcflag_t & oflag()
Definition: Termios.h:150
static struct nidas::util::Termios::baudtable bauds[]
Definition: Termios.cc:42
tcflag_t getOflag() const
Definition: Termios.h:156
void setParity(enum parity val)
Definition: Termios.cc:176
void setRawTimeout(unsigned char val)
Definition: Termios.cc:349
struct termios _tio
Definition: Termios.h:167
flowcontrol getFlowControl() const
Definition: Termios.cc:298
void apply(int fd, const std::string &devname)
Set the termios options on a serial port.
Definition: Termios.cc:104
Definition: Termios.h:116
Definition: Termios.h:116
flowcontrol
HARDWARE flow control is CTSRTS.
Definition: Termios.h:116
void setFlowControl(flowcontrol val)
Set flow control to NOFLOWCONTROL, HARDWARE or SOFTWARE.
Definition: Termios.cc:273
cc_t * cc()
Definition: Termios.h:153
virtual ~Termios()
Definition: Termios.h:68
int fd
Definition: twod.c:56
tcflag_t & iflag()
Definition: Termios.h:149
bool setBaudRate(int val)
Definition: Termios.cc:145
Definition: IOException.h:37
int rate
Definition: Termios.h:160
std::string getParityString() const
Definition: Termios.cc:367
unsigned char _rawlen
Definition: Termios.h:169
void setDefaultTermios()
Definition: Termios.cc:124
void setLocal(bool val)
If local, then ignore carrier detect modem control line.
Definition: Termios.cc:255
unsigned int cbaud
Definition: Termios.h:159
Definition: Termios.h:116
bool getRaw() const
Definition: Termios.cc:335
void setRaw(bool val)
Sets termios options for raw or non-raw(cooked) mode.
Definition: Termios.cc:307
void setStopBits(int val)
Set number of stop bits, to 1 or 2.
Definition: Termios.cc:239
int getDataBits() const
Definition: Termios.cc:227
void setRawLength(unsigned char val)
Definition: Termios.cc:342
Definition: Termios.h:89
A class providing get/set methods into a termios structure.
Definition: Termios.h:48
int getBaudRate() const
Definition: Termios.cc:166
parity getParity() const
Definition: Termios.cc:201
tcflag_t & cflag()
Definition: Termios.h:151