nidas v1.2.3
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
43namespace nidas { namespace util {
44
48class Termios {
49
50public:
51
55 Termios();
56
60 Termios(const struct termios*);
61
67 Termios(int fd, const std::string& devname);
68
69 virtual ~Termios() {}
70
76 void apply(int fd, const std::string& devname);
77
81 void set(const struct termios*);
82
86 const struct termios* get();
87
88 bool setBaudRate(int val);
89 int getBaudRate() const;
90
91 enum parity { NONE, ODD, EVEN};
92
93 void setParity(enum parity val);
94 parity getParity() const;
95 std::string getParityString() const;
96
100 void setDataBits(int val);
101 int getDataBits() const;
102
106 void setStopBits(int val);
107 int getStopBits() const;
108
112 void setLocal(bool val);
113 bool getLocal() const;
114
120
124 void setFlowControl(flowcontrol val);
126 std::string getFlowControlString() const;
127
142 void setRaw(bool val);
143 bool getRaw() const;
144
145 void setRawLength(unsigned char val);
146 unsigned char getRawLength() const;
147
148 void setRawTimeout(unsigned char val);
149 unsigned char getRawTimeout() const;
150
151 tcflag_t &iflag() { return _tio.c_iflag; }
152 tcflag_t &oflag() { return _tio.c_oflag; }
153 tcflag_t &cflag() { return _tio.c_cflag; }
154 tcflag_t &lflag() { return _tio.c_lflag; }
155 cc_t *cc() { return _tio.c_cc; }
156
157 tcflag_t getIflag() const { return _tio.c_iflag; }
158 tcflag_t getOflag() const { return _tio.c_oflag; }
159
160 static struct baudtable {
161 unsigned int cbaud;
162 int rate;
163 } bauds[];
164
165 void setDefaultTermios();
166
167private:
168
169 struct termios _tio;
170
171 unsigned char _rawlen;
172
173 unsigned char _rawtimeout;
174};
175
176}} // namespace nidas namespace util
177
178#endif
A class providing get/set methods into a termios structure.
Definition Termios.h:48
bool getRaw() const
Definition Termios.cc:335
void apply(int fd, const std::string &devname)
Set the termios options on a serial port.
Definition Termios.cc:104
void set(const struct termios *)
Set all Termios parameters from the contents of struct termios.
Definition Termios.cc:115
tcflag_t & iflag()
Definition Termios.h:151
Termios()
Default constructor: 9600 n81, no flow control, canonical input, output.
Definition Termios.cc:78
void setDataBits(int val)
Set number of data bits to 5,6,7 or 8.
Definition Termios.cc:209
const struct termios * get()
Get a const pointer to the internal struct termios.
Definition Termios.cc:110
void setRawTimeout(unsigned char val)
Definition Termios.cc:349
void setRaw(bool val)
Sets termios options for raw or non-raw(cooked) mode.
Definition Termios.cc:307
int getDataBits() const
Definition Termios.cc:227
unsigned char _rawlen
Definition Termios.h:171
unsigned char getRawLength() const
Definition Termios.cc:356
int getBaudRate() const
Definition Termios.cc:166
parity
Definition Termios.h:91
@ ODD
Definition Termios.h:91
@ EVEN
Definition Termios.h:91
@ NONE
Definition Termios.h:91
parity getParity() const
Definition Termios.cc:201
tcflag_t getIflag() const
Definition Termios.h:157
cc_t * cc()
Definition Termios.h:155
tcflag_t & cflag()
Definition Termios.h:153
std::string getParityString() const
Definition Termios.cc:367
unsigned char _rawtimeout
Definition Termios.h:173
struct termios _tio
Definition Termios.h:169
bool setBaudRate(int val)
Definition Termios.cc:145
void setFlowControl(flowcontrol val)
Set flow control to NOFLOWCONTROL, HARDWARE or SOFTWARE.
Definition Termios.cc:273
enum flowcontrol flowcontrol
Definition Termios.h:119
tcflag_t & oflag()
Definition Termios.h:152
int getStopBits() const
Definition Termios.cc:248
unsigned char getRawTimeout() const
Definition Termios.cc:362
static struct nidas::util::Termios::baudtable bauds[]
Definition Termios.cc:42
void setStopBits(int val)
Set number of stop bits, to 1 or 2.
Definition Termios.cc:239
bool getLocal() const
Definition Termios.cc:267
flowcontrol getFlowControl() const
Definition Termios.cc:298
flowcontrol
HARDWARE flow control is CTSRTS.
Definition Termios.h:118
@ SOFTWARE
Definition Termios.h:118
@ NOFLOWCONTROL
Definition Termios.h:118
@ HARDWARE
Definition Termios.h:118
std::string getFlowControlString() const
Definition Termios.cc:376
virtual ~Termios()
Definition Termios.h:69
void setParity(enum parity val)
Definition Termios.cc:176
void setDefaultTermios()
Definition Termios.cc:124
void setLocal(bool val)
If local, then ignore carrier detect modem control line.
Definition Termios.cc:255
void setRawLength(unsigned char val)
Definition Termios.cc:342
tcflag_t getOflag() const
Definition Termios.h:158
tcflag_t & lflag()
Definition Termios.h:154
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
Definition Termios.h:160
int rate
Definition Termios.h:162
unsigned int cbaud
Definition Termios.h:161
int fd
Definition twod.c:56