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

Last change on this file since 10793 was 10778, checked in by stuerze, 6 weeks ago

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

File size: 4.8 KB
RevLine 
[1752]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 *
[10766]13 * Changes:
[1752]14 *
15 * -----------------------------------------------------------------------*/
16
17#include "bncnetquerys.h"
[2011]18#include "bncversion.h"
[1752]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
[10766]36//
[1752]37////////////////////////////////////////////////////////////////////////////
38void bncNetQueryS::stop() {
39#ifndef sparc
40 if (_serialPort) {
41 }
42#endif
43 _status = finished;
[10766]44}
[1752]45
[10766]46//
[1752]47/////////////////////////////////////////////////////////////////////////////
48void bncNetQueryS::waitForRequestResult(const QUrl&, QByteArray&) {
49}
50
[10766]51//
[1752]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;
[10766]72
[1752]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 // -----------
[10766]85 hlp = _url.userInfo().replace("-"," ");
86 hlpL = hlp.split(" ");
[1752]87 QString _portString;
[10766]88 if (hlpL.size() == 1) {
89 _portString = hlpL[hlpL.size()-1];
[1752]90 } else {
[10766]91 _portString = "/" + hlpL[hlpL.size()-2] + "/" + hlpL[hlpL.size()-1];
[1752]92 }
93
[10778]94 _serialPort = new QextSerialPort(_portString);
[10766]95
[1752]96 // Baud Rate
97 // ---------
[10766]98 hlp = _url.host().replace("-"," ");
99 hlpL = hlp.split(" ");
[1752]100 hlp = hlpL[hlpL.size()-1];
[10776]101 if (hlp == "110") {
102 _serialPort->setBaudRate(BAUD110);
[1752]103 }
[10776]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 }
[1752]113 else if (hlp == "2400") {
[10776]114 _serialPort->setBaudRate(BAUD2400);
[1752]115 }
116 else if (hlp == "4800") {
[10776]117 _serialPort->setBaudRate(BAUD4800);
[1752]118 }
119 else if (hlp == "9600") {
[10776]120 _serialPort->setBaudRate(BAUD9600);
[1752]121 }
122 else if (hlp == "19200") {
[10776]123 _serialPort->setBaudRate(BAUD19200);
[1752]124 }
125 else if (hlp == "38400") {
[10776]126 _serialPort->setBaudRate(BAUD38400);
[1752]127 }
128 else if (hlp == "57600") {
[10776]129 _serialPort->setBaudRate(BAUD57600);
[1752]130 }
131 else if (hlp == "115200") {
[10776]132 _serialPort->setBaudRate(BAUD115200);
[1752]133 }
134
135 // Parity
136 // ------
137 hlp = hlpL[hlpL.size()-4].toUpper();
138 if (hlp == "NONE") {
[10776]139 _serialPort->setParity(PAR_NONE);
[1752]140 }
141 else if (hlp == "ODD") {
[10776]142 _serialPort->setParity(PAR_ODD);
[1752]143 }
144 else if (hlp == "EVEN") {
[10776]145 _serialPort->setParity(PAR_EVEN);
[1752]146 }
147 else if (hlp == "SPACE") {
[10776]148 _serialPort->setParity(PAR_SPACE);
[1752]149 }
150
151 // Data Bits
152 // ---------
153 hlp = hlpL[hlpL.size()-5];
154 if (hlp == "5") {
[10776]155 _serialPort->setDataBits(DATA_5);
[1752]156 }
157 else if (hlp == "6") {
[10776]158 _serialPort->setDataBits(DATA_6);
[1752]159 }
160 else if (hlp == "7") {
[10776]161 _serialPort->setDataBits(DATA_7);
[1752]162 }
163 else if (hlp == "8") {
[10776]164 _serialPort->setDataBits(DATA_8);
[1752]165 }
166
167 // Stop Bits
168 // ---------
169 hlp = hlpL[hlpL.size()-3];
170 if (hlp == "1") {
[10776]171 _serialPort->setStopBits(STOP_1);
[1752]172 }
173 else if (hlp == "2") {
[10776]174 _serialPort->setStopBits(STOP_2);
[1752]175 }
176
177 // Flow Control
178 // ------------
179 hlp = hlpL[hlpL.size()-2].toUpper();
180 if (hlp == "XONXOFF") {
[10776]181 _serialPort->setFlowControl(FLOW_XONXOFF);
[1752]182 }
183 else if (hlp == "HARDWARE") {
[10776]184 _serialPort->setFlowControl(FLOW_HARDWARE);
[1752]185 }
186 else {
[10776]187 _serialPort->setFlowControl(FLOW_OFF);
[1752]188 }
189
[10776]190 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
[1754]191
[1752]192 if (!_serialPort->isOpen()) {
[10766]193 emit newMessage(_url.path().toLatin1().replace(0,1,"") + ": Cannot open serial port " + _portString.toLatin1()
[10776]194 + ": " + _serialPort->errorString().toLatin1(), true);
[1752]195 delete _serialPort;
196 _serialPort = 0;
197 _status = error;
198 return;
199 }
[10776]200 else {
201 emit(newMessage(_url.path().toLatin1().replace(0,1,"") + ": Serial port " + _portString.toLatin1()
202 + " is connected: " , true));
203 _status = running;
204 }
[1752]205}
206
[6787]207void bncNetQueryS::keepAliveRequest(const QUrl& /* url */, const QByteArray& /* gga */) {
208}
Note: See TracBrowser for help on using the repository browser.