source: ntrip/trunk/BNC/src/bncgetthread.cpp@ 11061

Last change on this file since 11061 was 11057, checked in by stuerze, 2 weeks ago

bug fixes resulting from overall tests

File size: 37.5 KB
Line 
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://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 <iostream>
43#include <iomanip>
44#include <sstream>
45
46#include <QComboBox>
47#include <QDialog>
48#include <QFile>
49#include <QTextStream>
50#include <QMutex>
51#include <QPushButton>
52#include <QTableWidget>
53#include <QTime>
54
55#include "bncgetthread.h"
56#include "bnctabledlg.h"
57#include "bnccore.h"
58#include "bncutils.h"
59#include "bnctime.h"
60#include "bnczerodecoder.h"
61#include "bncnetqueryv0.h"
62#include "bncnetqueryv1.h"
63#include "bncnetqueryv2.h"
64#include "bncnetqueryrtp.h"
65#include "bncnetqueryudp.h"
66#include "bncnetqueryudp0.h"
67#include "bncnetquerys.h"
68#include "bncsettings.h"
69#include "latencychecker.h"
70#include "upload/bncrtnetdecoder.h"
71#include "RTCM/RTCM2Decoder.h"
72#include "RTCM3/RTCM3Decoder.h"
73#include "serial/qextserialport.h"
74
75using namespace std;
76
77// Constructor 1
78////////////////////////////////////////////////////////////////////////////
79bncGetThread::bncGetThread(bncRawFile* rawFile) {
80
81 _rawFile = rawFile;
82 _format = rawFile->format();
83 _staID = rawFile->staID();
84 _rawOutput = false;
85 _ntripVersion = "N";
86
87 initialize();
88}
89
90// Constructor 2
91////////////////////////////////////////////////////////////////////////////
92bncGetThread::bncGetThread(const QUrl& mountPoint, const QByteArray& format,
93 const QByteArray& latitude, const QByteArray& longitude,
94 const QByteArray& nmea, const QByteArray& ntripVersion) {
95 _rawFile = 0;
96 _mountPoint = mountPoint;
97 _staID = mountPoint.path().mid(1).toLatin1();
98 _format = format;
99 _latitude = latitude;
100 _longitude = longitude;
101 _nmea = nmea;
102 _ntripVersion = ntripVersion;
103
104 bncSettings settings;
105 if (!settings.value("rawOutFile").toString().isEmpty()) {
106 _rawOutput = true;
107 }
108 else {
109 _rawOutput = false;
110 }
111
112 _latencycheck = true; // in order to allow at least to check for reconnect
113
114 _NMEASampl = settings.value("serialNMEASampling").toInt();
115
116 initialize();
117 initDecoder();
118}
119
120// Initialization (common part of the constructor)
121////////////////////////////////////////////////////////////////////////////
122void bncGetThread::initialize() {
123
124 bncSettings settings;
125
126 setTerminationEnabled(true);
127
128 connect(this, SIGNAL(newMessage(QByteArray,bool)),
129 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
130
131 _isToBeDeleted = false;
132 _query = 0;
133 _nextSleep = 0;
134 _miscMount = settings.value("miscMount").toString();
135 _decoder = 0;
136
137 // NMEA Port
138 // -----------
139 QListIterator<QString> iSta(settings.value("PPP/staTable").toStringList());
140 int nmeaPort = 0;
141 while (iSta.hasNext()) {
142 QStringList hlp = iSta.next().split(",");
143 if (hlp.size() < 10) {
144 continue;
145 }
146 QByteArray mp = hlp[0].toLatin1();
147 if (_staID == mp) {
148 nmeaPort = hlp[9].toInt();
149 }
150 }
151 if (nmeaPort != 0) {
152 _nmeaServer = new QTcpServer;
153 _nmeaServer->setProxy(QNetworkProxy::NoProxy);
154 if (!_nmeaServer->listen(QHostAddress::LocalHost, nmeaPort)) {
155 QString message = "bncCaster: Cannot listen on port "
156 + QByteArray::number(nmeaPort) + ": "
157 + _nmeaServer->errorString();
158 emit newMessage(message.toLatin1(), true);
159 }
160 else {
161 connect(_nmeaServer, SIGNAL(newConnection()), this, SLOT(slotNewNMEAConnection()));
162 connect(BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)), this, SLOT(slotNewNMEAstr(QByteArray, QByteArray)));
163 _nmeaSockets = new QList<QTcpSocket*>;
164 _nmeaPortsMap[_staID] = nmeaPort;
165 }
166 } else {
167 _nmeaServer = 0;
168 _nmeaSockets = 0;
169 }
170
171 // Serial Port
172 // -----------
173 _serialNMEA = NO_NMEA;
174 _serialOutFile = 0;
175 _serialPort = 0;
176 QString portString = settings.value("serialPortName").toString();
177
178 if (!_staID.isEmpty()
179 && settings.value("serialMountPoint").toString() == _staID) {
180 _serialPort = new QextSerialPort(portString);
181 _serialPort->setTimeout(0, 100);
182
183 // Baud Rate
184 // ---------
185 QString hlp = settings.value("serialBaudRate").toString();
186 if (hlp == "110") {
187 _serialPort->setBaudRate(BAUD110);
188 } else if (hlp == "300") {
189 _serialPort->setBaudRate(BAUD300);
190 } else if (hlp == "600") {
191 _serialPort->setBaudRate(BAUD600);
192 } else if (hlp == "1200") {
193 _serialPort->setBaudRate(BAUD1200);
194 } else if (hlp == "2400") {
195 _serialPort->setBaudRate(BAUD2400);
196 } else if (hlp == "4800") {
197 _serialPort->setBaudRate(BAUD4800);
198 } else if (hlp == "9600") {
199 _serialPort->setBaudRate(BAUD9600);
200 } else if (hlp == "19200") {
201 _serialPort->setBaudRate(BAUD19200);
202 } else if (hlp == "38400") {
203 _serialPort->setBaudRate(BAUD38400);
204 } else if (hlp == "57600") {
205 _serialPort->setBaudRate(BAUD57600);
206 } else if (hlp == "115200") {
207 _serialPort->setBaudRate(BAUD115200);
208 }
209
210 // Parity
211 // ------
212 hlp = settings.value("serialParity").toString();
213 if (hlp == "NONE") {
214 _serialPort->setParity(PAR_NONE);
215 } else if (hlp == "ODD") {
216 _serialPort->setParity(PAR_ODD);
217 } else if (hlp == "EVEN") {
218 _serialPort->setParity(PAR_EVEN);
219 } else if (hlp == "SPACE") {
220 _serialPort->setParity(PAR_SPACE);
221 }
222
223 // Data Bits
224 // ---------
225 hlp = settings.value("serialDataBits").toString();
226 if (hlp == "5") {
227 _serialPort->setDataBits(DATA_5);
228 } else if (hlp == "6") {
229 _serialPort->setDataBits(DATA_6);
230 } else if (hlp == "7") {
231 _serialPort->setDataBits(DATA_7);
232 } else if (hlp == "8") {
233 _serialPort->setDataBits(DATA_8);
234 }
235 // Stop Bits
236 // ---------
237 hlp = settings.value("serialStopBits").toString();
238 if (hlp == "1") {
239 _serialPort->setStopBits(STOP_1);
240 } else if (hlp == "2") {
241 _serialPort->setStopBits(STOP_2);
242 }
243
244 // Flow Control
245 // ------------
246 hlp = settings.value("serialFlowControl").toString();
247 if (hlp == "XONXOFF") {
248 _serialPort->setFlowControl(FLOW_XONXOFF);
249 } else if (hlp == "HARDWARE") {
250 _serialPort->setFlowControl(FLOW_HARDWARE);
251 } else {
252 _serialPort->setFlowControl(FLOW_OFF);
253 }
254
255 // Open Serial Port
256 // ----------------
257 _serialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
258 msleep(100); //sleep 0.1 sec
259 if (!_serialPort->isOpen()) {
260 emit(newMessage(_staID + ": Cannot open serial port " + portString.toLatin1()
261 + ": " + _serialPort->errorString().toLatin1(), true));
262 delete _serialPort;
263 _serialPort = 0;
264 }
265 else {
266 emit(newMessage(_staID + ": Serial port " + portString.toLatin1()
267 + "is connected: " + _serialPort->errorString().toLatin1(), true));
268 connect(_serialPort, SIGNAL(readyRead()), this, SLOT(slotSerialReadyRead()));
269 }
270
271 // Automatic NMEA
272 // --------------
273 QString nmeaMode = settings.value("serialAutoNMEA").toString();
274 if (nmeaMode == "Auto") {
275 _serialNMEA = AUTO_NMEA;
276 QString fName = settings.value("serialFileNMEA").toString();
277 if (!fName.isEmpty()) {
278 _serialOutFile = new QFile(fName);
279 if (Qt::CheckState(settings.value("rnxAppend").toInt())
280 == Qt::Checked) {
281 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
282 } else {
283 _serialOutFile->open(QIODevice::WriteOnly);
284 }
285 }
286 }
287 // Manual NMEA
288 // -----------
289 if ((nmeaMode == "Manual GPGGA") ||
290 (nmeaMode == "Manual GNGGA")) {
291 _serialNMEA = MANUAL_NMEA;
292 bncSettings settings;
293 QString hlp = settings.value("serialHeightNMEA").toString();
294 if (hlp.isEmpty()) {
295 hlp = "0.0";
296 }
297 QByteArray _serialHeightNMEA = hlp.toLatin1();
298 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA, nmeaMode);
299 }
300 }
301
302 if (!_staID.isEmpty() && _latencycheck) {
303 _latencyChecker = new latencyChecker(_staID);
304 _rtcmObs = false;
305 _rtcmSsrOrb = false;
306 _rtcmSsrClk = false;
307 _rtcmSsrOrbClk = false;
308 _rtcmSsrCbi = false;
309 _rtcmSsrPbi = false;
310 _rtcmSsrVtec = false;
311 _rtcmSsrUra = false;
312 _rtcmSsrHr = false;
313 _rtcmSsrIgs = false;
314 _ssrEpoch = 0;
315 } else {
316 _latencyChecker = 0;
317 }
318}
319
320// Instantiate the decoder
321//////////////////////////////////////////////////////////////////////////////
322t_irc bncGetThread::initDecoder() {
323
324 _decoder = 0;
325
326 if (_format.indexOf("RTCM_2") != -1 ||
327 _format.indexOf("RTCM2") != -1 ||
328 _format.indexOf("RTCM 2") != -1) {
329 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
330 _decoder = new RTCM2Decoder(_staID.data());
331 } else if (_format.indexOf("RTCM_3") != -1 ||
332 _format.indexOf("RTCM3") != -1 ||
333 _format.indexOf("RTCM 3") != -1) {
334 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
335 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
336 _decoder = newDecoder;
337 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
338 this, SIGNAL(newMessage(QByteArray,bool)));
339 } else if (_format == "ZERO") {
340 emit(newMessage(_staID + ": Forward data in original format", true));
341 _decoder = new bncZeroDecoder(_staID, false);
342 }
343 else if (_format == "ZERO2FILE") {
344 emit(newMessage(_staID + ": Get data in original format and store it", true));
345 _decoder = new bncZeroDecoder(_staID, true);
346 }
347 else if (_format.indexOf("RTNET") != -1) {
348 emit(newMessage(_staID + ": Get data in RTNet format", true));
349 _decoder = new bncRtnetDecoder();
350 } else {
351 emit(newMessage(_staID + ": Unknown data format " + _format + ". Please change the format entry to ZERO or ZERO2FILE to forward unchanged data.", true));
352 _isToBeDeleted = true;
353 return failure;
354 }
355
356 msleep(100); //sleep 0.1 sec
357
358 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
359 _ntripVersion);
360
361 if (_rawFile) {
362 _decodersRaw[_staID] = _decoder;
363 }
364
365 return success;
366}
367
368// Current decoder in use
369////////////////////////////////////////////////////////////////////////////
370GPSDecoder* bncGetThread::decoder() {
371 if (!_rawFile) {
372 return _decoder;
373 } else {
374 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
375 return _decodersRaw[_staID];
376 }
377 }
378 return 0;
379}
380
381// Destructor
382////////////////////////////////////////////////////////////////////////////
383bncGetThread::~bncGetThread() {
384 if (isRunning()) {
385 wait();
386 }
387 if (_query) {
388 _query->stop();
389 _query->deleteLater();
390 }
391 if (_rawFile) {
392 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
393 while (it.hasNext()) {
394 it.next();
395 delete it.value();
396 }
397 _decodersRaw.clear();
398 } else {
399 delete _decoder;
400 }
401 delete _rawFile;
402 delete _serialOutFile;
403 delete _serialPort;
404 delete _latencyChecker;
405 delete _nmeaServer;
406 delete _nmeaSockets;
407 emit getThreadFinished(_staID);
408}
409
410//
411////////////////////////////////////////////////////////////////////////////
412void bncGetThread::terminate() {
413 _isToBeDeleted = true;
414
415 if (_nmeaPortsMap.contains(_staID)) {
416 _nmeaPortsMap.remove(_staID);
417 }
418 delete _nmeaServer; _nmeaServer = nullptr;
419 delete _nmeaSockets; _nmeaSockets = nullptr;
420
421#ifdef BNC_DEBUG
422 if (BNC_CORE->mode() != t_bncCore::interactive) {
423 while (!isFinished()) {
424 wait();
425 }
426 delete this;
427 } else {
428 if (!isRunning()) {
429 delete this;
430 }
431 }
432#else
433 if (!isRunning()) {delete this;}
434#endif
435
436}
437
438// Run
439////////////////////////////////////////////////////////////////////////////
440void bncGetThread::run() {
441
442 while (true) {
443 try {
444 if (_isToBeDeleted) {
445 emit(newMessage(_staID + ": is to be deleted", true));
446 QThread::exit(4);
447 this->deleteLater();
448 return;
449 }
450
451 if (tryReconnect() != success) {
452 if (_latencyChecker) {
453 _latencyChecker->checkReconnect();
454 }
455 continue;
456 }
457
458 // Delete old observations
459 // -----------------------
460 if (_rawFile) {
461 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
462 while (itDec.hasNext()) {
463 itDec.next();
464 GPSDecoder* decoder = itDec.value();
465 decoder->_obsList.clear();
466 }
467 } else {
468 _decoder->_obsList.clear();
469 }
470
471 // Read Data
472 // ---------
473 QByteArray data;
474 if (_query) {
475 _query->waitForReadyRead(data);
476 } else if (_rawFile) {
477 data = _rawFile->readChunk();
478 _format = _rawFile->format();
479 _staID = _rawFile->staID();
480
481 QCoreApplication::processEvents();
482
483 if (data.isEmpty() || BNC_CORE->sigintReceived) {
484 emit(newMessage("No more data or SIGINT/SIGTERM received", true));
485 // pass on data the decoders still hold back (last epoch)
486 QMapIterator<QString, GPSDecoder*> itFlush(_decodersRaw);
487 while (itFlush.hasNext()) {
488 itFlush.next();
489 itFlush.value()->flush();
490 }
491 BNC_CORE->stopPPP();
492 BNC_CORE->stopCombination();
493 sleep(2);
494 ::exit(5);
495 }
496 }
497
498 qint64 nBytes = data.size();
499
500 // Timeout, reconnect
501 // ------------------
502 if (nBytes == 0) {
503 if (_latencyChecker) {
504 _latencyChecker->checkReconnect();
505 }
506 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
507 msleep(10000); //sleep 10 sec, G. Weber
508 continue;
509 } else {
510 emit newBytes(_staID, nBytes);
511 emit newRawData(_staID, data);
512 }
513
514 // Output Data
515 // -----------
516 if (_rawOutput) {
517 BNC_CORE->writeRawData(data, _staID, _format);
518 }
519
520 if (_serialPort) {
521 slotSerialReadyRead();
522 _serialPort->write(data);
523 }
524
525 // Decode Data
526 // -----------
527 vector<string> errmsg;
528 if (!decoder()) {
529 _isToBeDeleted = true;
530 continue;
531 }
532
533 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
534
535 if (irc != success) {
536 continue;
537 }
538 // Perform various scans and checks
539 // --------------------------------
540 if (_latencyChecker) {
541 _latencyChecker->checkOutage(irc);
542 QListIterator<GPSDecoder::t_typeInfo> it(decoder()->_typeList);
543 _ssrEpoch = static_cast<int>(decoder()->corrGPSEpochTime());
544 if (_ssrEpoch != -1) {
545 if (_rtcmSsrOrb) {
546 _latencyChecker->checkCorrLatency(_ssrEpoch, 1057);
547 _rtcmSsrOrb = false;
548 }
549 if (_rtcmSsrClk) {
550 _latencyChecker->checkCorrLatency(_ssrEpoch, 1058);
551 _rtcmSsrClk = false;
552 }
553 if (_rtcmSsrOrbClk) {
554 _latencyChecker->checkCorrLatency(_ssrEpoch, 1060);
555 _rtcmSsrOrbClk = false;
556 }
557 if (_rtcmSsrCbi) {
558 _latencyChecker->checkCorrLatency(_ssrEpoch, 1059);
559 _rtcmSsrCbi = false;
560 }
561 if (_rtcmSsrPbi) {
562 _latencyChecker->checkCorrLatency(_ssrEpoch, 1265);
563 _rtcmSsrPbi = false;
564 }
565 if (_rtcmSsrVtec) {
566 _latencyChecker->checkCorrLatency(_ssrEpoch, 1264);
567 _rtcmSsrVtec = false;
568 }
569 if (_rtcmSsrUra) {
570 _latencyChecker->checkCorrLatency(_ssrEpoch, 1061);
571 _rtcmSsrUra = false;
572 }
573 if (_rtcmSsrHr) {
574 _latencyChecker->checkCorrLatency(_ssrEpoch, 1062);
575 _rtcmSsrHr = false;
576 }
577 if (_rtcmSsrIgs) {
578 _latencyChecker->checkCorrLatency(_ssrEpoch, 4076);
579 _rtcmSsrIgs = false;
580 }
581 }
582 while (it.hasNext()) {
583 int rtcmType = it.next()._type;
584 if ((rtcmType >= 1001 && rtcmType <= 1004) || // legacy RTCM OBS
585 (rtcmType >= 1009 && rtcmType <= 1012) || // legacy RTCM OBS
586 (rtcmType >= 1070 && rtcmType <= 1137)) { // MSM RTCM OBS
587 _rtcmObs = true;
588 } else if ((rtcmType >= 1057 && rtcmType <= 1068) ||
589 (rtcmType >= 1240 && rtcmType <= 1270) ||
590 (rtcmType == 4076)) {
591 switch (rtcmType) {
592 case 1057: case 1063: case 1240: case 1246: case 1252: case 1258:
593 _rtcmSsrOrb = true;
594 break;
595 case 1058: case 1064: case 1241: case 1247: case 1253: case 1259:
596 _rtcmSsrClk = true;
597 break;
598 case 1060: case 1066: case 1243: case 1249: case 1255: case 1261:
599 _rtcmSsrOrbClk = true;
600 break;
601 case 1059: case 1065: case 1242: case 1248: case 1254: case 1260:
602 _rtcmSsrCbi = true;
603 break;
604 case 1265: case 1266: case 1267: case 1268: case 1269: case 1270:
605 _rtcmSsrPbi = true;
606 break;
607 case 1264:
608 _rtcmSsrVtec = true;
609 break;
610 case 1061: case 1067: case 1244: case 1250: case 1256: case 1262:
611 _rtcmSsrUra = true;
612 break;
613 case 1062: case 1068: case 1245: case 1251: case 1257: case 1263:
614 _rtcmSsrHr = true;
615 break;
616 case 4076:
617 _rtcmSsrIgs = true;
618 break;
619 }
620 }
621 }
622 if (_rtcmObs) {
623 _latencyChecker->checkObsLatency(decoder()->_obsList);
624 }
625 emit newLatency(_staID, _latencyChecker->currentLatency());
626 }
627 miscScanRTCM();
628
629 // Loop over all observations (observations output)
630 // ------------------------------------------------
631 QListIterator<t_satObs> it(decoder()->_obsList);
632
633 QList<t_satObs> obsListHlp;
634
635 while (it.hasNext()) {
636 const t_satObs& obs = it.next();
637
638 // Check observation epoch
639 // -----------------------
640 if (!_rawFile) {
641 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
642 if (wrongObservationEpoch) {
643 QString prn(obs._prn.toString().c_str());
644 QString type = QString("%1").arg(obs._type);
645 emit(newMessage(_staID + " (" + prn.toLatin1() + ")" + ": Wrong observation epoch(s)" + "( MT: " + type.toLatin1() + ")", false));
646 continue;
647 }
648 }
649
650 // Check observations coming twice (e.g. KOUR0 Problem)
651 // ----------------------------------------------------
652 if (!_rawFile) {
653 QString prn(obs._prn.toString().c_str());
654 bncTime obsTime = obs._time;
655 QMap<QString, bncTime>::const_iterator it = _prnLastEpo.find(prn);
656 if (it != _prnLastEpo.end()) {
657 bncTime oldTime = it.value();
658 if (obsTime < oldTime) {
659 emit(newMessage(_staID + ": old observation " + prn.toLatin1(), false));
660 continue;
661 } else if (obsTime == oldTime) {
662 emit(newMessage(_staID + ": observation coming more than once " + prn.toLatin1(), false));
663 continue;
664 }
665 }
666 _prnLastEpo[prn] = obsTime;
667 }
668
669 decoder()->dumpRinexEpoch(obs, _format);
670
671 // Save observations
672 // -----------------
673 obsListHlp.append(obs);
674 }
675
676 // Emit signal
677 // -----------
678 if (!_isToBeDeleted && obsListHlp.size() > 0) {
679 emit newObs(_staID, obsListHlp);
680 }
681
682 }
683 catch (Exception& exc) {
684 emit(newMessage(_staID + " " + exc.what(), true));
685 _isToBeDeleted = true;
686 }
687 catch (std::exception& exc) {
688 emit(newMessage(_staID + " " + exc.what(), true));
689 _isToBeDeleted = true;
690 }
691 catch (const string& error) {
692 emit(newMessage(_staID + " ERROR: " + error.c_str(), true));
693 _isToBeDeleted = true;
694 }
695 catch (const char* error) {
696 emit(newMessage(_staID + " ERROR: " + error, true));
697 _isToBeDeleted = true;
698 }
699 catch (QString error) {
700 emit(newMessage(_staID + " ERROR: " + error.toStdString().c_str(), true));
701 _isToBeDeleted = true;
702 }
703 catch (...) {
704 emit(newMessage(_staID + " bncGetThread: unknown exception", true));
705 _isToBeDeleted = true;
706 }
707 }
708}
709
710// Try Re-Connect
711////////////////////////////////////////////////////////////////////////////
712t_irc bncGetThread::tryReconnect() {
713
714 // Easy Return
715 // -----------
716 if (_query && _query->status() == bncNetQuery::running) {
717 _nextSleep = 0;
718 if (_rawFile) {
719 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
720 while (itDec.hasNext()) {
721 itDec.next();
722 GPSDecoder* decoder = itDec.value();
723 decoder->setRinexReconnectFlag(false);
724 }
725 } else {
726 _decoder->setRinexReconnectFlag(false);
727 }
728 return success;
729 }
730
731 // Start a new query
732 // -----------------
733 if (!_rawFile) {
734
735 sleep(_nextSleep);
736 if (_nextSleep == 0) {
737 _nextSleep = 1;
738 } else {
739 _nextSleep = 2 * _nextSleep;
740 if (_nextSleep > 256) {
741 _nextSleep = 256;
742 }
743#ifdef MLS_SOFTWARE
744 if (_nextSleep > 4) {
745 _nextSleep = 4;
746 }
747#endif
748 }
749 delete _query;
750 if (_ntripVersion == "U") {
751 _query = new bncNetQueryUdp();
752 } else if (_ntripVersion == "R") {
753 _query = new bncNetQueryRtp();
754 } else if (_ntripVersion == "S") {
755 _query = new bncNetQueryS();
756 } else if (_ntripVersion == "N") {
757 _query = new bncNetQueryV0();
758 } else if (_ntripVersion == "UN") {
759 _query = new bncNetQueryUdp0();
760 } else if (_ntripVersion == "2") {
761 _query = new bncNetQueryV2(false);
762 } else if (_ntripVersion == "2s") {
763 _query = new bncNetQueryV2(true);
764 } else {
765 _query = new bncNetQueryV1();
766 }
767 if (_nmea == "yes") {
768 if (_serialNMEA == MANUAL_NMEA) {
769 _query->startRequest(_mountPoint, _manualNMEAString);
770 _lastNMEA = QDateTime::currentDateTime();
771 } else if (_serialNMEA == AUTO_NMEA) {
772 if (_serialPort) {
773 int nb = _serialPort->bytesAvailable();
774 if (nb > 0) {
775 QByteArray data = _serialPort->read(nb);
776 int i1 = data.indexOf("$GPGGA");
777 if (i1 == -1) {
778 i1 = data.indexOf("$GNGGA");
779 }
780 if (i1 != -1) {
781 int i2 = data.indexOf("*", i1);
782 if (i2 != -1 && data.size() > i2 + 1) {
783 QByteArray gga = data.mid(i1, i2 - i1 + 3);
784 _query->startRequest(_mountPoint, gga);
785 _lastNMEA = QDateTime::currentDateTime();
786 }
787 }
788 }
789 }
790 }
791 } else {
792 _query->startRequest(_mountPoint, "");
793 }
794
795 if (_query->status() != bncNetQuery::running) {
796 return failure;
797 }
798 }
799
800 if (_rawFile) {
801 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
802 while (itDec.hasNext()) {
803 itDec.next();
804 GPSDecoder* decoder = itDec.value();
805 decoder->setRinexReconnectFlag(false);
806 }
807 } else {
808 _decoder->setRinexReconnectFlag(false);
809 }
810
811 return success;
812}
813
814// RTCM scan output
815//////////////////////////////////////////////////////////////////////////////
816void bncGetThread::miscScanRTCM() {
817
818 if (!decoder()) {
819 return;
820 }
821
822 bncSettings settings;
823 if (Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked) {
824
825 if (_miscMount == _staID || _miscMount == "ALL") {
826 // RTCM message types
827 // ------------------
828 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
829 QString type = QString("%1 ").arg(decoder()->_typeList[ii]._type);
830 QString size = (decoder()->_typeList[ii]._size) ? QString("(size %1)").arg(decoder()->_typeList[ii]._size) : "";
831 emit(newMessage(_staID + ": Received message type " + type.toLatin1() + size.toLatin1(), true));
832 }
833
834 // Check Observation Types
835 // -----------------------
836 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
837 t_satObs& obs = decoder()->_obsList[ii];
838 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
839 bool allFound = true;
840 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
841 if (obs._obs[iFrq]->_codeValid) {
842 QString rnxStr('C');
843 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
844 if (_format.indexOf("RTCM_2") != -1
845 || _format.indexOf("RTCM2") != -1
846 || _format.indexOf("RTCM 2") != -1) {
847 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
848 }
849 if (rnxTypes.indexOf(rnxStr) == -1) {
850 rnxTypes.push_back(rnxStr);
851 allFound = false;
852 }
853 }
854 if (obs._obs[iFrq]->_phaseValid) {
855 QString rnxStr('L');
856 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
857 if (_format.indexOf("RTCM_2") != -1
858 || _format.indexOf("RTCM2") != -1
859 || _format.indexOf("RTCM 2") != -1) {
860 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
861 }
862 if (rnxTypes.indexOf(rnxStr) == -1) {
863 rnxTypes.push_back(rnxStr);
864 allFound = false;
865 }
866 }
867 if (obs._obs[iFrq]->_dopplerValid) {
868 QString rnxStr('D');
869 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
870 if (_format.indexOf("RTCM_2") != -1
871 || _format.indexOf("RTCM2") != -1
872 || _format.indexOf("RTCM 2") != -1) {
873 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
874 }
875 if (rnxTypes.indexOf(rnxStr) == -1) {
876 rnxTypes.push_back(rnxStr);
877 allFound = false;
878 }
879 }
880 if (obs._obs[iFrq]->_snrValid) {
881 QString rnxStr('S');
882 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
883 if (_format.indexOf("RTCM_2") != -1
884 || _format.indexOf("RTCM2") != -1
885 || _format.indexOf("RTCM 2") != -1) {
886 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
887 }
888 if (rnxTypes.indexOf(rnxStr) == -1) {
889 rnxTypes.push_back(rnxStr);
890 allFound = false;
891 }
892 }
893 }
894 if (!allFound) {
895 QString msg;
896 QTextStream str(&msg);
897 str << obs._prn.system() << QString(" %1 ").arg(rnxTypes.size());
898 for (int iType = 0; iType < rnxTypes.size(); iType++) {
899 str << " " << rnxTypes[iType];
900 }
901 emit(newMessage(_staID + ": Observation Types: " + msg.toLatin1(), true));
902 }
903 }
904
905 // RTCMv3 antenna descriptor
906 // -------------------------
907 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
908 QString ant1 = QString(": Antenna Descriptor: %1 ").arg(decoder()->_antType[ii]._descriptor);
909 emit(newMessage(_staID + ant1.toLatin1(), true));
910 if (strlen(decoder()->_antType[ii]._serialnumber)) {
911 QString ant2 = QString(": Antenna Serial Number: %1 ").arg(decoder()->_antType[ii]._serialnumber);
912 emit(newMessage(_staID + ant2.toLatin1(), true));
913 }
914 }
915
916 // RTCM Antenna Coordinates
917 // ------------------------
918 for (int ii = 0; ii < decoder()->_antList.size(); ii++) {
919 QByteArray antT;
920 if (decoder()->_antList[ii]._type == GPSDecoder::t_antRefPoint::ARP) {
921 antT = "ARP";
922 } else if (decoder()->_antList[ii]._type == GPSDecoder::t_antRefPoint::APC) {
923 antT = "APC";
924 }
925 QByteArray ant1, ant2, ant3;
926 ant1 = QString("%1 ").arg(decoder()->_antList[ii]._xx, 0, 'f', 4).toLatin1();
927 ant2 = QString("%1 ").arg(decoder()->_antList[ii]._yy, 0, 'f', 4).toLatin1();
928 ant3 = QString("%1 ").arg(decoder()->_antList[ii]._zz, 0, 'f', 4).toLatin1();
929 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
930 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
931 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
932 double hh = 0.0;
933 if (decoder()->_antList[ii]._height_f) {
934 hh = decoder()->_antList[ii]._height;
935 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toLatin1();
936 emit(newMessage(
937 _staID + ": Antenna height above marker " + ant4 + "m", true));
938 }
939 emit(newAntCrd(_staID, decoder()->_antList[ii]._xx,
940 decoder()->_antList[ii]._yy, decoder()->_antList[ii]._zz, hh, antT));
941 }
942
943 // RTCMv3 receiver descriptor
944 // --------------------------
945 for (int ii = 0; ii < decoder()->_recType.size(); ii++) {
946 QString rec1 = QString(": Receiver Descriptor: %1 ").arg(decoder()->_recType[ii]._descriptor);
947 QString rec2 = QString(": Receiver Firmware Version: %1 ").arg(decoder()->_recType[ii]._firmware);
948 QString rec3 = QString(": Receiver Serial Number: %1 ").arg(decoder()->_recType[ii]._serialnumber);
949 emit(newMessage(_staID + rec1.toLatin1(), true));
950 emit(newMessage(_staID + rec2.toLatin1(), true));
951 emit(newMessage(_staID + rec3.toLatin1(), true));
952 }
953
954 // RTCM GLONASS slots
955 // ------------------
956 if (decoder()->_gloFrq.size()) {
957 bool allFound = true;
958 QString slot = decoder()->_gloFrq;
959 slot.replace(" ", " ").replace(" ", ":");
960 if (_gloSlots.indexOf(slot) == -1) {
961 _gloSlots.append(slot);
962 allFound = false;
963 }
964 if (!allFound) {
965 _gloSlots.sort();
966 emit(newMessage(
967 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toLatin1(),
968 true));
969 }
970 }
971
972 // RTCM GLONASS Code-Phase biases (MT 1230)
973 // ----------------------------------------
974 if (decoder()->_gloBiasInfo.changed()) {
975 QString gloCodePhaseBiases = decoder()->_gloBiasInfo.toString();
976 emit(newMessage(_staID + gloCodePhaseBiases.toLatin1(), true));
977 decoder()->_gloBiasInfo.setChanged(false);
978 }
979
980 // Service CRS / RTCM CRS
981 // ------------------------
982 if (fmod(decoder()->corrGPSEpochTime(), 60.0) == 0.0) {
983 // Service CRS
984 for (int ii = 0; ii < decoder()->_serviceCrs.size(); ii++) {
985 QString servicecrsname = QString(": Service CRS Name: %1 ").arg(decoder()->_serviceCrs[ii]._name);
986 QString coordinateEpoch = QString(": Service CRS Coordinate Epoch: %1 ").arg(decoder()->_serviceCrs[ii]._coordinateEpoch);
987 //QString ce = QString(": CE: %1 ").arg(decoder()->_serviceCrs[ii]._CE);
988 emit(newMessage(_staID + servicecrsname.toLatin1(), true));
989 emit(newMessage(_staID + coordinateEpoch.toLatin1(), true));
990 //emit(newMessage(_staID + ce.toLatin1(), true));
991 }
992 // RTCM CRS
993 for (int ii = 0; ii < decoder()->_rtcmCrs.size(); ii++) {
994 QString rtcmcrsname = QString(": RTCM CRS Name: %1 ").arg(decoder()->_rtcmCrs[ii]._name);
995 QString anchor = QString(": RTCM CRS Anchor: %1 ").arg(decoder()->_rtcmCrs[ii]._anchor);
996 QString platenumber = QString(": RTCM CRS Plate Number: %1 ").arg(decoder()->_rtcmCrs[ii]._plateNumber);
997 emit(newMessage(_staID + rtcmcrsname.toLatin1(), true));
998 emit(newMessage(_staID + anchor.toLatin1(), true));
999 emit(newMessage(_staID + platenumber.toLatin1(), true));
1000 for (int i = 0; i<decoder()->_rtcmCrs[ii]._databaseLinks.size(); i++) {
1001 QString dblink = QString(": Database Link: %1 ").arg(decoder()->_rtcmCrs[ii]._databaseLinks[i]);
1002 emit(newMessage(_staID + dblink.toLatin1(), true));
1003 }
1004 }
1005
1006 // Helmert Parameters
1007 //-------------------
1008 for (int ii = 0; ii < decoder()->_helmertPar.size(); ii++) {
1009 t_helmertPar& helmertPar = decoder()->_helmertPar[ii];
1010 bncTime t; t.setmjd(0, helmertPar._mjd); QString dateStr = QString::fromStdString(t.datestr());
1011 QString sourcename = QString(": MT1301 Source Name: %1 ").arg(helmertPar._sourceName);
1012 QString targetname = QString(": MT1301 Target Name: %1 ").arg(helmertPar._targetName);
1013 QString sysidentnum = QString(": MT1301 Sys Ident Num: %1 ").arg(helmertPar._sysIdentNum);
1014 QString trafomessageind = QString(": MT1301 Trafo Ident Num: %1 ").arg(helmertPar.IndtoString());
1015 QString epoch = QString(": MT1301 t0: MJD %1 (%2) ").arg(helmertPar._mjd).arg(dateStr);
1016 QString partrans = QString(": MT1301 Helmert Par Trans: dx = %1, dy = %2, dz = %3, dxr = %4, dyr = %5, dzr = %6")
1017 .arg(helmertPar._dx).arg(helmertPar._dy).arg(helmertPar._dz)
1018 .arg(helmertPar._dxr).arg(helmertPar._dyr).arg(helmertPar._dzr);
1019 QString parrot = QString(": MT1301 Helmert Par Rot: ox = %1, oy = %2, oz = %3, oxr = %4, oyr = %5, ozr = %6")
1020 .arg(helmertPar._ox).arg(helmertPar._oy).arg(helmertPar._oz)
1021 .arg(helmertPar._oxr).arg(helmertPar._oyr).arg(helmertPar._ozr);
1022 QString parscale = QString(": MT1301 Helmert Par Scale: sc = %1, scr = %2").arg(helmertPar._sc).arg(helmertPar._scr);
1023 emit(newMessage(_staID + sourcename.toLatin1(), true));
1024 emit(newMessage(_staID + targetname.toLatin1(), true));
1025 emit(newMessage(_staID + sysidentnum.toLatin1(), true));
1026 emit(newMessage(_staID + trafomessageind.toLatin1(), true));
1027 emit(newMessage(_staID + epoch.toLatin1(), true));
1028 emit(newMessage(_staID + partrans.toLatin1(), true));
1029 emit(newMessage(_staID + parrot.toLatin1(), true));
1030 emit(newMessage(_staID + parscale.toLatin1(), true));
1031 }
1032 }
1033 }
1034 }
1035
1036#ifdef MLS_SOFTWARE
1037 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
1038 QByteArray antT;
1039 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
1040 antT = "ARP";
1041 }
1042 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
1043 antT = "APC";
1044 }
1045 double hh = 0.0;
1046 if (decoder()->_antList[ii].height_f) {
1047 hh = decoder()->_antList[ii].height;
1048 }
1049 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
1050 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
1051 hh, antT));
1052 }
1053
1054 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
1055 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
1056 }
1057#endif
1058
1059 decoder()->_gloFrq.clear();
1060 // decoder()->_gloBiases.clear();
1061 decoder()->_typeList.clear();
1062 decoder()->_antType.clear();
1063 decoder()->_recType.clear();
1064 decoder()->_antList.clear();
1065}
1066
1067// Handle Data from Serial Port
1068////////////////////////////////////////////////////////////////////////////
1069void bncGetThread::slotSerialReadyRead() {
1070
1071 if (_serialPort) {
1072
1073 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
1074 if (_NMEASampl) {
1075 int dt = _lastNMEA.secsTo(QDateTime::currentDateTime());
1076 if (dt && (fmod(double(dt), double(_NMEASampl)) == 0.0)) {
1077 _query->sendNMEA(_manualNMEAString);
1078 _lastNMEA = QDateTime::currentDateTime();
1079 }
1080 }
1081 }
1082
1083 int nb = _serialPort->bytesAvailable();
1084 if (nb > 0) {
1085 QByteArray data = _serialPort->read(nb);
1086
1087 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
1088 int i1 = data.indexOf("$GPGGA");
1089 if (i1 == -1) {
1090 i1 = data.indexOf("$GNGGA");
1091 }
1092 if (i1 != -1) {
1093 int i2 = data.indexOf("*", i1);
1094 if (i2 != -1 && data.size() > i2 + 1) {
1095 QByteArray gga = data.mid(i1, i2 - i1 + 3);
1096 if (_NMEASampl) {
1097 int dt = _lastNMEA.secsTo(QDateTime::currentDateTime());
1098 if (dt && (fmod(double(dt), double(_NMEASampl)) == 0.0)) {
1099 _query->sendNMEA(gga);
1100 _lastNMEA = QDateTime::currentDateTime();
1101 }
1102 }
1103 }
1104 }
1105 }
1106
1107 if (_serialOutFile) {
1108 _serialOutFile->write(data);
1109 _serialOutFile->flush();
1110 }
1111 }
1112 }
1113}
1114
1115void bncGetThread::slotNewNMEAConnection() {
1116 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
1117 emit(newMessage(
1118 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1(),
1119 true));
1120}
1121
1122//
1123////////////////////////////////////////////////////////////////////////////
1124void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
1125 if (_nmeaPortsMap.contains(staID)) {
1126 int nmeaPort = _nmeaPortsMap.value(staID);
1127 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
1128 while (is.hasNext()) {
1129 QTcpSocket* sock = is.next();
1130 if (sock->localPort() == nmeaPort) {
1131 if (sock->state() == QAbstractSocket::ConnectedState) {
1132 sock->write(str);
1133 } else if (sock->state() != QAbstractSocket::ConnectingState) {
1134 delete sock;
1135 is.remove();
1136 }
1137 }
1138 }
1139 }
1140}
Note: See TracBrowser for help on using the repository browser.