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