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