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

Last change on this file since 8919 was 8919, checked in by stuerze, 4 years ago

port error messages extended

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