source: ntrip/trunk/BNC/src/serial/qextserialbase.h@ 10525

Last change on this file since 10525 was 10525, checked in by stuerze, 3 months ago

replacement of obsolete qt-class members

File size: 4.4 KB
Line 
1
2#ifndef _QEXTSERIALBASE_H_
3#define _QEXTSERIALBASE_H_
4
5#include <QIODevice>
6#include <QFile>
7
8#ifdef QT_THREAD_SUPPORT
9#include <QThread>
10#include <QMutex>
11#endif
12
13/*if all warning messages are turned off, flag portability warnings to be turned off as well*/
14#ifdef _TTY_NOWARN_
15#define _TTY_NOWARN_PORT_
16#endif
17
18/*macros for thread support*/
19#ifdef QT_THREAD_SUPPORT
20#define LOCK_MUTEX() mutex->lock()
21#define UNLOCK_MUTEX() mutex->unlock()
22#else
23#define LOCK_MUTEX()
24#define UNLOCK_MUTEX()
25#endif
26
27/*macros for warning messages*/
28#ifdef _TTY_NOWARN_PORT_
29#define TTY_PORTABILITY_WARNING(s)
30#else
31#define TTY_PORTABILITY_WARNING(s) qWarning(s)
32#endif
33#ifdef _TTY_NOWARN_
34#define TTY_WARNING(s)
35#else
36#define TTY_WARNING(s) qWarning(s)
37#endif
38
39
40/*line status constants*/
41#define LS_CTS 0x01
42#define LS_DSR 0x02
43#define LS_DCD 0x04
44#define LS_RI 0x08
45#define LS_RTS 0x10
46#define LS_DTR 0x20
47#define LS_ST 0x40
48#define LS_SR 0x80
49
50/*error constants*/
51#define E_NO_ERROR 0
52#define E_INVALID_FD 1
53#define E_NO_MEMORY 2
54#define E_CAUGHT_NON_BLOCKED_SIGNAL 3
55#define E_PORT_TIMEOUT 4
56#define E_INVALID_DEVICE 5
57#define E_BREAK_CONDITION 6
58#define E_FRAMING_ERROR 7
59#define E_IO_ERROR 8
60#define E_BUFFER_OVERRUN 9
61#define E_RECEIVE_OVERFLOW 10
62#define E_RECEIVE_PARITY_ERROR 11
63#define E_TRANSMIT_OVERFLOW 12
64#define E_READ_FAILED 13
65#define E_WRITE_FAILED 14
66
67/*enums for port settings*/
68enum NamingConvention {
69 WIN_NAMES,
70 IRIX_NAMES,
71 HPUX_NAMES,
72 SUN_NAMES,
73 DIGITAL_NAMES,
74 FREEBSD_NAMES,
75 LINUX_NAMES
76};
77
78enum BaudRateType {
79 BAUD50, //POSIX ONLY
80 BAUD75, //POSIX ONLY
81 BAUD110,
82 BAUD134, //POSIX ONLY
83 BAUD150, //POSIX ONLY
84 BAUD200, //POSIX ONLY
85 BAUD300,
86 BAUD600,
87 BAUD1200,
88 BAUD1800, //POSIX ONLY
89 BAUD2400,
90 BAUD4800,
91 BAUD9600,
92 BAUD14400, //WINDOWS ONLY
93 BAUD19200,
94 BAUD38400,
95 BAUD56000, //WINDOWS ONLY
96 BAUD57600,
97 BAUD76800, //POSIX ONLY
98 BAUD115200,
99 BAUD128000, //WINDOWS ONLY
100 BAUD256000 //WINDOWS ONLY
101};
102
103enum DataBitsType {
104 DATA_5,
105 DATA_6,
106 DATA_7,
107 DATA_8
108};
109
110enum ParityType {
111 PAR_NONE,
112 PAR_ODD,
113 PAR_EVEN,
114 PAR_MARK, //WINDOWS ONLY
115 PAR_SPACE
116};
117
118enum StopBitsType {
119 STOP_1,
120 STOP_1_5, //WINDOWS ONLY
121 STOP_2
122};
123
124enum FlowType {
125 FLOW_OFF,
126 FLOW_HARDWARE,
127 FLOW_XONXOFF
128};
129
130/*structure to contain port settings*/
131struct PortSettings {
132 BaudRateType BaudRate;
133 DataBitsType DataBits;
134 ParityType Parity;
135 StopBitsType StopBits;
136 FlowType FlowControl;
137 ulong Timeout_Sec;
138 ulong Timeout_Millisec;
139};
140
141class QextSerialBase : public QIODevice {
142public:
143 QextSerialBase();
144 QextSerialBase(const QString & name);
145 virtual ~QextSerialBase();
146 virtual void construct();
147 virtual void setPortName(const QString & name);
148 virtual QString portName() const;
149
150 virtual void setBaudRate(BaudRateType)=0;
151 virtual BaudRateType baudRate() const;
152 virtual void setDataBits(DataBitsType)=0;
153 virtual DataBitsType dataBits() const;
154 virtual void setParity(ParityType)=0;
155 virtual ParityType parity() const;
156 virtual void setStopBits(StopBitsType)=0;
157 virtual StopBitsType stopBits() const;
158 virtual void setFlowControl(FlowType)=0;
159 virtual FlowType flowControl() const;
160 virtual void setTimeout(ulong, ulong)=0;
161
162 virtual bool open(OpenMode mode=QIODevice::NotOpen)=0;
163 virtual bool isSequential() const;
164 virtual void close()=0;
165 virtual void flush()=0;
166
167 virtual qint64 size() const=0;
168 virtual qint64 bytesAvailable()=0;
169 virtual bool atEnd() const;
170
171 virtual void ungetChar(char c)=0;
172 virtual qint64 readLine(char * data, qint64 maxSize);
173
174 virtual ulong lastError() const;
175 virtual void translateError(ulong error)=0;
176
177 virtual void setDtr(bool set=true)=0;
178 virtual void setRts(bool set=true)=0;
179 virtual ulong lineStatus()=0;
180
181protected:
182 QString port;
183 PortSettings Settings;
184 ulong lastErr;
185
186#ifdef QT_THREAD_SUPPORT
187 static QMutex* mutex;
188 static ulong refCount;
189#endif
190
191 virtual qint64 readData(char * data, qint64 maxSize)=0;
192 virtual qint64 writeData(const char * data, qint64 maxSize)=0;
193
194};
195
196#endif
Note: See TracBrowser for help on using the repository browser.