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