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

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

external class QextSerialPort was replaced by Qt5 internal class QSerialPort, serial port is now introduced as case sensitive

File size: 4.9 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 QSerialPort(_portString);
95
96
97 // Baud Rate
98 // ---------
99 hlp = _url.host().replace("-"," ");
100 hlpL = hlp.split(" ");
101 hlp = hlpL[hlpL.size()-1];
102 if (hlp == "1200") {
103 _serialPort->setBaudRate(QSerialPort::Baud1200);
104 }
105 else if (hlp == "2400") {
106 _serialPort->setBaudRate(QSerialPort::Baud2400);
107 }
108 else if (hlp == "4800") {
109 _serialPort->setBaudRate(QSerialPort::Baud4800);
110 }
111 else if (hlp == "9600") {
112 _serialPort->setBaudRate(QSerialPort::Baud9600);
113 }
114 else if (hlp == "19200") {
115 _serialPort->setBaudRate(QSerialPort::Baud19200);
116 }
117 else if (hlp == "38400") {
118 _serialPort->setBaudRate(QSerialPort::Baud38400);
119 }
120 else if (hlp == "57600") {
121 _serialPort->setBaudRate(QSerialPort::Baud57600);
122 }
123 else if (hlp == "115200") {
124 _serialPort->setBaudRate(QSerialPort::Baud115200);
125 }
126
127 // Parity
128 // ------
129 hlp = hlpL[hlpL.size()-4].toUpper();
130 if (hlp == "NONE") {
131 _serialPort->setParity(QSerialPort::NoParity);
132 }
133 else if (hlp == "ODD") {
134 _serialPort->setParity(QSerialPort::OddParity);
135 }
136 else if (hlp == "EVEN") {
137 _serialPort->setParity(QSerialPort::EvenParity);
138 }
139 else if (hlp == "SPACE") {
140 _serialPort->setParity(QSerialPort::SpaceParity);
141 }
142 else if (hlp == "MARK") {
143 _serialPort->setParity(QSerialPort::MarkParity);
144 }
145
146
147 // Data Bits
148 // ---------
149 hlp = hlpL[hlpL.size()-5];
150 if (hlp == "5") {
151 _serialPort->setDataBits(QSerialPort::Data5);
152 }
153 else if (hlp == "6") {
154 _serialPort->setDataBits(QSerialPort::Data6);
155 }
156 else if (hlp == "7") {
157 _serialPort->setDataBits(QSerialPort::Data6);
158 }
159 else if (hlp == "8") {
160 _serialPort->setDataBits(QSerialPort::Data7);
161 }
162
163 // Stop Bits
164 // ---------
165 hlp = hlpL[hlpL.size()-3];
166 if (hlp == "1") {
167 _serialPort->setStopBits(QSerialPort::OneStop);
168 }
169 else if (hlp == "1.5") {
170 _serialPort->setStopBits(QSerialPort::OneAndHalfStop);
171 }
172 else if (hlp == "2") {
173 _serialPort->setStopBits(QSerialPort::TwoStop);
174 }
175
176 // Flow Control
177 // ------------
178 hlp = hlpL[hlpL.size()-2].toUpper();
179 if (hlp == "XONXOFF") {
180 _serialPort->setFlowControl(QSerialPort::SoftwareControl);
181 }
182 else if (hlp == "HARDWARE") {
183 _serialPort->setFlowControl(QSerialPort::HardwareControl);
184 }
185 else {
186 _serialPort->setFlowControl(QSerialPort::NoFlowControl);
187 }
188
189 _status = running;
190
191 //_serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
192 _serialPort->open(QIODevice::ReadWrite);
193
194 if (!_serialPort->isOpen()) {
195 emit newMessage(_url.path().toLatin1().replace(0,1,"") + ": Cannot open serial port " + _portString.toLatin1()
196 + ": " +_serialPort->errorString().toLatin1(), true);
197 delete _serialPort;
198 _serialPort = 0;
199 _status = error;
200 return;
201 }
202}
203
204void bncNetQueryS::keepAliveRequest(const QUrl& /* url */, const QByteArray& /* gga */) {
205}
Note: See TracBrowser for help on using the repository browser.