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

Last change on this file since 8260 was 8252, checked in by stoecker, 6 years ago

see #105 - reenable Qt4 build options, drop generic version dependend includes, replace by direct requirements, remaining QtCore lines should also be replaced

File size: 31.0 KB
RevLine 
[280]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[280]3//
[464]4// Copyright (C) 2007
[280]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[280]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.
[35]24
25/* -------------------------------------------------------------------------
[93]26 * BKG NTRIP Client
[35]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 *
[7486]37 * Changes:
[35]38 *
39 * -----------------------------------------------------------------------*/
40
[277]41#include <stdlib.h>
[1044]42#include <iomanip>
[1218]43#include <sstream>
[277]44
[8127]45#include <QComboBox>
46#include <QDialog>
[35]47#include <QFile>
48#include <QTextStream>
[5524]49#include <QMutex>
[8127]50#include <QPushButton>
51#include <QTableWidget>
[356]52#include <QTime>
[35]53
54#include "bncgetthread.h"
[192]55#include "bnctabledlg.h"
[5070]56#include "bnccore.h"
[352]57#include "bncutils.h"
[423]58#include "bnczerodecoder.h"
[1621]59#include "bncnetqueryv0.h"
[1387]60#include "bncnetqueryv1.h"
61#include "bncnetqueryv2.h"
[1410]62#include "bncnetqueryrtp.h"
[1721]63#include "bncnetqueryudp.h"
[1779]64#include "bncnetqueryudp0.h"
[1753]65#include "bncnetquerys.h"
[1535]66#include "bncsettings.h"
[1558]67#include "latencychecker.h"
[3168]68#include "upload/bncrtnetdecoder.h"
[243]69#include "RTCM/RTCM2Decoder.h"
[297]70#include "RTCM3/RTCM3Decoder.h"
[1318]71#include "serial/qextserialport.h"
[35]72
73using namespace std;
74
[1143]75// Constructor 1
[35]76////////////////////////////////////////////////////////////////////////////
[2519]77bncGetThread::bncGetThread(bncRawFile* rawFile) {
[1138]78
[8082]79 _rawFile = rawFile;
80 _format = rawFile->format();
81 _staID = rawFile->staID();
82 _rawOutput = false;
[2390]83 _ntripVersion = "N";
84
[1555]85 initialize();
[1138]86}
87
[1143]88// Constructor 2
89////////////////////////////////////////////////////////////////////////////
[8082]90bncGetThread::bncGetThread(const QUrl& mountPoint, const QByteArray& format,
91 const QByteArray& latitude, const QByteArray& longitude,
92 const QByteArray& nmea, const QByteArray& ntripVersion) {
93 _rawFile = 0;
94 _mountPoint = mountPoint;
[8127]95 _staID = mountPoint.path().mid(1).toLatin1();
[8082]96 _format = format;
97 _latitude = latitude;
98 _longitude = longitude;
99 _nmea = nmea;
[1353]100 _ntripVersion = ntripVersion;
[1139]101
[2386]102 bncSettings settings;
103 if (!settings.value("rawOutFile").toString().isEmpty()) {
104 _rawOutput = true;
[3734]105 } else {
106 _rawOutput = false;
[2386]107 }
108
[1139]109 initialize();
[3523]110 initDecoder();
[1139]111}
112
[1555]113// Initialization (common part of the constructor)
[1143]114////////////////////////////////////////////////////////////////////////////
[1139]115void bncGetThread::initialize() {
116
[3528]117 bncSettings settings;
118
[1555]119 setTerminationEnabled(true);
120
[7486]121 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[8082]122 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[1555]123
[1525]124 _isToBeDeleted = false;
[8082]125 _query = 0;
126 _nextSleep = 0;
127 _miscMount = settings.value("miscMount").toString();
128 _decoder = 0;
[255]129
[7180]130 // NMEA Port
131 // -----------
132 QListIterator<QString> iSta(settings.value("PPP/staTable").toStringList());
133 int nmeaPort = 0;
134 while (iSta.hasNext()) {
135 QStringList hlp = iSta.next().split(",");
[8082]136 if (hlp.size() < 10) {
137 continue;
138 }
[8127]139 QByteArray mp = hlp[0].toLatin1();
[7180]140 if (_staID == mp) {
141 nmeaPort = hlp[9].toInt();
142 }
143 }
144 if (nmeaPort != 0) {
145 _nmeaServer = new QTcpServer;
[8082]146 if (!_nmeaServer->listen(QHostAddress::Any, nmeaPort)) {
[7180]147 emit newMessage("bncCaster: Cannot listen on port", true);
[8082]148 } else {
149 connect(_nmeaServer, SIGNAL(newConnection()), this,
150 SLOT(slotNewNMEAConnection()));
151 connect(BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)), this,
152 SLOT(slotNewNMEAstr(QByteArray, QByteArray)));
[7180]153 _nmeaSockets = new QList<QTcpSocket*>;
154 _nmeaPortsMap[_staID] = nmeaPort;
155 }
156 } else {
157 _nmeaServer = 0;
158 _nmeaSockets = 0;
159 }
160
[1555]161 // Serial Port
162 // -----------
[8082]163 _serialNMEA = NO_NMEA;
[1710]164 _serialOutFile = 0;
[8082]165 _serialPort = 0;
[1710]166
[8082]167 if (!_staID.isEmpty()
168 && settings.value("serialMountPoint").toString() == _staID) {
169 _serialPort = new QextSerialPort(
170 settings.value("serialPortName").toString());
171 _serialPort->setTimeout(0, 100);
[1710]172
173 // Baud Rate
174 // ---------
[1330]175 QString hlp = settings.value("serialBaudRate").toString();
[8082]176 if (hlp == "110") {
[7486]177 _serialPort->setBaudRate(BAUD110);
[8082]178 } else if (hlp == "300") {
[7486]179 _serialPort->setBaudRate(BAUD300);
[8082]180 } else if (hlp == "600") {
[7486]181 _serialPort->setBaudRate(BAUD600);
[8082]182 } else if (hlp == "1200") {
[7486]183 _serialPort->setBaudRate(BAUD1200);
[8082]184 } else if (hlp == "2400") {
[7486]185 _serialPort->setBaudRate(BAUD2400);
[8082]186 } else if (hlp == "4800") {
[7486]187 _serialPort->setBaudRate(BAUD4800);
[8082]188 } else if (hlp == "9600") {
[7486]189 _serialPort->setBaudRate(BAUD9600);
[8082]190 } else if (hlp == "19200") {
[7486]191 _serialPort->setBaudRate(BAUD19200);
[8082]192 } else if (hlp == "38400") {
[7486]193 _serialPort->setBaudRate(BAUD38400);
[8082]194 } else if (hlp == "57600") {
[7486]195 _serialPort->setBaudRate(BAUD57600);
[8082]196 } else if (hlp == "115200") {
[7486]197 _serialPort->setBaudRate(BAUD115200);
[1330]198 }
[1710]199
200 // Parity
201 // ------
[1330]202 hlp = settings.value("serialParity").toString();
[8082]203 if (hlp == "NONE") {
[7486]204 _serialPort->setParity(PAR_NONE);
[8082]205 } else if (hlp == "ODD") {
[7486]206 _serialPort->setParity(PAR_ODD);
[8082]207 } else if (hlp == "EVEN") {
[7486]208 _serialPort->setParity(PAR_EVEN);
[8082]209 } else if (hlp == "SPACE") {
[7486]210 _serialPort->setParity(PAR_SPACE);
[1330]211 }
[1710]212
213 // Data Bits
214 // ---------
[1330]215 hlp = settings.value("serialDataBits").toString();
[8082]216 if (hlp == "5") {
[7486]217 _serialPort->setDataBits(DATA_5);
[8082]218 } else if (hlp == "6") {
[7486]219 _serialPort->setDataBits(DATA_6);
[8082]220 } else if (hlp == "7") {
[7486]221 _serialPort->setDataBits(DATA_7);
[8082]222 } else if (hlp == "8") {
[7486]223 _serialPort->setDataBits(DATA_8);
[1330]224 }
225 hlp = settings.value("serialStopBits").toString();
[8082]226 if (hlp == "1") {
[7486]227 _serialPort->setStopBits(STOP_1);
[8082]228 } else if (hlp == "2") {
[7486]229 _serialPort->setStopBits(STOP_2);
[1330]230 }
[1710]231
232 // Flow Control
233 // ------------
234 hlp = settings.value("serialFlowControl").toString();
[1711]235 if (hlp == "XONXOFF") {
[7486]236 _serialPort->setFlowControl(FLOW_XONXOFF);
[8082]237 } else if (hlp == "HARDWARE") {
[7486]238 _serialPort->setFlowControl(FLOW_HARDWARE);
[8082]239 } else {
[7486]240 _serialPort->setFlowControl(FLOW_OFF);
[1711]241 }
[1710]242
243 // Open Serial Port
244 // ----------------
[8082]245 _serialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
[1331]246 if (!_serialPort->isOpen()) {
247 delete _serialPort;
248 _serialPort = 0;
[1451]249 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
[1331]250 }
[8082]251 connect(_serialPort, SIGNAL(readyRead()), this,
252 SLOT(slotSerialReadyRead()));
[1606]253
[1710]254 // Automatic NMEA
255 // --------------
[6785]256 QString nmeaMode = settings.value("serialAutoNMEA").toString();
257 if (nmeaMode == "Auto") {
[1710]258 _serialNMEA = AUTO_NMEA;
259 QString fName = settings.value("serialFileNMEA").toString();
260 if (!fName.isEmpty()) {
261 _serialOutFile = new QFile(fName);
[8082]262 if (Qt::CheckState(settings.value("rnxAppend").toInt())
263 == Qt::Checked) {
[1710]264 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
[8082]265 } else {
[1710]266 _serialOutFile->open(QIODevice::WriteOnly);
267 }
[1634]268 }
[1606]269 }
[1710]270 // Manual NMEA
271 // -----------
[8082]272 if ((nmeaMode == "Manual GPGGA") || (nmeaMode == "Manual GNGGA")) {
[1710]273 _serialNMEA = MANUAL_NMEA;
[6751]274 bncSettings settings;
275 _manualNMEASampl = settings.value("serialManualNMEASampling").toInt();
[8082]276 QString hlp = settings.value("serialHeightNMEA").toString();
[6751]277 if (hlp.isEmpty()) {
278 hlp = "0.0";
279 }
[8127]280 QByteArray _serialHeightNMEA = hlp.toLatin1();
[8082]281 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA,
282 nmeaMode);
[1636]283 }
[1318]284 }
285
[3532]286 if (!_staID.isEmpty()) {
287 _latencyChecker = new latencyChecker(_staID);
[8082]288 obs = false;
289 ssrOrb = false;
290 ssrClk = false;
291 ssrOrbClk = false;
292 ssrCbi = false;
293 ssrPbi = false;
294 ssrVtec = false;
295 ssrUra = false;
296 ssrHr = false;
297 _oldSsrEpoch = 0;
298 _ssrEpoch = 0;
299 } else {
[3532]300 _latencyChecker = 0;
301 }
[3523]302}
303
304// Instantiate the decoder
305//////////////////////////////////////////////////////////////////////////////
306t_irc bncGetThread::initDecoder() {
307
[3560]308 _decoder = 0;
309
[8082]310 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1
311 || _format.indexOf("RTCM 2") != -1) {
[1555]312 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
[3560]313 _decoder = new RTCM2Decoder(_staID.data());
[8082]314 } else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1
315 || _format.indexOf("RTCM 3") != -1) {
[1555]316 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
[3558]317 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
[3560]318 _decoder = newDecoder;
[7486]319 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
[8082]320 this, SIGNAL(newMessage(QByteArray,bool)));
321 } else if (_format.indexOf("ZERO") != -1) {
[1555]322 emit(newMessage(_staID + ": Get data in original format", true));
[3560]323 _decoder = new bncZeroDecoder(_staID);
[8082]324 } else if (_format.indexOf("RTNET") != -1) {
[3168]325 emit(newMessage(_staID + ": Get data in RTNet format", true));
[3560]326 _decoder = new bncRtnetDecoder();
[8082]327 } else {
[1555]328 emit(newMessage(_staID + ": Unknown data format " + _format, true));
329 _isToBeDeleted = true;
[3523]330 return failure;
[1555]331 }
332
[319]333 msleep(100); //sleep 0.1 sec
[7486]334
[8082]335 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
336 _ntripVersion);
[3560]337
338 if (_rawFile) {
339 _decodersRaw[_staID] = _decoder;
[3530]340 }
341
[3523]342 return success;
[35]343}
344
[3523]345// Current decoder in use
346////////////////////////////////////////////////////////////////////////////
347GPSDecoder* bncGetThread::decoder() {
[3560]348 if (!_rawFile) {
349 return _decoder;
[8082]350 } else {
[3560]351 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
352 return _decodersRaw[_staID];
353 }
[3523]354 }
[3560]355 return 0;
[3523]356}
357
[35]358// Destructor
359////////////////////////////////////////////////////////////////////////////
360bncGetThread::~bncGetThread() {
[1928]361 if (isRunning()) {
362 wait();
363 }
[1527]364 if (_query) {
365 _query->stop();
[1708]366 _query->deleteLater();
[1527]367 }
[3560]368 if (_rawFile) {
369 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
370 while (it.hasNext()) {
371 it.next();
372 delete it.value();
373 }
[8082]374 } else {
[3560]375 delete _decoder;
376 }
[2519]377 delete _rawFile;
[1607]378 delete _serialOutFile;
[1328]379 delete _serialPort;
[1557]380 delete _latencyChecker;
[1556]381 emit getThreadFinished(_staID);
[35]382}
383
[7486]384//
[1390]385////////////////////////////////////////////////////////////////////////////
386void bncGetThread::terminate() {
[1525]387 _isToBeDeleted = true;
[7854]388
[8082]389 if (_nmeaPortsMap.contains(_staID)) {
[7854]390 _nmeaPortsMap.remove(_staID);
[1559]391 }
[7854]392 if (_nmeaServer) {
393 delete _nmeaServer;
394 }
395 if (_nmeaSockets) {
396 delete _nmeaSockets;
397 }
[7858]398
399#ifdef BNC_DEBUG
[7859]400 if (BNC_CORE->mode() != t_bncCore::interactive) {
[8082]401 while (!isFinished()) {
402 wait();
403 }
[7859]404 delete this;
[8082]405 } else {
406 if (!isRunning()) {
407 delete this;
408 }
[7858]409 }
410#else
[8082]411 if (!isRunning()) {delete this;}
[7858]412#endif
413
[1390]414}
415
[136]416// Run
417////////////////////////////////////////////////////////////////////////////
418void bncGetThread::run() {
419
[35]420 while (true) {
[629]421 try {
[1555]422 if (_isToBeDeleted) {
423 QThread::exit(0);
424 this->deleteLater();
425 return;
[629]426 }
[621]427
[1555]428 if (tryReconnect() != success) {
[3532]429 if (_latencyChecker) {
430 _latencyChecker->checkReconnect();
431 }
[1555]432 continue;
[621]433 }
[1555]434
435 // Delete old observations
436 // -----------------------
[3560]437 if (_rawFile) {
438 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
439 while (itDec.hasNext()) {
440 itDec.next();
441 GPSDecoder* decoder = itDec.value();
442 decoder->_obsList.clear();
443 }
[8082]444 } else {
[3560]445 _decoder->_obsList.clear();
446 }
[621]447
[1555]448 // Read Data
449 // ---------
[1377]450 QByteArray data;
[8082]451 if (_query) {
[1377]452 _query->waitForReadyRead(data);
[8082]453 } else if (_rawFile) {
[2527]454 data = _rawFile->readChunk();
[3523]455 _format = _rawFile->format();
[8082]456 _staID = _rawFile->staID();
[2388]457
[5903]458 QCoreApplication::processEvents();
459
[7976]460 if (data.isEmpty() || BNC_CORE->sigintReceived) {
461 cout << "no more data or Ctrl-C received" << endl;
[5068]462 BNC_CORE->stopCombination();
[5900]463 BNC_CORE->stopPPP();
[5903]464 ::exit(0);
[1555]465 }
[1138]466 }
[8123]467
[1555]468 qint64 nBytes = data.size();
[1138]469
[1555]470 // Timeout, reconnect
471 // ------------------
472 if (nBytes == 0) {
[3532]473 if (_latencyChecker) {
474 _latencyChecker->checkReconnect();
475 }
[1555]476 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
[2355]477 msleep(10000); //sleep 10 sec, G. Weber
[1555]478 continue;
[8082]479 } else {
[567]480 emit newBytes(_staID, nBytes);
[5648]481 emit newRawData(_staID, data);
[1555]482 }
[567]483
[1555]484 // Output Data
485 // -----------
[2386]486 if (_rawOutput) {
[7486]487 BNC_CORE->writeRawData(data, _staID, _format);
[2386]488 }
[2385]489
[1555]490 if (_serialPort) {
[1633]491 slotSerialReadyRead();
[1555]492 _serialPort->write(data);
493 }
[7486]494
[1555]495 // Decode Data
496 // -----------
497 vector<string> errmsg;
[3526]498 if (!decoder()) {
499 _isToBeDeleted = true;
500 continue;
501 }
[7753]502
[3523]503 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
[1137]504
[7753]505 if (irc != success) {
506 continue;
507 }
[1555]508 // Perform various scans and checks
509 // --------------------------------
[3532]510 if (_latencyChecker) {
511 _latencyChecker->checkOutage(irc == success);
[8082]512 QListIterator<int> it(decoder()->_typeList);
513 _ssrEpoch = decoder()->corrGPSEpochTime();
[8246]514 if (_oldSsrEpoch && _ssrEpoch && _ssrEpoch != _oldSsrEpoch) {
[8082]515 if (ssrOrb) {
516 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1057);
517 ssrOrb = false;
518 }
519 if (ssrClk) {
520 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1058);
521 ssrClk = false;
522 }
523 if (ssrOrbClk) {
524 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1060);
525 ssrOrbClk = false;
526 }
527 if (ssrCbi) {
528 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1059);
529 ssrCbi = false;
530 }
531 if (ssrPbi) {
532 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1265);
533 ssrPbi = false;
534 }
535 if (ssrVtec) {
536 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1264);
537 ssrVtec = false;
538 }
539 if (ssrUra) {
540 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1061);
541 ssrUra = false;
542 }
543 if (ssrHr) {
544 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1062);
545 ssrHr = false;
546 }
547 }
548 while (it.hasNext()) {
549 int rtcmType = it.next();
550 if ((rtcmType >= 1001 && rtcmType <= 1004) || // legacy RTCM OBS
551 (rtcmType >= 1009 && rtcmType <= 1012) || // legacy RTCM OBS
552 (rtcmType >= 1071 && rtcmType <= 1127)) { // MSM RTCM OBS
553 obs = true;
554 } else if ((rtcmType >= 1057 && rtcmType <= 1068) ||
555 (rtcmType >= 1240 && rtcmType <= 1270)) {
556 switch (rtcmType) {
557 case 1057: case 1063: case 1240: case 1246: case 1252: case 1258:
558 ssrOrb = true;
559 break;
560 case 1058: case 1064: case 1241: case 1247: case 1253: case 1259:
561 ssrClk = true;
562 break;
563 case 1060: case 1066: case 1243: case 1249: case 1255: case 1261:
564 ssrOrbClk = true;
565 break;
566 case 1059: case 1065: case 1242: case 1248: case 1254: case 1260:
567 ssrCbi = true;
568 break;
569 case 1265: case 1266: case 1267: case 1268: case 1269: case 1270:
570 ssrPbi = true;
571 break;
572 case 1264:
573 ssrVtec = true;
574 break;
575 case 1061: case 1067: case 1244: case 1250: case 1256: case 1262:
576 ssrUra = true;
577 break;
578 case 1062: case 1068: case 1245: case 1251: case 1257: case 1263:
579 ssrHr = true;
580 break;
581 }
582 }
583 }
584 if (obs) {
585 _latencyChecker->checkObsLatency(decoder()->_obsList);
586 }
587 _oldSsrEpoch = _ssrEpoch;
[3532]588 emit newLatency(_staID, _latencyChecker->currentLatency());
589 }
[7753]590 miscScanRTCM();
[1138]591
[1555]592 // Loop over all observations (observations output)
593 // ------------------------------------------------
[6137]594 QListIterator<t_satObs> it(decoder()->_obsList);
[5524]595
[6137]596 QList<t_satObs> obsListHlp;
[5524]597
[1555]598 while (it.hasNext()) {
[6137]599 const t_satObs& obs = it.next();
[2711]600
[1555]601 // Check observation epoch
602 // -----------------------
[5739]603 if (!_rawFile) {
[8011]604 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
605 if (wrongObservationEpoch) {
[8021]606 QString prn(obs._prn.toString().c_str());
[8082]607 emit(newMessage(
[8127]608 _staID + " (" + prn.toLatin1() + ")"
[8082]609 + ": Wrong observation epoch(s)", false));
[1555]610 continue;
[940]611 }
[686]612 }
[6812]613
[3305]614 // Check observations coming twice (e.g. KOUR0 Problem)
615 // ----------------------------------------------------
[3535]616 if (!_rawFile) {
[8011]617 QString prn(obs._prn.toString().c_str());
[8082]618 long iSec = long(floor(obs._time.gpssec() + 0.5));
619 long obsTime = obs._time.gpsw() * 7 * 24 * 3600 + iSec;
[3535]620 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
621 if (it != _prnLastEpo.end()) {
622 long oldTime = it.value();
[8082]623 if (obsTime < oldTime) {
[8127]624 emit(newMessage(_staID + ": old observation " + prn.toLatin1(),
[8082]625 false));
[3535]626 continue;
[8082]627 } else if (obsTime == oldTime) {
628 emit(newMessage(
629 _staID + ": observation coming more than once "
[8127]630 + prn.toLatin1(), false));
[3535]631 continue;
632 }
[3302]633 }
[3535]634 _prnLastEpo[prn] = obsTime;
[3301]635 }
636
[3528]637 decoder()->dumpRinexEpoch(obs, _format);
638
[5524]639 // Save observations
640 // -----------------
641 obsListHlp.append(obs);
642 }
[2030]643
[5524]644 // Emit signal
645 // -----------
646 if (!_isToBeDeleted && obsListHlp.size() > 0) {
647 emit newObs(_staID, obsListHlp);
[249]648 }
[5524]649
[8082]650 } catch (Exception& exc) {
[3311]651 emit(newMessage(_staID + " " + exc.what(), true));
652 _isToBeDeleted = true;
[8082]653 } catch (...) {
[3311]654 emit(newMessage(_staID + " bncGetThread exception", true));
[1559]655 _isToBeDeleted = true;
[1555]656 }
[35]657 }
658}
659
[7486]660// Try Re-Connect
[136]661////////////////////////////////////////////////////////////////////////////
[1555]662t_irc bncGetThread::tryReconnect() {
663
664 // Easy Return
665 // -----------
666 if (_query && _query->status() == bncNetQuery::running) {
667 _nextSleep = 0;
[3560]668 if (_rawFile) {
669 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
670 while (itDec.hasNext()) {
671 itDec.next();
672 GPSDecoder* decoder = itDec.value();
673 decoder->setRinexReconnectFlag(false);
674 }
[8082]675 } else {
[3560]676 _decoder->setRinexReconnectFlag(false);
677 }
[1555]678 return success;
[408]679 }
[1555]680
681 // Start a new query
682 // -----------------
[2519]683 if (!_rawFile) {
[1555]684
[138]685 sleep(_nextSleep);
[1555]686 if (_nextSleep == 0) {
687 _nextSleep = 1;
[8082]688 } else {
[1555]689 _nextSleep = 2 * _nextSleep;
[442]690 if (_nextSleep > 256) {
691 _nextSleep = 256;
[152]692 }
[1816]693#ifdef MLS_SOFTWARE
[1817]694 if (_nextSleep > 4) {
695 _nextSleep = 4;
[1816]696 }
697#endif
[138]698 }
[8123]699 delete _query;
[8082]700 if (_ntripVersion == "U") {
[1721]701 _query = new bncNetQueryUdp();
[8082]702 } else if (_ntripVersion == "R") {
[1555]703 _query = new bncNetQueryRtp();
[8082]704 } else if (_ntripVersion == "S") {
[1753]705 _query = new bncNetQueryS();
[8082]706 } else if (_ntripVersion == "N") {
[1621]707 _query = new bncNetQueryV0();
[8082]708 } else if (_ntripVersion == "UN") {
[1779]709 _query = new bncNetQueryUdp0();
[8082]710 } else if (_ntripVersion == "2") {
[3337]711 _query = new bncNetQueryV2(false);
[8082]712 } else if (_ntripVersion == "2s") {
[3337]713 _query = new bncNetQueryV2(true);
[8082]714 } else {
[1555]715 _query = new bncNetQueryV1();
716 }
[6770]717 if (_nmea == "yes") {
718 if (_serialNMEA == MANUAL_NMEA) {
719 _query->startRequest(_mountPoint, _manualNMEAString);
720 _lastManualNMEA = QDateTime::currentDateTime();
[8082]721 } else if (_serialNMEA == AUTO_NMEA) {
[6770]722 if (_serialPort) {
723 int nb = _serialPort->bytesAvailable();
724 if (nb > 0) {
725 QByteArray data = _serialPort->read(nb);
726 int i1 = data.indexOf("$GPGGA");
727 if (i1 == -1) {
728 i1 = data.indexOf("$GNGGA");
729 }
730 if (i1 != -1) {
731 int i2 = data.indexOf("*", i1);
732 if (i2 != -1 && data.size() > i2 + 1) {
733 QByteArray gga = data.mid(i1, i2 - i1 + 3);
734 _query->startRequest(_mountPoint, gga);
735 }
736 }
737 }
738 }
739 }
[8082]740 } else {
[1555]741 _query->startRequest(_mountPoint, "");
742 }
[6770]743
[1555]744 if (_query->status() != bncNetQuery::running) {
745 return failure;
746 }
[138]747 }
[658]748
[3560]749 if (_rawFile) {
750 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
751 while (itDec.hasNext()) {
752 itDec.next();
753 GPSDecoder* decoder = itDec.value();
754 decoder->setRinexReconnectFlag(false);
755 }
[8082]756 } else {
757 _decoder->setRinexReconnectFlag(false);
[658]758 }
[1555]759
760 return success;
[658]761}
[1044]762
[1555]763// RTCM scan output
[1044]764//////////////////////////////////////////////////////////////////////////////
[7423]765void bncGetThread::miscScanRTCM() {
[1044]766
[8082]767 if (!decoder()) {
[3558]768 return;
769 }
770
[1555]771 bncSettings settings;
[8082]772 if (Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked) {
[1574]773
[8082]774 if (_miscMount == _staID || _miscMount == "ALL") {
[1575]775 // RTCM message types
776 // ------------------
[4476]777 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
[8082]778 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
[8127]779 emit(newMessage(_staID + ": Received message type " + type.toLatin1(),
[8082]780 true));
[1574]781 }
[7486]782
[4476]783 // Check Observation Types
784 // -----------------------
785 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
[6137]786 t_satObs& obs = decoder()->_obsList[ii];
787 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
[4476]788 bool allFound = true;
[6137]789 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
[6579]790 if (obs._obs[iFrq]->_codeValid) {
791 QString rnxStr('C');
792 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[8082]793 if (_format.indexOf("RTCM_2") != -1
794 || _format.indexOf("RTCM2") != -1
795 || _format.indexOf("RTCM 2") != -1) {
[6580]796 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
797 }
[6579]798 if (rnxTypes.indexOf(rnxStr) == -1) {
799 rnxTypes.push_back(rnxStr);
800 allFound = false;
801 }
[4476]802 }
[6579]803 if (obs._obs[iFrq]->_phaseValid) {
804 QString rnxStr('L');
805 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[8082]806 if (_format.indexOf("RTCM_2") != -1
807 || _format.indexOf("RTCM2") != -1
808 || _format.indexOf("RTCM 2") != -1) {
[6580]809 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
810 }
[6579]811 if (rnxTypes.indexOf(rnxStr) == -1) {
812 rnxTypes.push_back(rnxStr);
813 allFound = false;
814 }
815 }
[8082]816 if (obs._obs[iFrq]->_dopplerValid) {
[6579]817 QString rnxStr('D');
818 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[8082]819 if (_format.indexOf("RTCM_2") != -1
820 || _format.indexOf("RTCM2") != -1
821 || _format.indexOf("RTCM 2") != -1) {
[6580]822 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
823 }
[6579]824 if (rnxTypes.indexOf(rnxStr) == -1) {
825 rnxTypes.push_back(rnxStr);
826 allFound = false;
827 }
828 }
[8082]829 if (obs._obs[iFrq]->_snrValid) {
[6579]830 QString rnxStr('S');
831 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[8082]832 if (_format.indexOf("RTCM_2") != -1
833 || _format.indexOf("RTCM2") != -1
834 || _format.indexOf("RTCM 2") != -1) {
[6580]835 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
836 }
[6579]837 if (rnxTypes.indexOf(rnxStr) == -1) {
838 rnxTypes.push_back(rnxStr);
839 allFound = false;
840 }
841 }
[4476]842 }
843 if (!allFound) {
[7486]844 QString msg;
[4477]845 QTextStream str(&msg);
[6579]846 QString s;
[8082]847 str << obs._prn.system() << " "
848 << s.sprintf("%2d", rnxTypes.size()) << " ";
[4476]849 for (int iType = 0; iType < rnxTypes.size(); iType++) {
[4478]850 str << " " << rnxTypes[iType];
[4476]851 }
[8127]852 emit(newMessage(_staID + ": Observation Types: " + msg.toLatin1(),
[8082]853 true));
[4476]854 }
855 }
856
[1574]857 // RTCMv3 antenna descriptor
858 // -------------------------
[4476]859 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
[8236]860 QString ant1 = QString(": Antenna Descriptor: %1 ").arg(decoder()->_antType[ii].descriptor);
861 emit(newMessage(_staID + ant1.toLatin1(), true));
862 if (strlen(decoder()->_antType[ii].serialnumber)) {
863 QString ant2 = QString(": Antenna Serial Number: %1 ").arg(decoder()->_antType[ii].serialnumber);
864 emit(newMessage(_staID + ant2.toLatin1(), true));
865 }
[1574]866 }
[1555]867
[1575]868 // RTCM Antenna Coordinates
869 // ------------------------
[8082]870 for (int ii = 0; ii < decoder()->_antList.size(); ii++) {
[1574]871 QByteArray antT;
[8236]872 if (decoder()->_antList[ii].type == GPSDecoder::t_antRefPoint::ARP) {
[1574]873 antT = "ARP";
[8236]874 } else if (decoder()->_antList[ii].type == GPSDecoder::t_antRefPoint::APC) {
[1574]875 antT = "APC";
876 }
[1575]877 QByteArray ant1, ant2, ant3;
[8236]878 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).toLatin1();
879 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).toLatin1();
880 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).toLatin1();
[1575]881 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
882 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
883 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
[3595]884 double hh = 0.0;
[3523]885 if (decoder()->_antList[ii].height_f) {
[3595]886 hh = decoder()->_antList[ii].height;
[8127]887 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toLatin1();
[8082]888 emit(newMessage(
889 _staID + ": Antenna height above marker " + ant4 + "m", true));
[1575]890 }
[7486]891 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
[8082]892 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, hh, antT));
[1218]893 }
[6864]894
[8197]895 // RTCMv3 receiver descriptor
896 // --------------------------
897 for (int ii = 0; ii < decoder()->_recType.size(); ii++) {
[8236]898 QString rec1 = QString(": Receiver Descriptor: %1 ").arg(decoder()->_recType[ii].descriptor);
899 QString rec2 = QString(": Receiver Firmware Version: %1 ").arg(decoder()->_recType[ii].firmware);
900 QString rec3 = QString(": Receiver Serial Number: %1 ").arg(decoder()->_recType[ii].serialnumber);
901 emit(newMessage(_staID + rec1.toLatin1(), true));
902 emit(newMessage(_staID + rec2.toLatin1(), true));
903 emit(newMessage(_staID + rec3.toLatin1(), true));
[8197]904 }
905
[6864]906 // RTCM GLONASS slots
907 // ------------------
908 if (decoder()->_gloFrq.size()) {
909 bool allFound = true;
910 QString slot = decoder()->_gloFrq;
[8082]911 slot.replace(" ", " ").replace(" ", ":");
[6864]912 if (_gloSlots.indexOf(slot) == -1) {
913 _gloSlots.append(slot);
914 allFound = false;
915 }
916 if (!allFound) {
917 _gloSlots.sort();
[8082]918 emit(newMessage(
[8127]919 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toLatin1(),
[8082]920 true));
[6864]921 }
922 }
[1218]923 }
[1044]924 }
[1575]925
[1770]926#ifdef MLS_SOFTWARE
[3523]927 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
[8082]928 QByteArray antT;
929 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
930 antT = "ARP";
931 }
932 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
933 antT = "APC";
934 }
935 double hh = 0.0;
936 if (decoder()->_antList[ii].height_f) {
937 hh = decoder()->_antList[ii].height;
938 }
939 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
940 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
941 hh, antT));
[1770]942 }
[2356]943
[3523]944 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
945 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
[2356]946 }
[1770]947#endif
948
[6864]949 decoder()->_gloFrq.clear();
[3523]950 decoder()->_typeList.clear();
951 decoder()->_antType.clear();
[8197]952 decoder()->_recType.clear();
[3523]953 decoder()->_antList.clear();
[1044]954}
[1555]955
[1606]956// Handle Data from Serial Port
957////////////////////////////////////////////////////////////////////////////
958void bncGetThread::slotSerialReadyRead() {
[6770]959
[1607]960 if (_serialPort) {
[6770]961
[6773]962 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
963 if (_manualNMEASampl) {
964 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
965 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
966 _query->sendNMEA(_manualNMEAString);
967 _lastManualNMEA = QDateTime::currentDateTime();
968 }
969 }
970 }
971
[1633]972 int nb = _serialPort->bytesAvailable();
973 if (nb > 0) {
974 QByteArray data = _serialPort->read(nb);
[1711]975
[6695]976 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
[1725]977 int i1 = data.indexOf("$GPGGA");
[6651]978 if (i1 == -1) {
979 i1 = data.indexOf("$GNGGA");
980 }
[1725]981 if (i1 != -1) {
[6751]982 int i2 = data.indexOf("*", i1);
[1725]983 if (i2 != -1 && data.size() > i2 + 1) {
[6751]984 QByteArray gga = data.mid(i1, i2 - i1 + 3);
[1725]985 _query->sendNMEA(gga);
[6751]986 }
987 }
[1711]988 }
989
[1633]990 if (_serialOutFile) {
991 _serialOutFile->write(data);
992 _serialOutFile->flush();
993 }
[1607]994 }
995 }
[1606]996}
[7180]997
998void bncGetThread::slotNewNMEAConnection() {
999 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
[8082]1000 emit(newMessage(
[8127]1001 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1(),
[8082]1002 true));
[7180]1003}
1004
1005//
1006////////////////////////////////////////////////////////////////////////////
1007void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
1008 if (_nmeaPortsMap.contains(staID)) {
1009 int nmeaPort = _nmeaPortsMap.value(staID);
1010 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
1011 while (is.hasNext()) {
1012 QTcpSocket* sock = is.next();
1013 if (sock->localPort() == nmeaPort) {
1014 if (sock->state() == QAbstractSocket::ConnectedState) {
1015 sock->write(str);
[8082]1016 } else if (sock->state() != QAbstractSocket::ConnectingState) {
[7180]1017 delete sock;
1018 is.remove();
1019 }
1020 }
1021 }
1022 }
1023}
Note: See TracBrowser for help on using the repository browser.