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