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

Last change on this file since 8846 was 8781, checked in by stuerze, 5 years ago

minor changes

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