[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 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[277] | 41 | #include <stdlib.h>
|
---|
[1044] | 42 | #include <iomanip>
|
---|
[1218] | 43 | #include <sstream>
|
---|
[277] | 44 |
|
---|
[35] | 45 | #include <QFile>
|
---|
| 46 | #include <QTextStream>
|
---|
[5524] | 47 | #include <QMutex>
|
---|
[35] | 48 | #include <QtNetwork>
|
---|
[356] | 49 | #include <QTime>
|
---|
[35] | 50 |
|
---|
| 51 | #include "bncgetthread.h"
|
---|
[192] | 52 | #include "bnctabledlg.h"
|
---|
[5070] | 53 | #include "bnccore.h"
|
---|
[352] | 54 | #include "bncutils.h"
|
---|
[423] | 55 | #include "bnczerodecoder.h"
|
---|
[1621] | 56 | #include "bncnetqueryv0.h"
|
---|
[1387] | 57 | #include "bncnetqueryv1.h"
|
---|
| 58 | #include "bncnetqueryv2.h"
|
---|
[1410] | 59 | #include "bncnetqueryrtp.h"
|
---|
[1721] | 60 | #include "bncnetqueryudp.h"
|
---|
[1779] | 61 | #include "bncnetqueryudp0.h"
|
---|
[1753] | 62 | #include "bncnetquerys.h"
|
---|
[1535] | 63 | #include "bncsettings.h"
|
---|
[1558] | 64 | #include "latencychecker.h"
|
---|
[2035] | 65 | #include "bncpppclient.h"
|
---|
[3168] | 66 | #include "upload/bncrtnetdecoder.h"
|
---|
[243] | 67 | #include "RTCM/RTCM2Decoder.h"
|
---|
[297] | 68 | #include "RTCM3/RTCM3Decoder.h"
|
---|
[1310] | 69 | #include "GPSS/gpssDecoder.h"
|
---|
[3504] | 70 | #include "GPSS/hassDecoder.h"
|
---|
[1318] | 71 | #include "serial/qextserialport.h"
|
---|
[35] | 72 |
|
---|
| 73 | using namespace std;
|
---|
| 74 |
|
---|
[1143] | 75 | // Constructor 1
|
---|
[35] | 76 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2519] | 77 | bncGetThread::bncGetThread(bncRawFile* rawFile) {
|
---|
[1138] | 78 |
|
---|
[2519] | 79 | _rawFile = rawFile;
|
---|
| 80 | _format = rawFile->format();
|
---|
[3548] | 81 | _staID = rawFile->staID();
|
---|
[2519] | 82 | _rawOutput = false;
|
---|
[2390] | 83 | _ntripVersion = "N";
|
---|
| 84 |
|
---|
[1555] | 85 | initialize();
|
---|
[1138] | 86 | }
|
---|
| 87 |
|
---|
[1143] | 88 | // Constructor 2
|
---|
| 89 | ////////////////////////////////////////////////////////////////////////////
|
---|
[278] | 90 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
---|
[366] | 91 | const QByteArray& format,
|
---|
| 92 | const QByteArray& latitude,
|
---|
| 93 | const QByteArray& longitude,
|
---|
[1353] | 94 | const QByteArray& nmea,
|
---|
[3527] | 95 | const QByteArray& ntripVersion) {
|
---|
[2519] | 96 | _rawFile = 0;
|
---|
[1555] | 97 | _mountPoint = mountPoint;
|
---|
[3003] | 98 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
[1555] | 99 | _format = format;
|
---|
| 100 | _latitude = latitude;
|
---|
| 101 | _longitude = longitude;
|
---|
| 102 | _nmea = nmea;
|
---|
[1353] | 103 | _ntripVersion = ntripVersion;
|
---|
[1139] | 104 |
|
---|
[2386] | 105 | bncSettings settings;
|
---|
| 106 | if (!settings.value("rawOutFile").toString().isEmpty()) {
|
---|
| 107 | _rawOutput = true;
|
---|
[3734] | 108 | } else {
|
---|
| 109 | _rawOutput = false;
|
---|
[2386] | 110 | }
|
---|
| 111 |
|
---|
[1139] | 112 | initialize();
|
---|
[3523] | 113 | initDecoder();
|
---|
[1139] | 114 | }
|
---|
| 115 |
|
---|
[1555] | 116 | // Initialization (common part of the constructor)
|
---|
[1143] | 117 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1139] | 118 | void bncGetThread::initialize() {
|
---|
| 119 |
|
---|
[3528] | 120 | bncSettings settings;
|
---|
| 121 |
|
---|
[1555] | 122 | setTerminationEnabled(true);
|
---|
| 123 |
|
---|
| 124 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
[5068] | 125 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
[1555] | 126 |
|
---|
[1525] | 127 | _isToBeDeleted = false;
|
---|
[1555] | 128 | _query = 0;
|
---|
| 129 | _nextSleep = 0;
|
---|
[2035] | 130 | _PPPclient = 0;
|
---|
[3528] | 131 | _miscMount = settings.value("miscMount").toString();
|
---|
[3560] | 132 | _decoder = 0;
|
---|
[255] | 133 |
|
---|
[1555] | 134 | // Serial Port
|
---|
| 135 | // -----------
|
---|
[1710] | 136 | _serialNMEA = NO_NMEA;
|
---|
| 137 | _serialOutFile = 0;
|
---|
| 138 | _serialPort = 0;
|
---|
| 139 |
|
---|
[3532] | 140 | if (!_staID.isEmpty() &&
|
---|
| 141 | settings.value("serialMountPoint").toString() == _staID) {
|
---|
[1710] | 142 | _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
|
---|
| 143 | _serialPort->setTimeout(0,100);
|
---|
| 144 |
|
---|
| 145 | // Baud Rate
|
---|
| 146 | // ---------
|
---|
[1330] | 147 | QString hlp = settings.value("serialBaudRate").toString();
|
---|
| 148 | if (hlp == "110") {
|
---|
| 149 | _serialPort->setBaudRate(BAUD110);
|
---|
| 150 | }
|
---|
| 151 | else if (hlp == "300") {
|
---|
| 152 | _serialPort->setBaudRate(BAUD300);
|
---|
| 153 | }
|
---|
| 154 | else if (hlp == "600") {
|
---|
| 155 | _serialPort->setBaudRate(BAUD600);
|
---|
| 156 | }
|
---|
| 157 | else if (hlp == "1200") {
|
---|
| 158 | _serialPort->setBaudRate(BAUD1200);
|
---|
| 159 | }
|
---|
| 160 | else if (hlp == "2400") {
|
---|
| 161 | _serialPort->setBaudRate(BAUD2400);
|
---|
| 162 | }
|
---|
| 163 | else if (hlp == "4800") {
|
---|
| 164 | _serialPort->setBaudRate(BAUD4800);
|
---|
| 165 | }
|
---|
| 166 | else if (hlp == "9600") {
|
---|
| 167 | _serialPort->setBaudRate(BAUD9600);
|
---|
| 168 | }
|
---|
| 169 | else if (hlp == "19200") {
|
---|
| 170 | _serialPort->setBaudRate(BAUD19200);
|
---|
| 171 | }
|
---|
| 172 | else if (hlp == "38400") {
|
---|
| 173 | _serialPort->setBaudRate(BAUD38400);
|
---|
| 174 | }
|
---|
| 175 | else if (hlp == "57600") {
|
---|
| 176 | _serialPort->setBaudRate(BAUD57600);
|
---|
| 177 | }
|
---|
| 178 | else if (hlp == "115200") {
|
---|
| 179 | _serialPort->setBaudRate(BAUD115200);
|
---|
| 180 | }
|
---|
[1710] | 181 |
|
---|
| 182 | // Parity
|
---|
| 183 | // ------
|
---|
[1330] | 184 | hlp = settings.value("serialParity").toString();
|
---|
| 185 | if (hlp == "NONE") {
|
---|
| 186 | _serialPort->setParity(PAR_NONE);
|
---|
| 187 | }
|
---|
| 188 | else if (hlp == "ODD") {
|
---|
| 189 | _serialPort->setParity(PAR_ODD);
|
---|
| 190 | }
|
---|
| 191 | else if (hlp == "EVEN") {
|
---|
| 192 | _serialPort->setParity(PAR_EVEN);
|
---|
| 193 | }
|
---|
| 194 | else if (hlp == "SPACE") {
|
---|
| 195 | _serialPort->setParity(PAR_SPACE);
|
---|
| 196 | }
|
---|
[1710] | 197 |
|
---|
| 198 | // Data Bits
|
---|
| 199 | // ---------
|
---|
[1330] | 200 | hlp = settings.value("serialDataBits").toString();
|
---|
| 201 | if (hlp == "5") {
|
---|
| 202 | _serialPort->setDataBits(DATA_5);
|
---|
| 203 | }
|
---|
| 204 | else if (hlp == "6") {
|
---|
| 205 | _serialPort->setDataBits(DATA_6);
|
---|
| 206 | }
|
---|
| 207 | else if (hlp == "7") {
|
---|
| 208 | _serialPort->setDataBits(DATA_7);
|
---|
| 209 | }
|
---|
| 210 | else if (hlp == "8") {
|
---|
| 211 | _serialPort->setDataBits(DATA_8);
|
---|
| 212 | }
|
---|
| 213 | hlp = settings.value("serialStopBits").toString();
|
---|
| 214 | if (hlp == "1") {
|
---|
| 215 | _serialPort->setStopBits(STOP_1);
|
---|
| 216 | }
|
---|
| 217 | else if (hlp == "2") {
|
---|
| 218 | _serialPort->setStopBits(STOP_2);
|
---|
| 219 | }
|
---|
[1710] | 220 |
|
---|
| 221 | // Flow Control
|
---|
| 222 | // ------------
|
---|
| 223 | hlp = settings.value("serialFlowControl").toString();
|
---|
[1711] | 224 | if (hlp == "XONXOFF") {
|
---|
[1710] | 225 | _serialPort->setFlowControl(FLOW_XONXOFF);
|
---|
| 226 | }
|
---|
| 227 | else if (hlp == "HARDWARE") {
|
---|
| 228 | _serialPort->setFlowControl(FLOW_HARDWARE);
|
---|
| 229 | }
|
---|
[1711] | 230 | else {
|
---|
| 231 | _serialPort->setFlowControl(FLOW_OFF);
|
---|
| 232 | }
|
---|
[1710] | 233 |
|
---|
| 234 | // Open Serial Port
|
---|
| 235 | // ----------------
|
---|
[1326] | 236 | _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
|
---|
[1331] | 237 | if (!_serialPort->isOpen()) {
|
---|
| 238 | delete _serialPort;
|
---|
| 239 | _serialPort = 0;
|
---|
[1451] | 240 | emit(newMessage((_staID + ": Cannot open serial port\n"), true));
|
---|
[1331] | 241 | }
|
---|
[1606] | 242 | connect(_serialPort, SIGNAL(readyRead()),
|
---|
| 243 | this, SLOT(slotSerialReadyRead()));
|
---|
| 244 |
|
---|
[1710] | 245 | // Automatic NMEA
|
---|
| 246 | // --------------
|
---|
| 247 | if (settings.value("serialAutoNMEA").toString() == "Auto") {
|
---|
| 248 | _serialNMEA = AUTO_NMEA;
|
---|
| 249 |
|
---|
| 250 | QString fName = settings.value("serialFileNMEA").toString();
|
---|
| 251 | if (!fName.isEmpty()) {
|
---|
| 252 | _serialOutFile = new QFile(fName);
|
---|
| 253 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 254 | _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 255 | }
|
---|
| 256 | else {
|
---|
| 257 | _serialOutFile->open(QIODevice::WriteOnly);
|
---|
| 258 | }
|
---|
[1634] | 259 | }
|
---|
[1606] | 260 | }
|
---|
[1710] | 261 |
|
---|
| 262 | // Manual NMEA
|
---|
| 263 | // -----------
|
---|
| 264 | else {
|
---|
| 265 | _serialNMEA = MANUAL_NMEA;
|
---|
[1636] | 266 | }
|
---|
[1318] | 267 | }
|
---|
| 268 |
|
---|
[3532] | 269 | if (!_staID.isEmpty()) {
|
---|
| 270 | _latencyChecker = new latencyChecker(_staID);
|
---|
[2004] | 271 | }
|
---|
[3532] | 272 | else {
|
---|
| 273 | _latencyChecker = 0;
|
---|
| 274 | }
|
---|
[3523] | 275 | }
|
---|
| 276 |
|
---|
| 277 | // Instantiate the decoder
|
---|
| 278 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 279 | t_irc bncGetThread::initDecoder() {
|
---|
| 280 |
|
---|
[3560] | 281 | _decoder = 0;
|
---|
| 282 |
|
---|
[1744] | 283 | if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
|
---|
| 284 | _format.indexOf("RTCM 2") != -1 ) {
|
---|
[1555] | 285 | emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
|
---|
[3560] | 286 | _decoder = new RTCM2Decoder(_staID.data());
|
---|
[1555] | 287 | }
|
---|
[1744] | 288 | else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
|
---|
| 289 | _format.indexOf("RTCM 3") != -1 ) {
|
---|
[1555] | 290 | emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
|
---|
[3558] | 291 | RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
|
---|
[3560] | 292 | _decoder = newDecoder;
|
---|
[3558] | 293 | connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
|
---|
[1555] | 294 | this, SIGNAL(newMessage(QByteArray,bool)));
|
---|
| 295 | }
|
---|
| 296 | else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
|
---|
| 297 | emit(newMessage(_staID + ": Get Data in GPSS format", true));
|
---|
[3560] | 298 | _decoder = new gpssDecoder();
|
---|
[1555] | 299 | }
|
---|
| 300 | else if (_format.indexOf("ZERO") != -1) {
|
---|
| 301 | emit(newMessage(_staID + ": Get data in original format", true));
|
---|
[3560] | 302 | _decoder = new bncZeroDecoder(_staID);
|
---|
[1555] | 303 | }
|
---|
[3168] | 304 | else if (_format.indexOf("RTNET") != -1) {
|
---|
| 305 | emit(newMessage(_staID + ": Get data in RTNet format", true));
|
---|
[3560] | 306 | _decoder = new bncRtnetDecoder();
|
---|
[3168] | 307 | }
|
---|
[3509] | 308 | else if (_format.indexOf("HASS2ASCII") != -1) {
|
---|
[3517] | 309 | emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
|
---|
[3560] | 310 | _decoder = new hassDecoder(_staID);
|
---|
[3504] | 311 | }
|
---|
[1555] | 312 | else {
|
---|
| 313 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
---|
| 314 | _isToBeDeleted = true;
|
---|
[3523] | 315 | return failure;
|
---|
[1555] | 316 | }
|
---|
| 317 |
|
---|
[319] | 318 | msleep(100); //sleep 0.1 sec
|
---|
[3523] | 319 |
|
---|
[3560] | 320 | _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
|
---|
| 321 | _nmea, _ntripVersion);
|
---|
| 322 |
|
---|
| 323 | if (_rawFile) {
|
---|
| 324 | _decodersRaw[_staID] = _decoder;
|
---|
[3530] | 325 | }
|
---|
| 326 |
|
---|
[3532] | 327 | // Initialize PPP Client?
|
---|
| 328 | // ----------------------
|
---|
| 329 | #ifndef MLS_SOFTWARE
|
---|
| 330 | bncSettings settings;
|
---|
[4792] | 331 | if (!settings.value("pppSPP").toString().isEmpty() &&
|
---|
| 332 | settings.value("pppMount").toString() == _staID) {
|
---|
[3532] | 333 | _PPPclient = new bncPPPclient(_staID);
|
---|
[5068] | 334 | BNC_CORE->_bncPPPclient = _PPPclient;
|
---|
[3532] | 335 | qRegisterMetaType<bncTime>("bncTime");
|
---|
| 336 | connect(_PPPclient, SIGNAL(newPosition(bncTime, double, double, double)),
|
---|
| 337 | this, SIGNAL(newPosition(bncTime, double, double, double)));
|
---|
| 338 | connect(_PPPclient, SIGNAL(newNMEAstr(QByteArray)),
|
---|
| 339 | this, SIGNAL(newNMEAstr(QByteArray)));
|
---|
| 340 | }
|
---|
| 341 | #endif
|
---|
| 342 |
|
---|
[3523] | 343 | return success;
|
---|
[35] | 344 | }
|
---|
| 345 |
|
---|
[3523] | 346 | // Current decoder in use
|
---|
| 347 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 348 | GPSDecoder* bncGetThread::decoder() {
|
---|
[3560] | 349 | if (!_rawFile) {
|
---|
| 350 | return _decoder;
|
---|
[3523] | 351 | }
|
---|
| 352 | else {
|
---|
[3560] | 353 | if (_decodersRaw.contains(_staID) || initDecoder() == success) {
|
---|
| 354 | return _decodersRaw[_staID];
|
---|
| 355 | }
|
---|
[3523] | 356 | }
|
---|
[3560] | 357 | return 0;
|
---|
[3523] | 358 | }
|
---|
| 359 |
|
---|
[35] | 360 | // Destructor
|
---|
| 361 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 362 | bncGetThread::~bncGetThread() {
|
---|
[1928] | 363 | if (isRunning()) {
|
---|
| 364 | wait();
|
---|
| 365 | }
|
---|
[1527] | 366 | if (_query) {
|
---|
| 367 | _query->stop();
|
---|
[1708] | 368 | _query->deleteLater();
|
---|
[1527] | 369 | }
|
---|
[2035] | 370 | delete _PPPclient;
|
---|
[3560] | 371 | if (_rawFile) {
|
---|
| 372 | QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
|
---|
| 373 | while (it.hasNext()) {
|
---|
| 374 | it.next();
|
---|
| 375 | delete it.value();
|
---|
| 376 | }
|
---|
[3523] | 377 | }
|
---|
[3560] | 378 | else {
|
---|
| 379 | delete _decoder;
|
---|
| 380 | }
|
---|
[2519] | 381 | delete _rawFile;
|
---|
[1607] | 382 | delete _serialOutFile;
|
---|
[1328] | 383 | delete _serialPort;
|
---|
[1557] | 384 | delete _latencyChecker;
|
---|
[1556] | 385 | emit getThreadFinished(_staID);
|
---|
[35] | 386 | }
|
---|
| 387 |
|
---|
[1390] | 388 | //
|
---|
| 389 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 390 | void bncGetThread::terminate() {
|
---|
[1525] | 391 | _isToBeDeleted = true;
|
---|
[1559] | 392 | if (!isRunning()) {
|
---|
| 393 | delete this;
|
---|
| 394 | }
|
---|
[1390] | 395 | }
|
---|
| 396 |
|
---|
[136] | 397 | // Run
|
---|
| 398 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 399 | void bncGetThread::run() {
|
---|
| 400 |
|
---|
[35] | 401 | while (true) {
|
---|
[629] | 402 | try {
|
---|
[1555] | 403 | if (_isToBeDeleted) {
|
---|
| 404 | QThread::exit(0);
|
---|
| 405 | this->deleteLater();
|
---|
| 406 | return;
|
---|
[629] | 407 | }
|
---|
[621] | 408 |
|
---|
[1555] | 409 | if (tryReconnect() != success) {
|
---|
[3532] | 410 | if (_latencyChecker) {
|
---|
| 411 | _latencyChecker->checkReconnect();
|
---|
| 412 | }
|
---|
[1555] | 413 | continue;
|
---|
[621] | 414 | }
|
---|
[1555] | 415 |
|
---|
| 416 | // Delete old observations
|
---|
| 417 | // -----------------------
|
---|
[3560] | 418 | if (_rawFile) {
|
---|
| 419 | QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
|
---|
| 420 | while (itDec.hasNext()) {
|
---|
| 421 | itDec.next();
|
---|
| 422 | GPSDecoder* decoder = itDec.value();
|
---|
| 423 | decoder->_obsList.clear();
|
---|
| 424 | }
|
---|
[3515] | 425 | }
|
---|
[3560] | 426 | else {
|
---|
| 427 | _decoder->_obsList.clear();
|
---|
| 428 | }
|
---|
[621] | 429 |
|
---|
[1555] | 430 | // Read Data
|
---|
| 431 | // ---------
|
---|
[1377] | 432 | QByteArray data;
|
---|
| 433 | if (_query) {
|
---|
| 434 | _query->waitForReadyRead(data);
|
---|
[1138] | 435 | }
|
---|
[2519] | 436 | else if (_rawFile) {
|
---|
[2527] | 437 | data = _rawFile->readChunk();
|
---|
[3523] | 438 | _format = _rawFile->format();
|
---|
| 439 | _staID = _rawFile->staID();
|
---|
[2388] | 440 |
|
---|
[1555] | 441 | if (data.isEmpty()) {
|
---|
| 442 | cout << "no more data" << endl;
|
---|
[5068] | 443 | BNC_CORE->stopCombination();
|
---|
[3541] | 444 | QThread::exit(0);
|
---|
| 445 | delete this;
|
---|
[3534] | 446 | ::exit(0);
|
---|
[1555] | 447 | }
|
---|
[1138] | 448 | }
|
---|
[1555] | 449 | qint64 nBytes = data.size();
|
---|
[1138] | 450 |
|
---|
[1555] | 451 | // Timeout, reconnect
|
---|
| 452 | // ------------------
|
---|
| 453 | if (nBytes == 0) {
|
---|
[3532] | 454 | if (_latencyChecker) {
|
---|
| 455 | _latencyChecker->checkReconnect();
|
---|
| 456 | }
|
---|
[1555] | 457 | emit(newMessage(_staID + ": Data timeout, reconnecting", true));
|
---|
[2355] | 458 | msleep(10000); //sleep 10 sec, G. Weber
|
---|
[1555] | 459 | continue;
|
---|
| 460 | }
|
---|
| 461 | else {
|
---|
[567] | 462 | emit newBytes(_staID, nBytes);
|
---|
[1555] | 463 | }
|
---|
[567] | 464 |
|
---|
[1555] | 465 | // Output Data
|
---|
| 466 | // -----------
|
---|
[2386] | 467 | if (_rawOutput) {
|
---|
[5068] | 468 | BNC_CORE->writeRawData(data, _staID, _format);
|
---|
[2386] | 469 | }
|
---|
[2385] | 470 |
|
---|
[1555] | 471 | if (_serialPort) {
|
---|
[1633] | 472 | slotSerialReadyRead();
|
---|
[1555] | 473 | _serialPort->write(data);
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | // Decode Data
|
---|
| 477 | // -----------
|
---|
| 478 | vector<string> errmsg;
|
---|
[3526] | 479 | if (!decoder()) {
|
---|
| 480 | _isToBeDeleted = true;
|
---|
| 481 | continue;
|
---|
| 482 | }
|
---|
[3523] | 483 | decoder()->_obsList.clear();
|
---|
| 484 | t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
|
---|
[1137] | 485 |
|
---|
[1555] | 486 | // Perform various scans and checks
|
---|
| 487 | // --------------------------------
|
---|
[3532] | 488 | if (_latencyChecker) {
|
---|
| 489 | _latencyChecker->checkOutage(irc == success);
|
---|
| 490 | _latencyChecker->checkObsLatency(decoder()->_obsList);
|
---|
| 491 | _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
|
---|
| 492 |
|
---|
| 493 | emit newLatency(_staID, _latencyChecker->currentLatency());
|
---|
| 494 | }
|
---|
[1567] | 495 |
|
---|
[1555] | 496 | scanRTCM();
|
---|
[1138] | 497 |
|
---|
[1555] | 498 | // Loop over all observations (observations output)
|
---|
| 499 | // ------------------------------------------------
|
---|
[3523] | 500 | QListIterator<t_obs> it(decoder()->_obsList);
|
---|
[5524] | 501 |
|
---|
| 502 | QList<t_obs> obsListHlp;
|
---|
| 503 |
|
---|
[1555] | 504 | while (it.hasNext()) {
|
---|
[2711] | 505 | const t_obs& obs = it.next();
|
---|
| 506 |
|
---|
[3303] | 507 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 508 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
| 509 | long iSec = long(floor(obs.GPSWeeks+0.5));
|
---|
| 510 | long obsTime = obs.GPSWeek * 7*24*3600 + iSec;
|
---|
| 511 |
|
---|
[1555] | 512 | // Check observation epoch
|
---|
| 513 | // -----------------------
|
---|
[3523] | 514 | if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) {
|
---|
[3303] | 515 | int week;
|
---|
[1555] | 516 | double sec;
|
---|
| 517 | currentGPSWeeks(week, sec);
|
---|
[3304] | 518 | long currTime = week * 7*24*3600 + long(sec);
|
---|
[1555] | 519 | const double maxDt = 600.0;
|
---|
[3303] | 520 | if (fabs(currTime - obsTime) > maxDt) {
|
---|
[2308] | 521 | emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
|
---|
[1555] | 522 | continue;
|
---|
[940] | 523 | }
|
---|
[686] | 524 | }
|
---|
[1555] | 525 |
|
---|
[3305] | 526 | // Check observations coming twice (e.g. KOUR0 Problem)
|
---|
| 527 | // ----------------------------------------------------
|
---|
[3535] | 528 | if (!_rawFile) {
|
---|
| 529 | QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
|
---|
| 530 | if (it != _prnLastEpo.end()) {
|
---|
| 531 | long oldTime = it.value();
|
---|
| 532 | if (obsTime < oldTime) {
|
---|
| 533 | emit( newMessage(_staID +
|
---|
| 534 | ": old observation " + prn.toAscii(), false));
|
---|
| 535 | continue;
|
---|
| 536 | }
|
---|
| 537 | else if (obsTime == oldTime) {
|
---|
| 538 | emit( newMessage(_staID +
|
---|
| 539 | ": observation coming more than once " + prn.toAscii(), false));
|
---|
| 540 | continue;
|
---|
| 541 | }
|
---|
[3302] | 542 | }
|
---|
[3535] | 543 | _prnLastEpo[prn] = obsTime;
|
---|
[3301] | 544 | }
|
---|
| 545 |
|
---|
[3528] | 546 | decoder()->dumpRinexEpoch(obs, _format);
|
---|
| 547 |
|
---|
[2030] | 548 | // PPP Client
|
---|
| 549 | // ----------
|
---|
[2290] | 550 | #ifndef MLS_SOFTWARE
|
---|
[3535] | 551 | if (_PPPclient && _staID == _PPPclient->staID()) {
|
---|
[2035] | 552 | _PPPclient->putNewObs(obs);
|
---|
[2030] | 553 | }
|
---|
[2290] | 554 | #endif
|
---|
[5524] | 555 | // Save observations
|
---|
| 556 | // -----------------
|
---|
| 557 | obsListHlp.append(obs);
|
---|
| 558 | }
|
---|
[2030] | 559 |
|
---|
[5524] | 560 | // Emit signal
|
---|
| 561 | // -----------
|
---|
| 562 | if (!_isToBeDeleted && obsListHlp.size() > 0) {
|
---|
| 563 | emit newObs(_staID, obsListHlp);
|
---|
[249] | 564 | }
|
---|
[5524] | 565 |
|
---|
[3523] | 566 | decoder()->_obsList.clear();
|
---|
[35] | 567 | }
|
---|
[3311] | 568 | catch (Exception& exc) {
|
---|
| 569 | emit(newMessage(_staID + " " + exc.what(), true));
|
---|
| 570 | _isToBeDeleted = true;
|
---|
| 571 | }
|
---|
[1555] | 572 | catch (...) {
|
---|
[3311] | 573 | emit(newMessage(_staID + " bncGetThread exception", true));
|
---|
[1559] | 574 | _isToBeDeleted = true;
|
---|
[1555] | 575 | }
|
---|
[35] | 576 | }
|
---|
| 577 | }
|
---|
| 578 |
|
---|
[136] | 579 | // Try Re-Connect
|
---|
| 580 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1555] | 581 | t_irc bncGetThread::tryReconnect() {
|
---|
| 582 |
|
---|
| 583 | // Easy Return
|
---|
| 584 | // -----------
|
---|
| 585 | if (_query && _query->status() == bncNetQuery::running) {
|
---|
| 586 | _nextSleep = 0;
|
---|
[3560] | 587 | if (_rawFile) {
|
---|
| 588 | QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
|
---|
| 589 | while (itDec.hasNext()) {
|
---|
| 590 | itDec.next();
|
---|
| 591 | GPSDecoder* decoder = itDec.value();
|
---|
| 592 | decoder->setRinexReconnectFlag(false);
|
---|
| 593 | }
|
---|
[1709] | 594 | }
|
---|
[3560] | 595 | else {
|
---|
| 596 | _decoder->setRinexReconnectFlag(false);
|
---|
| 597 | }
|
---|
[1555] | 598 | return success;
|
---|
[408] | 599 | }
|
---|
[1555] | 600 |
|
---|
| 601 | // Start a new query
|
---|
| 602 | // -----------------
|
---|
[2519] | 603 | if (!_rawFile) {
|
---|
[1555] | 604 |
|
---|
[138] | 605 | sleep(_nextSleep);
|
---|
[1555] | 606 | if (_nextSleep == 0) {
|
---|
| 607 | _nextSleep = 1;
|
---|
[138] | 608 | }
|
---|
| 609 | else {
|
---|
[1555] | 610 | _nextSleep = 2 * _nextSleep;
|
---|
[442] | 611 | if (_nextSleep > 256) {
|
---|
| 612 | _nextSleep = 256;
|
---|
[152] | 613 | }
|
---|
[1816] | 614 | #ifdef MLS_SOFTWARE
|
---|
[1817] | 615 | if (_nextSleep > 4) {
|
---|
| 616 | _nextSleep = 4;
|
---|
[1816] | 617 | }
|
---|
| 618 | #endif
|
---|
[138] | 619 | }
|
---|
[1555] | 620 |
|
---|
| 621 | delete _query;
|
---|
[1722] | 622 | if (_ntripVersion == "U") {
|
---|
[1721] | 623 | _query = new bncNetQueryUdp();
|
---|
| 624 | }
|
---|
[1722] | 625 | else if (_ntripVersion == "R") {
|
---|
[1555] | 626 | _query = new bncNetQueryRtp();
|
---|
| 627 | }
|
---|
[1744] | 628 | else if (_ntripVersion == "S") {
|
---|
[1753] | 629 | _query = new bncNetQueryS();
|
---|
[1744] | 630 | }
|
---|
[1621] | 631 | else if (_ntripVersion == "N") {
|
---|
| 632 | _query = new bncNetQueryV0();
|
---|
| 633 | }
|
---|
[1779] | 634 | else if (_ntripVersion == "UN") {
|
---|
| 635 | _query = new bncNetQueryUdp0();
|
---|
| 636 | }
|
---|
[1555] | 637 | else if (_ntripVersion == "2") {
|
---|
[3337] | 638 | _query = new bncNetQueryV2(false);
|
---|
[1555] | 639 | }
|
---|
[3334] | 640 | else if (_ntripVersion == "2s") {
|
---|
[3337] | 641 | _query = new bncNetQueryV2(true);
|
---|
[3334] | 642 | }
|
---|
[1555] | 643 | else {
|
---|
| 644 | _query = new bncNetQueryV1();
|
---|
| 645 | }
|
---|
[1710] | 646 | if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
|
---|
| 647 | QByteArray gga = ggaString(_latitude, _longitude, "100.0");
|
---|
[1555] | 648 | _query->startRequest(_mountPoint, gga);
|
---|
| 649 | }
|
---|
| 650 | else {
|
---|
| 651 | _query->startRequest(_mountPoint, "");
|
---|
| 652 | }
|
---|
| 653 | if (_query->status() != bncNetQuery::running) {
|
---|
| 654 | return failure;
|
---|
| 655 | }
|
---|
[138] | 656 | }
|
---|
[658] | 657 |
|
---|
[3560] | 658 | if (_rawFile) {
|
---|
| 659 | QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
|
---|
| 660 | while (itDec.hasNext()) {
|
---|
| 661 | itDec.next();
|
---|
| 662 | GPSDecoder* decoder = itDec.value();
|
---|
| 663 | decoder->setRinexReconnectFlag(false);
|
---|
| 664 | }
|
---|
[658] | 665 | }
|
---|
[3560] | 666 | else {
|
---|
| 667 | _decoder->setRinexReconnectFlag(false);
|
---|
| 668 | }
|
---|
[1555] | 669 |
|
---|
| 670 | return success;
|
---|
[658] | 671 | }
|
---|
[1044] | 672 |
|
---|
[1555] | 673 | // RTCM scan output
|
---|
[1044] | 674 | //////////////////////////////////////////////////////////////////////////////
|
---|
[1555] | 675 | void bncGetThread::scanRTCM() {
|
---|
[1044] | 676 |
|
---|
[4476] | 677 | if ( !decoder() ) {
|
---|
[3558] | 678 | return;
|
---|
| 679 | }
|
---|
| 680 |
|
---|
[1555] | 681 | bncSettings settings;
|
---|
[1574] | 682 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
|
---|
| 683 |
|
---|
| 684 | if ( _miscMount == _staID || _miscMount == "ALL" ) {
|
---|
| 685 |
|
---|
[1575] | 686 | // RTCM message types
|
---|
| 687 | // ------------------
|
---|
[4476] | 688 | for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
|
---|
[3523] | 689 | QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
|
---|
[1574] | 690 | emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
|
---|
| 691 | }
|
---|
[1044] | 692 |
|
---|
[4476] | 693 | // Check Observation Types
|
---|
| 694 | // -----------------------
|
---|
| 695 | for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
|
---|
| 696 | t_obs& obs = decoder()->_obsList[ii];
|
---|
| 697 | QVector<QString>& rnxTypes = _rnxTypes[obs.satSys];
|
---|
| 698 | bool allFound = true;
|
---|
| 699 | for (int iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
|
---|
| 700 | if (obs._measdata[iEntry] != 0.0) {
|
---|
| 701 | if (rnxTypes.indexOf(obs.rnxStr(iEntry)) == -1) {
|
---|
| 702 | allFound = false;
|
---|
| 703 | rnxTypes << obs.rnxStr(iEntry);
|
---|
| 704 | }
|
---|
| 705 | }
|
---|
| 706 | }
|
---|
| 707 | if (!allFound) {
|
---|
[4477] | 708 | QString msg;
|
---|
| 709 | QTextStream str(&msg);
|
---|
| 710 | str << obs.satSys << " " << rnxTypes.size() << " ";
|
---|
[4476] | 711 | for (int iType = 0; iType < rnxTypes.size(); iType++) {
|
---|
[4478] | 712 | str << " " << rnxTypes[iType];
|
---|
[4476] | 713 | }
|
---|
[4477] | 714 | emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
|
---|
[4476] | 715 | }
|
---|
| 716 | }
|
---|
| 717 |
|
---|
[1574] | 718 | // RTCMv3 antenna descriptor
|
---|
| 719 | // -------------------------
|
---|
[4476] | 720 | for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
|
---|
[3523] | 721 | QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
|
---|
[1574] | 722 | emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
|
---|
| 723 | }
|
---|
[1555] | 724 |
|
---|
[1575] | 725 | // RTCM Antenna Coordinates
|
---|
| 726 | // ------------------------
|
---|
[4476] | 727 | for (int ii=0; ii < decoder()->_antList.size(); ii++) {
|
---|
[1574] | 728 | QByteArray antT;
|
---|
[3523] | 729 | if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
[1574] | 730 | antT = "ARP";
|
---|
| 731 | }
|
---|
[3523] | 732 | else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
[1574] | 733 | antT = "APC";
|
---|
| 734 | }
|
---|
[1575] | 735 | QByteArray ant1, ant2, ant3;
|
---|
[3523] | 736 | ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
|
---|
| 737 | ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
|
---|
| 738 | ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
|
---|
[1575] | 739 | emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
|
---|
| 740 | emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
|
---|
| 741 | emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
|
---|
[3595] | 742 | double hh = 0.0;
|
---|
[3523] | 743 | if (decoder()->_antList[ii].height_f) {
|
---|
[3595] | 744 | hh = decoder()->_antList[ii].height;
|
---|
| 745 | QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
|
---|
[1575] | 746 | emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
|
---|
| 747 | }
|
---|
[3523] | 748 | emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
|
---|
| 749 | decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
|
---|
[3595] | 750 | hh, antT));
|
---|
[1218] | 751 | }
|
---|
| 752 | }
|
---|
[1044] | 753 | }
|
---|
[1575] | 754 |
|
---|
[1770] | 755 | #ifdef MLS_SOFTWARE
|
---|
[3523] | 756 | for (int ii=0; ii <decoder()->_antList.size(); ii++) {
|
---|
[1770] | 757 | QByteArray antT;
|
---|
[3523] | 758 | if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
[1770] | 759 | antT = "ARP";
|
---|
| 760 | }
|
---|
[3523] | 761 | else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
[1770] | 762 | antT = "APC";
|
---|
| 763 | }
|
---|
[3595] | 764 | double hh = 0.0;
|
---|
| 765 | if (decoder()->_antList[ii].height_f) {
|
---|
| 766 | hh = decoder()->_antList[ii].height;
|
---|
| 767 | }
|
---|
[3523] | 768 | emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
|
---|
| 769 | decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
|
---|
[3595] | 770 | hh, antT));
|
---|
[1770] | 771 | }
|
---|
[2356] | 772 |
|
---|
[3523] | 773 | for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
|
---|
| 774 | emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
|
---|
[2356] | 775 | }
|
---|
[1770] | 776 | #endif
|
---|
| 777 |
|
---|
[3523] | 778 | decoder()->_typeList.clear();
|
---|
| 779 | decoder()->_antType.clear();
|
---|
| 780 | decoder()->_antList.clear();
|
---|
[1044] | 781 | }
|
---|
[1555] | 782 |
|
---|
[1606] | 783 | // Handle Data from Serial Port
|
---|
| 784 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 785 | void bncGetThread::slotSerialReadyRead() {
|
---|
[1607] | 786 | if (_serialPort) {
|
---|
[1633] | 787 | int nb = _serialPort->bytesAvailable();
|
---|
| 788 | if (nb > 0) {
|
---|
| 789 | QByteArray data = _serialPort->read(nb);
|
---|
[1711] | 790 |
|
---|
| 791 | if (_serialNMEA == AUTO_NMEA) {
|
---|
[1725] | 792 | int i1 = data.indexOf("$GPGGA");
|
---|
| 793 | if (i1 != -1) {
|
---|
| 794 | int i2 = data.indexOf("*", i1);
|
---|
| 795 | if (i2 != -1 && data.size() > i2 + 1) {
|
---|
| 796 | QByteArray gga = data.mid(i1,i2-i1+3);
|
---|
| 797 | _query->sendNMEA(gga);
|
---|
| 798 | }
|
---|
| 799 | }
|
---|
[1711] | 800 | }
|
---|
| 801 |
|
---|
[1633] | 802 | if (_serialOutFile) {
|
---|
| 803 | _serialOutFile->write(data);
|
---|
| 804 | _serialOutFile->flush();
|
---|
| 805 | }
|
---|
[1607] | 806 | }
|
---|
| 807 | }
|
---|
[1606] | 808 | }
|
---|