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