source: ntrip/trunk/BNC/src/bncnetquerys.cpp@ 10790

Last change on this file since 10790 was 10778, checked in by stuerze, 4 weeks ago

CHANGE: back to the class QextSerialPort because the QT5 internal class QSerialPort seems to have a bug

File size: 4.8 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncnetquerys
6 *
7 * Purpose: Serial Communication Requests, no NTRIP
8 *
9 * Author: G. Weber
10 *
11 * Created: 8-Mar-2009
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include "bncnetquerys.h"
18#include "bncversion.h"
19
20using namespace std;
21
22// Constructor
23////////////////////////////////////////////////////////////////////////////
24bncNetQueryS::bncNetQueryS() {
25
26 _serialPort = 0;
27
28}
29
30// Destructor
31////////////////////////////////////////////////////////////////////////////
32bncNetQueryS::~bncNetQueryS() {
33 delete _serialPort;
34}
35
36//
37////////////////////////////////////////////////////////////////////////////
38void bncNetQueryS::stop() {
39#ifndef sparc
40 if (_serialPort) {
41 }
42#endif
43 _status = finished;
44}
45
46//
47/////////////////////////////////////////////////////////////////////////////
48void bncNetQueryS::waitForRequestResult(const QUrl&, QByteArray&) {
49}
50
51//
52////////////////////////////////////////////////////////////////////////////
53void bncNetQueryS::waitForReadyRead(QByteArray& outData) {
54 if (_serialPort) {
55 while (true) {
56 int nb = _serialPort->bytesAvailable();
57 if (nb > 0) {
58 outData = _serialPort->read(nb);
59 return;
60 }
61 }
62 }
63}
64
65// Connect to Serial Port
66////////////////////////////////////////////////////////////////////////////
67void bncNetQueryS::startRequest(const QUrl& url, const QByteArray& gga) {
68
69 QByteArray dummy_gga = gga;
70
71 _url = url;
72
73 if (_url.scheme().isEmpty()) {
74 _url.setScheme("http");
75 }
76 if (_url.path().isEmpty()) {
77 _url.setPath("/");
78 }
79
80 QString hlp;
81 QStringList hlpL;
82
83 // Serial Port
84 // -----------
85 hlp = _url.userInfo().replace("-"," ");
86 hlpL = hlp.split(" ");
87 QString _portString;
88 if (hlpL.size() == 1) {
89 _portString = hlpL[hlpL.size()-1];
90 } else {
91 _portString = "/" + hlpL[hlpL.size()-2] + "/" + hlpL[hlpL.size()-1];
92 }
93
94 _serialPort = new QextSerialPort(_portString);
95
96 // Baud Rate
97 // ---------
98 hlp = _url.host().replace("-"," ");
99 hlpL = hlp.split(" ");
100 hlp = hlpL[hlpL.size()-1];
101 if (hlp == "110") {
102 _serialPort->setBaudRate(BAUD110);
103 }
104 else if (hlp == "300") {
105 _serialPort->setBaudRate(BAUD300);
106 }
107 else if (hlp == "600") {
108 _serialPort->setBaudRate(BAUD600);
109 }
110 else if (hlp == "1200") {
111 _serialPort->setBaudRate(BAUD1200);
112 }
113 else if (hlp == "2400") {
114 _serialPort->setBaudRate(BAUD2400);
115 }
116 else if (hlp == "4800") {
117 _serialPort->setBaudRate(BAUD4800);
118 }
119 else if (hlp == "9600") {
120 _serialPort->setBaudRate(BAUD9600);
121 }
122 else if (hlp == "19200") {
123 _serialPort->setBaudRate(BAUD19200);
124 }
125 else if (hlp == "38400") {
126 _serialPort->setBaudRate(BAUD38400);
127 }
128 else if (hlp == "57600") {
129 _serialPort->setBaudRate(BAUD57600);
130 }
131 else if (hlp == "115200") {
132 _serialPort->setBaudRate(BAUD115200);
133 }
134
135 // Parity
136 // ------
137 hlp = hlpL[hlpL.size()-4].toUpper();
138 if (hlp == "NONE") {
139 _serialPort->setParity(PAR_NONE);
140 }
141 else if (hlp == "ODD") {
142 _serialPort->setParity(PAR_ODD);
143 }
144 else if (hlp == "EVEN") {
145 _serialPort->setParity(PAR_EVEN);
146 }
147 else if (hlp == "SPACE") {
148 _serialPort->setParity(PAR_SPACE);
149 }
150
151 // Data Bits
152 // ---------
153 hlp = hlpL[hlpL.size()-5];
154 if (hlp == "5") {
155 _serialPort->setDataBits(DATA_5);
156 }
157 else if (hlp == "6") {
158 _serialPort->setDataBits(DATA_6);
159 }
160 else if (hlp == "7") {
161 _serialPort->setDataBits(DATA_7);
162 }
163 else if (hlp == "8") {
164 _serialPort->setDataBits(DATA_8);
165 }
166
167 // Stop Bits
168 // ---------
169 hlp = hlpL[hlpL.size()-3];
170 if (hlp == "1") {
171 _serialPort->setStopBits(STOP_1);
172 }
173 else if (hlp == "2") {
174 _serialPort->setStopBits(STOP_2);
175 }
176
177 // Flow Control
178 // ------------
179 hlp = hlpL[hlpL.size()-2].toUpper();
180 if (hlp == "XONXOFF") {
181 _serialPort->setFlowControl(FLOW_XONXOFF);
182 }
183 else if (hlp == "HARDWARE") {
184 _serialPort->setFlowControl(FLOW_HARDWARE);
185 }
186 else {
187 _serialPort->setFlowControl(FLOW_OFF);
188 }
189
190 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
191
192 if (!_serialPort->isOpen()) {
193 emit newMessage(_url.path().toLatin1().replace(0,1,"") + ": Cannot open serial port " + _portString.toLatin1()
194 + ": " + _serialPort->errorString().toLatin1(), true);
195 delete _serialPort;
196 _serialPort = 0;
197 _status = error;
198 return;
199 }
200 else {
201 emit(newMessage(_url.path().toLatin1().replace(0,1,"") + ": Serial port " + _portString.toLatin1()
202 + " is connected: " , true));
203 _status = running;
204 }
205}
206
207void bncNetQueryS::keepAliveRequest(const QUrl& /* url */, const QByteArray& /* gga */) {
208}
Note: See TracBrowser for help on using the repository browser.