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