1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: bncGetThread
|
---|
30 | *
|
---|
31 | * Purpose: Thread that retrieves data from NTRIP caster
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 24-Dec-2005
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <iomanip>
|
---|
43 | #include <sstream>
|
---|
44 |
|
---|
45 | #include <QFile>
|
---|
46 | #include <QTextStream>
|
---|
47 | #include <QtNetwork>
|
---|
48 | #include <QTime>
|
---|
49 |
|
---|
50 | #include "bncgetthread.h"
|
---|
51 | #include "bnctabledlg.h"
|
---|
52 | #include "bncapp.h"
|
---|
53 | #include "bncutils.h"
|
---|
54 | #include "bncrinex.h"
|
---|
55 | #include "bnczerodecoder.h"
|
---|
56 | #include "bncnetqueryv0.h"
|
---|
57 | #include "bncnetqueryv1.h"
|
---|
58 | #include "bncnetqueryv2.h"
|
---|
59 | #include "bncnetqueryrtp.h"
|
---|
60 | #include "bncnetqueryudp.h"
|
---|
61 | #include "bncnetqueryudp0.h"
|
---|
62 | #include "bncnetquerys.h"
|
---|
63 | #include "bncsettings.h"
|
---|
64 | #include "latencychecker.h"
|
---|
65 | #include "bncpppclient.h"
|
---|
66 | #include "upload/bncrtnetdecoder.h"
|
---|
67 | #include "RTCM/RTCM2Decoder.h"
|
---|
68 | #include "RTCM3/RTCM3Decoder.h"
|
---|
69 | #include "GPSS/gpssDecoder.h"
|
---|
70 | #include "GPSS/hassDecoder.h"
|
---|
71 | #include "serial/qextserialport.h"
|
---|
72 |
|
---|
73 | using namespace std;
|
---|
74 |
|
---|
75 | // Constructor 1
|
---|
76 | ////////////////////////////////////////////////////////////////////////////
|
---|
77 | bncGetThread::bncGetThread(bncRawFile* rawFile) {
|
---|
78 |
|
---|
79 | _rawFile = rawFile;
|
---|
80 | _format = rawFile->format();
|
---|
81 | _staID = rawFile->staID();
|
---|
82 | _rawOutput = false;
|
---|
83 | _ntripVersion = "N";
|
---|
84 |
|
---|
85 | initialize();
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Constructor 2
|
---|
89 | ////////////////////////////////////////////////////////////////////////////
|
---|
90 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
---|
91 | const QByteArray& format,
|
---|
92 | const QByteArray& latitude,
|
---|
93 | const QByteArray& longitude,
|
---|
94 | const QByteArray& nmea,
|
---|
95 | const QByteArray& ntripVersion,
|
---|
96 | const QByteArray& staIDextra) {
|
---|
97 | _rawFile = 0;
|
---|
98 | _mountPoint = mountPoint;
|
---|
99 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
100 | _staID_extra = staIDextra;
|
---|
101 | _format = format;
|
---|
102 | _latitude = latitude;
|
---|
103 | _longitude = longitude;
|
---|
104 | _nmea = nmea;
|
---|
105 | _ntripVersion = ntripVersion;
|
---|
106 |
|
---|
107 | bncSettings settings;
|
---|
108 | if (!settings.value("rawOutFile").toString().isEmpty()) {
|
---|
109 | _rawOutput = true;
|
---|
110 | }
|
---|
111 |
|
---|
112 | initialize();
|
---|
113 | }
|
---|
114 |
|
---|
115 | // Initialization (common part of the constructor)
|
---|
116 | ////////////////////////////////////////////////////////////////////////////
|
---|
117 | void bncGetThread::initialize() {
|
---|
118 |
|
---|
119 | setTerminationEnabled(true);
|
---|
120 |
|
---|
121 | bncApp* app = (bncApp*) qApp;
|
---|
122 |
|
---|
123 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
124 | app, SLOT(slotMessage(const QByteArray,bool)));
|
---|
125 |
|
---|
126 | _isToBeDeleted = false;
|
---|
127 | _decoder = 0;
|
---|
128 | _decoderAux = 0;
|
---|
129 | _query = 0;
|
---|
130 | _nextSleep = 0;
|
---|
131 | _PPPclient = 0;
|
---|
132 |
|
---|
133 | bncSettings settings;
|
---|
134 |
|
---|
135 | _miscMount = settings.value("miscMount").toString();
|
---|
136 |
|
---|
137 | // RINEX writer
|
---|
138 | // ------------
|
---|
139 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
140 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
141 | _rnx = 0;
|
---|
142 | }
|
---|
143 | else {
|
---|
144 | _rnx = new bncRinex(_staID, _mountPoint, _format, _latitude,
|
---|
145 | _longitude, _nmea, _ntripVersion);
|
---|
146 | }
|
---|
147 |
|
---|
148 | // Serial Port
|
---|
149 | // -----------
|
---|
150 | _serialNMEA = NO_NMEA;
|
---|
151 | _serialOutFile = 0;
|
---|
152 | _serialPort = 0;
|
---|
153 |
|
---|
154 | if (settings.value("serialMountPoint").toString() == _staID) {
|
---|
155 | _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
|
---|
156 | _serialPort->setTimeout(0,100);
|
---|
157 |
|
---|
158 | // Baud Rate
|
---|
159 | // ---------
|
---|
160 | QString hlp = settings.value("serialBaudRate").toString();
|
---|
161 | if (hlp == "110") {
|
---|
162 | _serialPort->setBaudRate(BAUD110);
|
---|
163 | }
|
---|
164 | else if (hlp == "300") {
|
---|
165 | _serialPort->setBaudRate(BAUD300);
|
---|
166 | }
|
---|
167 | else if (hlp == "600") {
|
---|
168 | _serialPort->setBaudRate(BAUD600);
|
---|
169 | }
|
---|
170 | else if (hlp == "1200") {
|
---|
171 | _serialPort->setBaudRate(BAUD1200);
|
---|
172 | }
|
---|
173 | else if (hlp == "2400") {
|
---|
174 | _serialPort->setBaudRate(BAUD2400);
|
---|
175 | }
|
---|
176 | else if (hlp == "4800") {
|
---|
177 | _serialPort->setBaudRate(BAUD4800);
|
---|
178 | }
|
---|
179 | else if (hlp == "9600") {
|
---|
180 | _serialPort->setBaudRate(BAUD9600);
|
---|
181 | }
|
---|
182 | else if (hlp == "19200") {
|
---|
183 | _serialPort->setBaudRate(BAUD19200);
|
---|
184 | }
|
---|
185 | else if (hlp == "38400") {
|
---|
186 | _serialPort->setBaudRate(BAUD38400);
|
---|
187 | }
|
---|
188 | else if (hlp == "57600") {
|
---|
189 | _serialPort->setBaudRate(BAUD57600);
|
---|
190 | }
|
---|
191 | else if (hlp == "115200") {
|
---|
192 | _serialPort->setBaudRate(BAUD115200);
|
---|
193 | }
|
---|
194 |
|
---|
195 | // Parity
|
---|
196 | // ------
|
---|
197 | hlp = settings.value("serialParity").toString();
|
---|
198 | if (hlp == "NONE") {
|
---|
199 | _serialPort->setParity(PAR_NONE);
|
---|
200 | }
|
---|
201 | else if (hlp == "ODD") {
|
---|
202 | _serialPort->setParity(PAR_ODD);
|
---|
203 | }
|
---|
204 | else if (hlp == "EVEN") {
|
---|
205 | _serialPort->setParity(PAR_EVEN);
|
---|
206 | }
|
---|
207 | else if (hlp == "SPACE") {
|
---|
208 | _serialPort->setParity(PAR_SPACE);
|
---|
209 | }
|
---|
210 |
|
---|
211 | // Data Bits
|
---|
212 | // ---------
|
---|
213 | hlp = settings.value("serialDataBits").toString();
|
---|
214 | if (hlp == "5") {
|
---|
215 | _serialPort->setDataBits(DATA_5);
|
---|
216 | }
|
---|
217 | else if (hlp == "6") {
|
---|
218 | _serialPort->setDataBits(DATA_6);
|
---|
219 | }
|
---|
220 | else if (hlp == "7") {
|
---|
221 | _serialPort->setDataBits(DATA_7);
|
---|
222 | }
|
---|
223 | else if (hlp == "8") {
|
---|
224 | _serialPort->setDataBits(DATA_8);
|
---|
225 | }
|
---|
226 | hlp = settings.value("serialStopBits").toString();
|
---|
227 | if (hlp == "1") {
|
---|
228 | _serialPort->setStopBits(STOP_1);
|
---|
229 | }
|
---|
230 | else if (hlp == "2") {
|
---|
231 | _serialPort->setStopBits(STOP_2);
|
---|
232 | }
|
---|
233 |
|
---|
234 | // Flow Control
|
---|
235 | // ------------
|
---|
236 | hlp = settings.value("serialFlowControl").toString();
|
---|
237 | if (hlp == "XONXOFF") {
|
---|
238 | _serialPort->setFlowControl(FLOW_XONXOFF);
|
---|
239 | }
|
---|
240 | else if (hlp == "HARDWARE") {
|
---|
241 | _serialPort->setFlowControl(FLOW_HARDWARE);
|
---|
242 | }
|
---|
243 | else {
|
---|
244 | _serialPort->setFlowControl(FLOW_OFF);
|
---|
245 | }
|
---|
246 |
|
---|
247 | // Open Serial Port
|
---|
248 | // ----------------
|
---|
249 | _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
|
---|
250 | if (!_serialPort->isOpen()) {
|
---|
251 | delete _serialPort;
|
---|
252 | _serialPort = 0;
|
---|
253 | emit(newMessage((_staID + ": Cannot open serial port\n"), true));
|
---|
254 | }
|
---|
255 | connect(_serialPort, SIGNAL(readyRead()),
|
---|
256 | this, SLOT(slotSerialReadyRead()));
|
---|
257 |
|
---|
258 | // Automatic NMEA
|
---|
259 | // --------------
|
---|
260 | if (settings.value("serialAutoNMEA").toString() == "Auto") {
|
---|
261 | _serialNMEA = AUTO_NMEA;
|
---|
262 |
|
---|
263 | QString fName = settings.value("serialFileNMEA").toString();
|
---|
264 | if (!fName.isEmpty()) {
|
---|
265 | _serialOutFile = new QFile(fName);
|
---|
266 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
267 | _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
268 | }
|
---|
269 | else {
|
---|
270 | _serialOutFile->open(QIODevice::WriteOnly);
|
---|
271 | }
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 | // Manual NMEA
|
---|
276 | // -----------
|
---|
277 | else {
|
---|
278 | _serialNMEA = MANUAL_NMEA;
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | // Initialize PPP Client?
|
---|
283 | // ----------------------
|
---|
284 | #ifndef MLS_SOFTWARE
|
---|
285 | if (settings.value("pppMount").toString() == _staID) {
|
---|
286 | _PPPclient = new bncPPPclient(_staID);
|
---|
287 | app->_bncPPPclient = _PPPclient;
|
---|
288 | qRegisterMetaType<bncTime>("bncTime");
|
---|
289 | connect(_PPPclient, SIGNAL(newPosition(bncTime, double, double, double)),
|
---|
290 | this, SIGNAL(newPosition(bncTime, double, double, double)));
|
---|
291 | connect(_PPPclient, SIGNAL(newNMEAstr(QByteArray)),
|
---|
292 | this, SIGNAL(newNMEAstr(QByteArray)));
|
---|
293 | }
|
---|
294 | #endif
|
---|
295 |
|
---|
296 | // Instantiate the decoder
|
---|
297 | // -----------------------
|
---|
298 | if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
|
---|
299 | _format.indexOf("RTCM 2") != -1 ) {
|
---|
300 | emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
|
---|
301 | _decoder = new RTCM2Decoder(_staID.data());
|
---|
302 | }
|
---|
303 | else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
|
---|
304 | _format.indexOf("RTCM 3") != -1 ) {
|
---|
305 | emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
|
---|
306 | _decoder = new RTCM3Decoder(_staID, _rawFile);
|
---|
307 | connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
|
---|
308 | this, SIGNAL(newMessage(QByteArray,bool)));
|
---|
309 | }
|
---|
310 | else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
|
---|
311 | emit(newMessage(_staID + ": Get Data in GPSS format", true));
|
---|
312 | _decoder = new gpssDecoder();
|
---|
313 | }
|
---|
314 | else if (_format.indexOf("ZERO") != -1) {
|
---|
315 | emit(newMessage(_staID + ": Get data in original format", true));
|
---|
316 | _decoder = new bncZeroDecoder(_staID);
|
---|
317 | }
|
---|
318 | else if (_format.indexOf("RTNET") != -1) {
|
---|
319 | emit(newMessage(_staID + ": Get data in RTNet format", true));
|
---|
320 | _decoder = new bncRtnetDecoder();
|
---|
321 | }
|
---|
322 | else if (_format.indexOf("HASS2ASCII") != -1) {
|
---|
323 | emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
|
---|
324 | _decoder = new hassDecoder(_staID);
|
---|
325 | }
|
---|
326 | else {
|
---|
327 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
---|
328 | _isToBeDeleted = true;
|
---|
329 | }
|
---|
330 |
|
---|
331 | _latencyChecker = new latencyChecker(_staID);
|
---|
332 |
|
---|
333 | msleep(100); //sleep 0.1 sec
|
---|
334 | }
|
---|
335 |
|
---|
336 | // Destructor
|
---|
337 | ////////////////////////////////////////////////////////////////////////////
|
---|
338 | bncGetThread::~bncGetThread() {
|
---|
339 | if (isRunning()) {
|
---|
340 | wait();
|
---|
341 | }
|
---|
342 | if (_query) {
|
---|
343 | _query->stop();
|
---|
344 | _query->deleteLater();
|
---|
345 | }
|
---|
346 | delete _PPPclient;
|
---|
347 | delete _decoder;
|
---|
348 | delete _decoderAux;
|
---|
349 | delete _rnx;
|
---|
350 | delete _rawFile;
|
---|
351 | delete _serialOutFile;
|
---|
352 | delete _serialPort;
|
---|
353 | delete _latencyChecker;
|
---|
354 | emit getThreadFinished(_staID);
|
---|
355 | }
|
---|
356 |
|
---|
357 | //
|
---|
358 | ////////////////////////////////////////////////////////////////////////////
|
---|
359 | void bncGetThread::terminate() {
|
---|
360 | _isToBeDeleted = true;
|
---|
361 | if (!isRunning()) {
|
---|
362 | delete this;
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 | // Run
|
---|
367 | ////////////////////////////////////////////////////////////////////////////
|
---|
368 | void bncGetThread::run() {
|
---|
369 |
|
---|
370 | while (true) {
|
---|
371 | try {
|
---|
372 | if (_isToBeDeleted) {
|
---|
373 | QThread::exit(0);
|
---|
374 | this->deleteLater();
|
---|
375 | return;
|
---|
376 | }
|
---|
377 |
|
---|
378 | if (tryReconnect() != success) {
|
---|
379 | _latencyChecker->checkReconnect();
|
---|
380 | continue;
|
---|
381 | }
|
---|
382 |
|
---|
383 | // Delete old observations
|
---|
384 | // -----------------------
|
---|
385 | _decoder->_obsList.clear();
|
---|
386 | if (_decoderAux) {
|
---|
387 | _decoderAux->_obsList.clear();
|
---|
388 | }
|
---|
389 |
|
---|
390 | GPSDecoder* decoderUsed = _decoder;
|
---|
391 |
|
---|
392 | // Read Data
|
---|
393 | // ---------
|
---|
394 | QByteArray data;
|
---|
395 | if (_query) {
|
---|
396 | _query->waitForReadyRead(data);
|
---|
397 | }
|
---|
398 | else if (_rawFile) {
|
---|
399 | data = _rawFile->readChunk();
|
---|
400 | if (_rawFile->format() == "HASS2ASCII") {
|
---|
401 | if (_decoderAux == 0) {
|
---|
402 | emit(newMessage(_rawFile->staID() + ": Get data in HASS2ASCII format", true));
|
---|
403 | _decoderAux = new hassDecoder(_rawFile->staID());
|
---|
404 | }
|
---|
405 | decoderUsed = _decoderAux;
|
---|
406 | }
|
---|
407 |
|
---|
408 | if (data.isEmpty()) {
|
---|
409 | cout << "no more data" << endl;
|
---|
410 | QThread::exit(0);
|
---|
411 | this->deleteLater();
|
---|
412 | return;
|
---|
413 | }
|
---|
414 | }
|
---|
415 | qint64 nBytes = data.size();
|
---|
416 |
|
---|
417 | // Timeout, reconnect
|
---|
418 | // ------------------
|
---|
419 | if (nBytes == 0) {
|
---|
420 | _latencyChecker->checkReconnect();
|
---|
421 | emit(newMessage(_staID + ": Data timeout, reconnecting", true));
|
---|
422 | msleep(10000); //sleep 10 sec, G. Weber
|
---|
423 | continue;
|
---|
424 | }
|
---|
425 | else {
|
---|
426 | emit newBytes(_staID, nBytes);
|
---|
427 | }
|
---|
428 |
|
---|
429 | // Output Data
|
---|
430 | // -----------
|
---|
431 | if (_rawOutput) {
|
---|
432 | bncApp* app = (bncApp*) qApp;
|
---|
433 | app->writeRawData(data, _staID, _format);
|
---|
434 | }
|
---|
435 |
|
---|
436 | if (_serialPort) {
|
---|
437 | slotSerialReadyRead();
|
---|
438 | _serialPort->write(data);
|
---|
439 | }
|
---|
440 |
|
---|
441 | // Decode Data
|
---|
442 | // -----------
|
---|
443 | vector<string> errmsg;
|
---|
444 | decoderUsed->_obsList.clear();
|
---|
445 | t_irc irc = decoderUsed->Decode(data.data(), data.size(), errmsg);
|
---|
446 |
|
---|
447 | // Perform various scans and checks
|
---|
448 | // --------------------------------
|
---|
449 | _latencyChecker->checkOutage(irc == success);
|
---|
450 | _latencyChecker->checkObsLatency(decoderUsed->_obsList);
|
---|
451 | _latencyChecker->checkCorrLatency(decoderUsed->corrGPSEpochTime());
|
---|
452 |
|
---|
453 | emit newLatency(_staID, _latencyChecker->currentLatency());
|
---|
454 |
|
---|
455 | scanRTCM();
|
---|
456 |
|
---|
457 | // Loop over all observations (observations output)
|
---|
458 | // ------------------------------------------------
|
---|
459 | QListIterator<t_obs> it(decoderUsed->_obsList);
|
---|
460 | bool firstObs = true;
|
---|
461 | while (it.hasNext()) {
|
---|
462 | const t_obs& obs = it.next();
|
---|
463 |
|
---|
464 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
465 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
466 | long iSec = long(floor(obs.GPSWeeks+0.5));
|
---|
467 | long obsTime = obs.GPSWeek * 7*24*3600 + iSec;
|
---|
468 |
|
---|
469 | // Check observation epoch
|
---|
470 | // -----------------------
|
---|
471 | if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoderUsed)) {
|
---|
472 | int week;
|
---|
473 | double sec;
|
---|
474 | currentGPSWeeks(week, sec);
|
---|
475 | long currTime = week * 7*24*3600 + long(sec);
|
---|
476 | const double maxDt = 600.0;
|
---|
477 | if (fabs(currTime - obsTime) > maxDt) {
|
---|
478 | emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
|
---|
479 | continue;
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | // Check observations coming twice (e.g. KOUR0 Problem)
|
---|
484 | // ----------------------------------------------------
|
---|
485 | QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
|
---|
486 | if (it != _prnLastEpo.end()) {
|
---|
487 | long oldTime = it.value();
|
---|
488 | if (obsTime < oldTime) {
|
---|
489 | emit( newMessage(_staID +
|
---|
490 | ": old observation " + prn.toAscii(), false));
|
---|
491 | continue;
|
---|
492 | }
|
---|
493 | else if (obsTime == oldTime) {
|
---|
494 | emit( newMessage(_staID +
|
---|
495 | ": observation coming more than once " + prn.toAscii(), false));
|
---|
496 | continue;
|
---|
497 | }
|
---|
498 | }
|
---|
499 | _prnLastEpo[prn] = obsTime;
|
---|
500 |
|
---|
501 | // RINEX Output
|
---|
502 | // ------------
|
---|
503 | if (_rnx) {
|
---|
504 | if (_samplingRate == 0 || iSec % _samplingRate == 0) {
|
---|
505 | _rnx->deepCopy(obs);
|
---|
506 | }
|
---|
507 | _rnx->dumpEpoch(obsTime);
|
---|
508 | }
|
---|
509 |
|
---|
510 | // PPP Client
|
---|
511 | // ----------
|
---|
512 | #ifndef MLS_SOFTWARE
|
---|
513 | if (_PPPclient) {
|
---|
514 | _PPPclient->putNewObs(obs);
|
---|
515 | }
|
---|
516 | #endif
|
---|
517 |
|
---|
518 | // Emit new observation signal
|
---|
519 | // ---------------------------
|
---|
520 | if (!_isToBeDeleted) {
|
---|
521 | emit newObs(_staID, firstObs, obs);
|
---|
522 | }
|
---|
523 | firstObs = false;
|
---|
524 | }
|
---|
525 | decoderUsed->_obsList.clear();
|
---|
526 | }
|
---|
527 | catch (Exception& exc) {
|
---|
528 | emit(newMessage(_staID + " " + exc.what(), true));
|
---|
529 | _isToBeDeleted = true;
|
---|
530 | }
|
---|
531 | catch (...) {
|
---|
532 | emit(newMessage(_staID + " bncGetThread exception", true));
|
---|
533 | _isToBeDeleted = true;
|
---|
534 | }
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | // Try Re-Connect
|
---|
539 | ////////////////////////////////////////////////////////////////////////////
|
---|
540 | t_irc bncGetThread::tryReconnect() {
|
---|
541 |
|
---|
542 | // Easy Return
|
---|
543 | // -----------
|
---|
544 | if (_query && _query->status() == bncNetQuery::running) {
|
---|
545 | _nextSleep = 0;
|
---|
546 | if (_rnx) {
|
---|
547 | _rnx->setReconnectFlag(false);
|
---|
548 | }
|
---|
549 | return success;
|
---|
550 | }
|
---|
551 |
|
---|
552 | // Start a new query
|
---|
553 | // -----------------
|
---|
554 | if (!_rawFile) {
|
---|
555 |
|
---|
556 | sleep(_nextSleep);
|
---|
557 | if (_nextSleep == 0) {
|
---|
558 | _nextSleep = 1;
|
---|
559 | }
|
---|
560 | else {
|
---|
561 | _nextSleep = 2 * _nextSleep;
|
---|
562 | if (_nextSleep > 256) {
|
---|
563 | _nextSleep = 256;
|
---|
564 | }
|
---|
565 | #ifdef MLS_SOFTWARE
|
---|
566 | if (_nextSleep > 4) {
|
---|
567 | _nextSleep = 4;
|
---|
568 | }
|
---|
569 | #endif
|
---|
570 | }
|
---|
571 |
|
---|
572 | delete _query;
|
---|
573 | if (_ntripVersion == "U") {
|
---|
574 | _query = new bncNetQueryUdp();
|
---|
575 | }
|
---|
576 | else if (_ntripVersion == "R") {
|
---|
577 | _query = new bncNetQueryRtp();
|
---|
578 | }
|
---|
579 | else if (_ntripVersion == "S") {
|
---|
580 | _query = new bncNetQueryS();
|
---|
581 | }
|
---|
582 | else if (_ntripVersion == "N") {
|
---|
583 | _query = new bncNetQueryV0();
|
---|
584 | }
|
---|
585 | else if (_ntripVersion == "UN") {
|
---|
586 | _query = new bncNetQueryUdp0();
|
---|
587 | }
|
---|
588 | else if (_ntripVersion == "2") {
|
---|
589 | _query = new bncNetQueryV2(false);
|
---|
590 | }
|
---|
591 | else if (_ntripVersion == "2s") {
|
---|
592 | _query = new bncNetQueryV2(true);
|
---|
593 | }
|
---|
594 | else {
|
---|
595 | _query = new bncNetQueryV1();
|
---|
596 | }
|
---|
597 | if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
|
---|
598 | QByteArray gga = ggaString(_latitude, _longitude, "100.0");
|
---|
599 | _query->startRequest(_mountPoint, gga);
|
---|
600 | }
|
---|
601 | else {
|
---|
602 | _query->startRequest(_mountPoint, "");
|
---|
603 | }
|
---|
604 | if (_query->status() != bncNetQuery::running) {
|
---|
605 | return failure;
|
---|
606 | }
|
---|
607 | }
|
---|
608 |
|
---|
609 | if (_rnx) {
|
---|
610 | _rnx->setReconnectFlag(true);
|
---|
611 | }
|
---|
612 |
|
---|
613 | return success;
|
---|
614 | }
|
---|
615 |
|
---|
616 | // RTCM scan output
|
---|
617 | //////////////////////////////////////////////////////////////////////////////
|
---|
618 | void bncGetThread::scanRTCM() {
|
---|
619 |
|
---|
620 | bncSettings settings;
|
---|
621 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
|
---|
622 |
|
---|
623 | if ( _miscMount == _staID || _miscMount == "ALL" ) {
|
---|
624 |
|
---|
625 | // RTCM message types
|
---|
626 | // ------------------
|
---|
627 | for (int ii = 0; ii <_decoder->_typeList.size(); ii++) {
|
---|
628 | QString type = QString("%1 ").arg(_decoder->_typeList[ii]);
|
---|
629 | emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
|
---|
630 | }
|
---|
631 |
|
---|
632 | // RTCMv3 antenna descriptor
|
---|
633 | // -------------------------
|
---|
634 | for (int ii=0;ii<_decoder->_antType.size();ii++) {
|
---|
635 | QString ant1 = QString("%1 ").arg(_decoder->_antType[ii]);
|
---|
636 | emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
|
---|
637 | }
|
---|
638 |
|
---|
639 | // RTCM Antenna Coordinates
|
---|
640 | // ------------------------
|
---|
641 | for (int ii=0; ii <_decoder->_antList.size(); ii++) {
|
---|
642 | QByteArray antT;
|
---|
643 | if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
644 | antT = "ARP";
|
---|
645 | }
|
---|
646 | else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
647 | antT = "APC";
|
---|
648 | }
|
---|
649 | QByteArray ant1, ant2, ant3;
|
---|
650 | ant1 = QString("%1 ").arg(_decoder->_antList[ii].xx,0,'f',4).toAscii();
|
---|
651 | ant2 = QString("%1 ").arg(_decoder->_antList[ii].yy,0,'f',4).toAscii();
|
---|
652 | ant3 = QString("%1 ").arg(_decoder->_antList[ii].zz,0,'f',4).toAscii();
|
---|
653 | emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
|
---|
654 | emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
|
---|
655 | emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
|
---|
656 | if (_decoder->_antList[ii].height_f) {
|
---|
657 | QByteArray ant4 = QString("%1 ").arg(_decoder->_antList[ii].height,0,'f',4).toAscii();
|
---|
658 | emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
|
---|
659 | }
|
---|
660 | emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
|
---|
661 | _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
---|
662 | antT));
|
---|
663 | }
|
---|
664 | }
|
---|
665 | }
|
---|
666 |
|
---|
667 | #ifdef MLS_SOFTWARE
|
---|
668 | for (int ii=0; ii <_decoder->_antList.size(); ii++) {
|
---|
669 | QByteArray antT;
|
---|
670 | if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
671 | antT = "ARP";
|
---|
672 | }
|
---|
673 | else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
674 | antT = "APC";
|
---|
675 | }
|
---|
676 | emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
|
---|
677 | _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
---|
678 | antT));
|
---|
679 | }
|
---|
680 |
|
---|
681 | for (int ii = 0; ii <_decoder->_typeList.size(); ii++) {
|
---|
682 | emit(newRTCMMessage(_staID, _decoder->_typeList[ii]));
|
---|
683 | }
|
---|
684 | #endif
|
---|
685 |
|
---|
686 |
|
---|
687 |
|
---|
688 |
|
---|
689 | _decoder->_typeList.clear();
|
---|
690 | _decoder->_antType.clear();
|
---|
691 | _decoder->_antList.clear();
|
---|
692 | }
|
---|
693 |
|
---|
694 | // Handle Data from Serial Port
|
---|
695 | ////////////////////////////////////////////////////////////////////////////
|
---|
696 | void bncGetThread::slotSerialReadyRead() {
|
---|
697 | if (_serialPort) {
|
---|
698 | int nb = _serialPort->bytesAvailable();
|
---|
699 | if (nb > 0) {
|
---|
700 | QByteArray data = _serialPort->read(nb);
|
---|
701 |
|
---|
702 | if (_serialNMEA == AUTO_NMEA) {
|
---|
703 | int i1 = data.indexOf("$GPGGA");
|
---|
704 | if (i1 != -1) {
|
---|
705 | int i2 = data.indexOf("*", i1);
|
---|
706 | if (i2 != -1 && data.size() > i2 + 1) {
|
---|
707 | QByteArray gga = data.mid(i1,i2-i1+3);
|
---|
708 | _query->sendNMEA(gga);
|
---|
709 | }
|
---|
710 | }
|
---|
711 | }
|
---|
712 |
|
---|
713 | if (_serialOutFile) {
|
---|
714 | _serialOutFile->write(data);
|
---|
715 | _serialOutFile->flush();
|
---|
716 | }
|
---|
717 | }
|
---|
718 | }
|
---|
719 | }
|
---|
720 |
|
---|
721 | //
|
---|
722 | //////////////////////////////////////////////////////////////////////////////
|
---|
723 | void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
724 | RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
|
---|
725 | RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(_decoder);
|
---|
726 |
|
---|
727 | if ( decoder2 ) {
|
---|
728 | QMutexLocker locker(&_mutex);
|
---|
729 |
|
---|
730 | string storedPRN;
|
---|
731 | vector<int> IODs;
|
---|
732 |
|
---|
733 | if ( decoder2->storeEph(gpseph, storedPRN, IODs) ) {
|
---|
734 | #ifdef DEBUG_RTCM2_2021
|
---|
735 | QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
|
---|
736 |
|
---|
737 | for (unsigned ii = 0; ii < IODs.size(); ii++) {
|
---|
738 | msg += QString(" %1").arg(IODs[ii],4);
|
---|
739 | }
|
---|
740 |
|
---|
741 | emit(newMessage(msg.toAscii()));
|
---|
742 | #endif
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | if ( decoder3 ) {
|
---|
747 | QMutexLocker locker(&_mutex);
|
---|
748 |
|
---|
749 | if ( decoder3->storeEph(gpseph) ) {
|
---|
750 | #ifdef DEBUG_RTCM3
|
---|
751 | QString msg = _staID + QString(": RTCM3Decoder, stored eph for satellite %1").arg(gpseph.satellite);
|
---|
752 | emit(newMessage(msg.toAscii(),true));
|
---|
753 | #endif
|
---|
754 | }
|
---|
755 | }
|
---|
756 | }
|
---|
757 |
|
---|