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

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

minor changes with respect to latencychecker

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