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

Last change on this file was 10423, checked in by stuerze, 3 weeks ago

minor changes

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