[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"
|
---|
[65] | 65 |
|
---|
[243] | 66 | #include "RTCM/RTCM2Decoder.h"
|
---|
[297] | 67 | #include "RTCM3/RTCM3Decoder.h"
|
---|
[293] | 68 | #include "RTIGS/RTIGSDecoder.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 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1138] | 76 | bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
|
---|
| 77 | const QByteArray& format) {
|
---|
| 78 |
|
---|
| 79 | _rawInpFile = new QFile(rawInpFileName);
|
---|
| 80 | _rawInpFile->open(QIODevice::ReadOnly);
|
---|
[1555] | 81 | _format = format;
|
---|
| 82 | _staID = rawInpFileName.mid(
|
---|
| 83 | rawInpFileName.lastIndexOf(QDir::separator())+1,4);
|
---|
[1147] | 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,
|
---|
[1770] | 95 | const QByteArray& ntripVersion, const QByteArray& extraStaID) {
|
---|
[1555] | 96 | _rawInpFile = 0;
|
---|
| 97 | _mountPoint = mountPoint;
|
---|
[1770] | 98 | _staID = (extraStaID.size() == 0 ? mountPoint.path().mid(1).toAscii() : extraStaID);
|
---|
[1555] | 99 | _format = format;
|
---|
| 100 | _latitude = latitude;
|
---|
| 101 | _longitude = longitude;
|
---|
| 102 | _nmea = nmea;
|
---|
[1353] | 103 | _ntripVersion = ntripVersion;
|
---|
[1139] | 104 |
|
---|
| 105 | initialize();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[1555] | 108 | // Initialization (common part of the constructor)
|
---|
[1143] | 109 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1139] | 110 | void bncGetThread::initialize() {
|
---|
| 111 |
|
---|
[1555] | 112 | setTerminationEnabled(true);
|
---|
| 113 |
|
---|
[1225] | 114 | bncApp* app = (bncApp*) qApp;
|
---|
| 115 |
|
---|
[1555] | 116 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 117 | app, SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 118 |
|
---|
[1525] | 119 | _isToBeDeleted = false;
|
---|
[1555] | 120 | _decoder = 0;
|
---|
| 121 | _query = 0;
|
---|
| 122 | _nextSleep = 0;
|
---|
| 123 | _rawOutFile = 0;
|
---|
[255] | 124 |
|
---|
[1574] | 125 | bncSettings settings;
|
---|
[1595] | 126 |
|
---|
[1574] | 127 | _miscMount = settings.value("miscMount").toString();
|
---|
| 128 |
|
---|
[408] | 129 | // RINEX writer
|
---|
| 130 | // ------------
|
---|
| 131 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
| 132 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
| 133 | _rnx = 0;
|
---|
[1555] | 134 | if (_rawInpFile) {
|
---|
| 135 | cerr << "no RINEX path specified" << endl;
|
---|
| 136 | ::exit(1);
|
---|
| 137 | }
|
---|
[408] | 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 |
|
---|
[1137] | 278 | // Raw Output
|
---|
| 279 | // ----------
|
---|
[1140] | 280 | // QByteArray rawOutFileName = "./" + _staID + ".raw";
|
---|
| 281 | // _rawOutFile = new QFile(rawOutFileName);
|
---|
| 282 | // _rawOutFile->open(QIODevice::WriteOnly);
|
---|
[1137] | 283 |
|
---|
[1555] | 284 |
|
---|
| 285 | // Instantiate the decoder
|
---|
| 286 | // -----------------------
|
---|
[1744] | 287 | if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
|
---|
| 288 | _format.indexOf("RTCM 2") != -1 ) {
|
---|
[1555] | 289 | emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
|
---|
| 290 | _decoder = new RTCM2Decoder(_staID.data());
|
---|
| 291 | }
|
---|
[1744] | 292 | else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
|
---|
| 293 | _format.indexOf("RTCM 3") != -1 ) {
|
---|
[1555] | 294 | emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
|
---|
| 295 | _decoder = new RTCM3Decoder(_staID);
|
---|
| 296 | connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 297 | this, SIGNAL(newMessage(QByteArray,bool)));
|
---|
| 298 | }
|
---|
| 299 | else if (_format.indexOf("RTIGS") != -1) {
|
---|
| 300 | emit(newMessage(_staID + ": Get data in RTIGS format", true));
|
---|
| 301 | _decoder = new RTIGSDecoder();
|
---|
| 302 | }
|
---|
| 303 | else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
|
---|
| 304 | emit(newMessage(_staID + ": Get Data in GPSS format", true));
|
---|
| 305 | _decoder = new gpssDecoder();
|
---|
| 306 | }
|
---|
| 307 | else if (_format.indexOf("ZERO") != -1) {
|
---|
| 308 | emit(newMessage(_staID + ": Get data in original format", true));
|
---|
| 309 | _decoder = new bncZeroDecoder(_staID);
|
---|
| 310 | }
|
---|
| 311 | else {
|
---|
| 312 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
---|
| 313 | _isToBeDeleted = true;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[1558] | 316 | _latencyChecker = new latencyChecker(_staID);
|
---|
[1557] | 317 |
|
---|
[319] | 318 | msleep(100); //sleep 0.1 sec
|
---|
[35] | 319 | }
|
---|
| 320 |
|
---|
| 321 | // Destructor
|
---|
| 322 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 323 | bncGetThread::~bncGetThread() {
|
---|
[1928] | 324 |
|
---|
| 325 | if (isRunning()) {
|
---|
| 326 | wait();
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[1527] | 329 | if (_query) {
|
---|
| 330 | _query->stop();
|
---|
[1708] | 331 | _query->deleteLater();
|
---|
[1527] | 332 | }
|
---|
[617] | 333 | delete _decoder;
|
---|
[1044] | 334 | delete _rnx;
|
---|
[1138] | 335 | delete _rawInpFile;
|
---|
| 336 | delete _rawOutFile;
|
---|
[1607] | 337 | delete _serialOutFile;
|
---|
[1328] | 338 | delete _serialPort;
|
---|
[1557] | 339 | delete _latencyChecker;
|
---|
[1556] | 340 | emit getThreadFinished(_staID);
|
---|
[35] | 341 | }
|
---|
| 342 |
|
---|
[1390] | 343 | //
|
---|
| 344 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 345 | void bncGetThread::terminate() {
|
---|
[1525] | 346 | _isToBeDeleted = true;
|
---|
[1559] | 347 | if (!isRunning()) {
|
---|
| 348 | delete this;
|
---|
| 349 | }
|
---|
[1390] | 350 | }
|
---|
| 351 |
|
---|
[136] | 352 | // Run
|
---|
| 353 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 354 | void bncGetThread::run() {
|
---|
| 355 |
|
---|
[35] | 356 | while (true) {
|
---|
[629] | 357 | try {
|
---|
[1555] | 358 | if (_isToBeDeleted) {
|
---|
| 359 | QThread::exit(0);
|
---|
| 360 | this->deleteLater();
|
---|
| 361 | return;
|
---|
[629] | 362 | }
|
---|
[621] | 363 |
|
---|
[1555] | 364 | if (tryReconnect() != success) {
|
---|
[1572] | 365 | _latencyChecker->checkReconnect();
|
---|
[1555] | 366 | continue;
|
---|
[621] | 367 | }
|
---|
[1555] | 368 |
|
---|
| 369 | // Delete old observations
|
---|
| 370 | // -----------------------
|
---|
| 371 | QListIterator<p_obs> itOld(_decoder->_obsList);
|
---|
| 372 | while (itOld.hasNext()) {
|
---|
| 373 | delete itOld.next();
|
---|
| 374 | }
|
---|
[621] | 375 | _decoder->_obsList.clear();
|
---|
| 376 |
|
---|
[1555] | 377 | // Read Data
|
---|
| 378 | // ---------
|
---|
[1377] | 379 | QByteArray data;
|
---|
| 380 | if (_query) {
|
---|
| 381 | _query->waitForReadyRead(data);
|
---|
[1138] | 382 | }
|
---|
| 383 | else if (_rawInpFile) {
|
---|
[1146] | 384 | const qint64 maxBytes = 1024;
|
---|
[1555] | 385 | data = _rawInpFile->read(maxBytes);
|
---|
| 386 | if (data.isEmpty()) {
|
---|
| 387 | cout << "no more data" << endl;
|
---|
| 388 | ::exit(0);
|
---|
| 389 | }
|
---|
[1138] | 390 | }
|
---|
[1555] | 391 | qint64 nBytes = data.size();
|
---|
[1138] | 392 |
|
---|
[1555] | 393 | // Timeout, reconnect
|
---|
| 394 | // ------------------
|
---|
| 395 | if (nBytes == 0) {
|
---|
[1576] | 396 | _latencyChecker->checkReconnect();
|
---|
[1555] | 397 | emit(newMessage(_staID + ": Data timeout, reconnecting", true));
|
---|
| 398 | continue;
|
---|
| 399 | }
|
---|
| 400 | else {
|
---|
[567] | 401 | emit newBytes(_staID, nBytes);
|
---|
[1555] | 402 | }
|
---|
[567] | 403 |
|
---|
[1555] | 404 | // Output Data
|
---|
| 405 | // -----------
|
---|
| 406 | if (_rawOutFile) {
|
---|
| 407 | _rawOutFile->write(data);
|
---|
| 408 | _rawOutFile->flush();
|
---|
| 409 | }
|
---|
| 410 | if (_serialPort) {
|
---|
[1633] | 411 | slotSerialReadyRead();
|
---|
[1555] | 412 | _serialPort->write(data);
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | // Decode Data
|
---|
| 416 | // -----------
|
---|
| 417 | vector<string> errmsg;
|
---|
[1562] | 418 | t_irc irc = _decoder->Decode(data.data(), data.size(), errmsg);
|
---|
[1137] | 419 |
|
---|
[1555] | 420 | // Perform various scans and checks
|
---|
| 421 | // --------------------------------
|
---|
[1562] | 422 | _latencyChecker->checkOutage(irc == success);
|
---|
| 423 | _latencyChecker->checkObsLatency(_decoder->_obsList);
|
---|
[1567] | 424 | _latencyChecker->checkCorrLatency(_decoder->corrGPSEpochTime());
|
---|
| 425 |
|
---|
[1973] | 426 | emit newLatency(_staID, _latencyChecker->currentLatency());
|
---|
[1969] | 427 |
|
---|
[1555] | 428 | scanRTCM();
|
---|
[1138] | 429 |
|
---|
[1555] | 430 | // Loop over all observations (observations output)
|
---|
| 431 | // ------------------------------------------------
|
---|
| 432 | QListIterator<p_obs> it(_decoder->_obsList);
|
---|
| 433 | while (it.hasNext()) {
|
---|
| 434 | p_obs obs = it.next();
|
---|
| 435 |
|
---|
| 436 | // Check observation epoch
|
---|
| 437 | // -----------------------
|
---|
| 438 | if (!_rawInpFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
|
---|
| 439 | int week;
|
---|
| 440 | double sec;
|
---|
| 441 | currentGPSWeeks(week, sec);
|
---|
| 442 | const double secPerWeek = 7.0 * 24.0 * 3600.0;
|
---|
| 443 |
|
---|
| 444 | if (week < obs->_o.GPSWeek) {
|
---|
| 445 | week += 1;
|
---|
| 446 | sec -= secPerWeek;
|
---|
[1218] | 447 | }
|
---|
[1555] | 448 | if (week > obs->_o.GPSWeek) {
|
---|
| 449 | week -= 1;
|
---|
| 450 | sec += secPerWeek;
|
---|
[650] | 451 | }
|
---|
[1555] | 452 | double dt = fabs(sec - obs->_o.GPSWeeks);
|
---|
| 453 | const double maxDt = 600.0;
|
---|
| 454 | if (week != obs->_o.GPSWeek || dt > maxDt) {
|
---|
| 455 | emit( newMessage(_staID + ": Wrong observation epoch(s)", true) );
|
---|
| 456 | delete obs;
|
---|
| 457 | continue;
|
---|
[940] | 458 | }
|
---|
[686] | 459 | }
|
---|
[1555] | 460 |
|
---|
| 461 | // RINEX Output
|
---|
| 462 | // ------------
|
---|
| 463 | if (_rnx) {
|
---|
| 464 | long iSec = long(floor(obs->_o.GPSWeeks+0.5));
|
---|
| 465 | long newTime = obs->_o.GPSWeek * 7*24*3600 + iSec;
|
---|
| 466 | if (_samplingRate == 0 || iSec % _samplingRate == 0) {
|
---|
| 467 | _rnx->deepCopy(obs);
|
---|
[1271] | 468 | }
|
---|
[1555] | 469 | _rnx->dumpEpoch(newTime);
|
---|
[1271] | 470 | }
|
---|
[1555] | 471 |
|
---|
| 472 | // Emit new observation signal
|
---|
| 473 | // ---------------------------
|
---|
| 474 | bool firstObs = (obs == _decoder->_obsList.first());
|
---|
| 475 | obs->_status = t_obs::posted;
|
---|
| 476 | emit newObs(_staID, firstObs, obs);
|
---|
[249] | 477 | }
|
---|
[1555] | 478 | _decoder->_obsList.clear();
|
---|
[35] | 479 | }
|
---|
[1555] | 480 | catch (...) {
|
---|
[1559] | 481 | emit(newMessage(_staID + "bncGetThread exception", true));
|
---|
| 482 | _isToBeDeleted = true;
|
---|
[1555] | 483 | }
|
---|
[35] | 484 | }
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[136] | 487 | // Try Re-Connect
|
---|
| 488 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1555] | 489 | t_irc bncGetThread::tryReconnect() {
|
---|
| 490 |
|
---|
| 491 | // Easy Return
|
---|
| 492 | // -----------
|
---|
| 493 | if (_query && _query->status() == bncNetQuery::running) {
|
---|
| 494 | _nextSleep = 0;
|
---|
[1709] | 495 | if (_rnx) {
|
---|
| 496 | _rnx->setReconnectFlag(false);
|
---|
| 497 | }
|
---|
[1555] | 498 | return success;
|
---|
[408] | 499 | }
|
---|
[1555] | 500 |
|
---|
| 501 | // Start a new query
|
---|
| 502 | // -----------------
|
---|
| 503 | if (!_rawInpFile) {
|
---|
| 504 |
|
---|
[138] | 505 | sleep(_nextSleep);
|
---|
[1555] | 506 | if (_nextSleep == 0) {
|
---|
| 507 | _nextSleep = 1;
|
---|
[138] | 508 | }
|
---|
| 509 | else {
|
---|
[1555] | 510 | _nextSleep = 2 * _nextSleep;
|
---|
[442] | 511 | if (_nextSleep > 256) {
|
---|
| 512 | _nextSleep = 256;
|
---|
[152] | 513 | }
|
---|
[1816] | 514 | #ifdef MLS_SOFTWARE
|
---|
[1817] | 515 | if (_nextSleep > 4) {
|
---|
| 516 | _nextSleep = 4;
|
---|
[1816] | 517 | }
|
---|
| 518 | #endif
|
---|
[138] | 519 | }
|
---|
[1555] | 520 |
|
---|
| 521 | delete _query;
|
---|
[1722] | 522 | if (_ntripVersion == "U") {
|
---|
[1721] | 523 | _query = new bncNetQueryUdp();
|
---|
| 524 | }
|
---|
[1722] | 525 | else if (_ntripVersion == "R") {
|
---|
[1555] | 526 | _query = new bncNetQueryRtp();
|
---|
| 527 | }
|
---|
[1744] | 528 | else if (_ntripVersion == "S") {
|
---|
[1753] | 529 | _query = new bncNetQueryS();
|
---|
[1744] | 530 | }
|
---|
[1621] | 531 | else if (_ntripVersion == "N") {
|
---|
| 532 | _query = new bncNetQueryV0();
|
---|
| 533 | }
|
---|
[1779] | 534 | else if (_ntripVersion == "UN") {
|
---|
| 535 | _query = new bncNetQueryUdp0();
|
---|
| 536 | }
|
---|
[1555] | 537 | else if (_ntripVersion == "2") {
|
---|
| 538 | _query = new bncNetQueryV2();
|
---|
| 539 | }
|
---|
| 540 | else {
|
---|
| 541 | _query = new bncNetQueryV1();
|
---|
| 542 | }
|
---|
[1710] | 543 | if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
|
---|
| 544 | QByteArray gga = ggaString(_latitude, _longitude, "100.0");
|
---|
[1555] | 545 | _query->startRequest(_mountPoint, gga);
|
---|
| 546 | }
|
---|
| 547 | else {
|
---|
| 548 | _query->startRequest(_mountPoint, "");
|
---|
| 549 | }
|
---|
| 550 | if (_query->status() != bncNetQuery::running) {
|
---|
| 551 | return failure;
|
---|
| 552 | }
|
---|
[138] | 553 | }
|
---|
[658] | 554 |
|
---|
[1555] | 555 | if (_rnx) {
|
---|
| 556 | _rnx->setReconnectFlag(true);
|
---|
[658] | 557 | }
|
---|
[1555] | 558 |
|
---|
| 559 | return success;
|
---|
[658] | 560 | }
|
---|
[1044] | 561 |
|
---|
[1555] | 562 | // RTCM scan output
|
---|
[1044] | 563 | //////////////////////////////////////////////////////////////////////////////
|
---|
[1555] | 564 | void bncGetThread::scanRTCM() {
|
---|
[1044] | 565 |
|
---|
[1555] | 566 | bncSettings settings;
|
---|
[1574] | 567 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
|
---|
| 568 |
|
---|
| 569 | if ( _miscMount == _staID || _miscMount == "ALL" ) {
|
---|
| 570 |
|
---|
[1575] | 571 | // RTCM message types
|
---|
| 572 | // ------------------
|
---|
[1574] | 573 | for (int ii = 0; ii <_decoder->_typeList.size(); ii++) {
|
---|
| 574 | QString type = QString("%1 ").arg(_decoder->_typeList[ii]);
|
---|
| 575 | emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
|
---|
| 576 | }
|
---|
[1044] | 577 |
|
---|
[1574] | 578 | // RTCMv3 antenna descriptor
|
---|
| 579 | // -------------------------
|
---|
| 580 | for (int ii=0;ii<_decoder->_antType.size();ii++) {
|
---|
| 581 | QString ant1 = QString("%1 ").arg(_decoder->_antType[ii]);
|
---|
| 582 | emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
|
---|
| 583 | }
|
---|
[1555] | 584 |
|
---|
[1575] | 585 | // RTCM Antenna Coordinates
|
---|
| 586 | // ------------------------
|
---|
[1574] | 587 | for (int ii=0; ii <_decoder->_antList.size(); ii++) {
|
---|
| 588 | QByteArray antT;
|
---|
| 589 | if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
| 590 | antT = "ARP";
|
---|
| 591 | }
|
---|
| 592 | else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
| 593 | antT = "APC";
|
---|
| 594 | }
|
---|
[1575] | 595 | QByteArray ant1, ant2, ant3;
|
---|
| 596 | ant1 = QString("%1 ").arg(_decoder->_antList[ii].xx,0,'f',4).toAscii();
|
---|
| 597 | ant2 = QString("%1 ").arg(_decoder->_antList[ii].yy,0,'f',4).toAscii();
|
---|
| 598 | ant3 = QString("%1 ").arg(_decoder->_antList[ii].zz,0,'f',4).toAscii();
|
---|
| 599 | emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
|
---|
| 600 | emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
|
---|
| 601 | emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
|
---|
| 602 | if (_decoder->_antList[ii].height_f) {
|
---|
| 603 | QByteArray ant4 = QString("%1 ").arg(_decoder->_antList[ii].height,0,'f',4).toAscii();
|
---|
| 604 | emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
|
---|
| 605 | }
|
---|
[1574] | 606 | emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
|
---|
| 607 | _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
---|
| 608 | antT));
|
---|
[1218] | 609 | }
|
---|
| 610 | }
|
---|
[1044] | 611 | }
|
---|
[1575] | 612 |
|
---|
[1770] | 613 | #ifdef MLS_SOFTWARE
|
---|
| 614 | for (int ii=0; ii <_decoder->_antList.size(); ii++) {
|
---|
| 615 | QByteArray antT;
|
---|
| 616 | if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
| 617 | antT = "ARP";
|
---|
| 618 | }
|
---|
| 619 | else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
| 620 | antT = "APC";
|
---|
| 621 | }
|
---|
| 622 | emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
|
---|
| 623 | _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
---|
| 624 | antT));
|
---|
| 625 | }
|
---|
| 626 | #endif
|
---|
| 627 |
|
---|
| 628 |
|
---|
| 629 |
|
---|
| 630 |
|
---|
[1555] | 631 | _decoder->_typeList.clear();
|
---|
| 632 | _decoder->_antType.clear();
|
---|
| 633 | _decoder->_antList.clear();
|
---|
[1044] | 634 | }
|
---|
[1555] | 635 |
|
---|
[1606] | 636 | // Handle Data from Serial Port
|
---|
| 637 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 638 | void bncGetThread::slotSerialReadyRead() {
|
---|
[1607] | 639 | if (_serialPort) {
|
---|
[1633] | 640 | int nb = _serialPort->bytesAvailable();
|
---|
| 641 | if (nb > 0) {
|
---|
| 642 | QByteArray data = _serialPort->read(nb);
|
---|
[1711] | 643 |
|
---|
| 644 | if (_serialNMEA == AUTO_NMEA) {
|
---|
[1725] | 645 | int i1 = data.indexOf("$GPGGA");
|
---|
| 646 | if (i1 != -1) {
|
---|
| 647 | int i2 = data.indexOf("*", i1);
|
---|
| 648 | if (i2 != -1 && data.size() > i2 + 1) {
|
---|
| 649 | QByteArray gga = data.mid(i1,i2-i1+3);
|
---|
| 650 | _query->sendNMEA(gga);
|
---|
| 651 | }
|
---|
| 652 | }
|
---|
[1711] | 653 | }
|
---|
| 654 |
|
---|
[1633] | 655 | if (_serialOutFile) {
|
---|
| 656 | _serialOutFile->write(data);
|
---|
| 657 | _serialOutFile->flush();
|
---|
| 658 | }
|
---|
[1607] | 659 | }
|
---|
| 660 | }
|
---|
[1606] | 661 | }
|
---|
[1768] | 662 |
|
---|
| 663 | //
|
---|
| 664 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 665 | void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
[1807] | 666 | RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
|
---|
| 667 | RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(_decoder);
|
---|
[1768] | 668 |
|
---|
[1807] | 669 | if ( decoder2 ) {
|
---|
[1768] | 670 | QMutexLocker locker(&_mutex);
|
---|
| 671 |
|
---|
| 672 | string storedPRN;
|
---|
| 673 | vector<int> IODs;
|
---|
| 674 |
|
---|
[1807] | 675 | if ( decoder2->storeEph(gpseph, storedPRN, IODs) ) {
|
---|
[1768] | 676 | #ifdef DEBUG_RTCM2_2021
|
---|
| 677 | QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
|
---|
| 678 |
|
---|
| 679 | for (unsigned ii = 0; ii < IODs.size(); ii++) {
|
---|
| 680 | msg += QString(" %1").arg(IODs[ii],4);
|
---|
| 681 | }
|
---|
| 682 |
|
---|
| 683 | emit(newMessage(msg.toAscii()));
|
---|
| 684 | #endif
|
---|
| 685 | }
|
---|
| 686 | }
|
---|
[1807] | 687 |
|
---|
| 688 | if ( decoder3 ) {
|
---|
| 689 | QMutexLocker locker(&_mutex);
|
---|
| 690 |
|
---|
| 691 | if ( decoder3->storeEph(gpseph) ) {
|
---|
[1813] | 692 | #ifdef DEBUG_RTCM3
|
---|
[1807] | 693 | QString msg = _staID + QString(": RTCM3Decoder, stored eph for satellite %1").arg(gpseph.satellite);
|
---|
| 694 | emit(newMessage(msg.toAscii(),true));
|
---|
[1813] | 695 | #endif
|
---|
[1807] | 696 | }
|
---|
| 697 | }
|
---|
[1768] | 698 | }
|
---|
| 699 |
|
---|