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