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

Last change on this file since 9517 was 8204, checked in by wiese, 7 years ago

CHANGE: #105 toAscii deprecated

File size: 4.5 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 *
13 * Changes:
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
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 if (_url.scheme().isEmpty()) {
73 _url.setScheme("http");
74 }
75 if (_url.path().isEmpty()) {
76 _url.setPath("/");
77 }
78
79 QString hlp;
80 QStringList hlpL;
[8204]81 hlp = _url.host().toLatin1().replace("-"," ");
[1752]82 hlpL = hlp.split(" ");
83
84 // Serial Port
85 // -----------
86 QString _portString;
87 if (hlpL.size() == 6) {
88 _portString = hlpL[hlpL.size()-6].replace("com","COM");
89 } else {
90 _portString = "/" + hlpL[hlpL.size()-7] + "/" + hlpL[hlpL.size()-6].replace("ttys","ttyS");
91 }
92 _serialPort = new QextSerialPort(_portString);
93
94 // Baud Rate
95 // ---------
96 hlp = hlpL[hlpL.size()-1];
97 if (hlp == "110") {
98 _serialPort->setBaudRate(BAUD110);
99 }
100 else if (hlp == "300") {
101 _serialPort->setBaudRate(BAUD300);
102 }
103 else if (hlp == "600") {
104 _serialPort->setBaudRate(BAUD600);
105 }
106 else if (hlp == "1200") {
107 _serialPort->setBaudRate(BAUD1200);
108 }
109 else if (hlp == "2400") {
110 _serialPort->setBaudRate(BAUD2400);
111 }
112 else if (hlp == "4800") {
113 _serialPort->setBaudRate(BAUD4800);
114 }
115 else if (hlp == "9600") {
116 _serialPort->setBaudRate(BAUD9600);
117 }
118 else if (hlp == "19200") {
119 _serialPort->setBaudRate(BAUD19200);
120 }
121 else if (hlp == "38400") {
122 _serialPort->setBaudRate(BAUD38400);
123 }
124 else if (hlp == "57600") {
125 _serialPort->setBaudRate(BAUD57600);
126 }
127 else if (hlp == "115200") {
128 _serialPort->setBaudRate(BAUD115200);
129 }
130
131 // Parity
132 // ------
133 hlp = hlpL[hlpL.size()-4].toUpper();
134 if (hlp == "NONE") {
135 _serialPort->setParity(PAR_NONE);
136 }
137 else if (hlp == "ODD") {
138 _serialPort->setParity(PAR_ODD);
139 }
140 else if (hlp == "EVEN") {
141 _serialPort->setParity(PAR_EVEN);
142 }
143 else if (hlp == "SPACE") {
144 _serialPort->setParity(PAR_SPACE);
145 }
146
147 // Data Bits
148 // ---------
149 hlp = hlpL[hlpL.size()-5];
150 if (hlp == "5") {
151 _serialPort->setDataBits(DATA_5);
152 }
153 else if (hlp == "6") {
154 _serialPort->setDataBits(DATA_6);
155 }
156 else if (hlp == "7") {
157 _serialPort->setDataBits(DATA_7);
158 }
159 else if (hlp == "8") {
160 _serialPort->setDataBits(DATA_8);
161 }
162
163 // Stop Bits
164 // ---------
165 hlp = hlpL[hlpL.size()-3];
166 if (hlp == "1") {
167 _serialPort->setStopBits(STOP_1);
168 }
169 else if (hlp == "2") {
170 _serialPort->setStopBits(STOP_2);
171 }
172
173 // Flow Control
174 // ------------
175 hlp = hlpL[hlpL.size()-2].toUpper();
176 if (hlp == "XONXOFF") {
177 _serialPort->setFlowControl(FLOW_XONXOFF);
178 }
179 else if (hlp == "HARDWARE") {
180 _serialPort->setFlowControl(FLOW_HARDWARE);
181 }
182 else {
183 _serialPort->setFlowControl(FLOW_OFF);
184 }
185
186 _status = running;
[1754]187
[1752]188 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
189 if (!_serialPort->isOpen()) {
190 delete _serialPort;
191 _serialPort = 0;
192 _status = error;
[8204]193 emit newMessage(_url.path().toLatin1().replace(0,1,"") + ": Cannot open serial port " + _portString.toLatin1(), true);
[1752]194 return;
195 }
196}
197
[6787]198void bncNetQueryS::keepAliveRequest(const QUrl& /* url */, const QByteArray& /* gga */) {
199}
Note: See TracBrowser for help on using the repository browser.