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

Last change on this file since 10541 was 10539, checked in by stuerze, 8 weeks ago

minor changes

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