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