source: ntrip/branches/BNC_2.12/src/bncgetthread.cpp@ 8273

Last change on this file since 8273 was 8273, checked in by stuerze, 6 years ago

a small bug regarding latency checker should be solved now

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