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

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

receiver type extraction from 1033 RTCM3 messages is added

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