[280] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[280] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[280] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[280] | 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
[35] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
[93] | 26 | * BKG NTRIP Client
|
---|
[35] | 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncGetThread
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Thread that retrieves data from NTRIP caster
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 24-Dec-2005
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[277] | 41 | #include <stdlib.h>
|
---|
[1044] | 42 | #include <iomanip>
|
---|
[1218] | 43 | #include <sstream>
|
---|
[277] | 44 |
|
---|
[35] | 45 | #include <QFile>
|
---|
| 46 | #include <QTextStream>
|
---|
| 47 | #include <QtNetwork>
|
---|
[356] | 48 | #include <QTime>
|
---|
[35] | 49 |
|
---|
| 50 | #include "bncgetthread.h"
|
---|
[192] | 51 | #include "bnctabledlg.h"
|
---|
[243] | 52 | #include "bncapp.h"
|
---|
[352] | 53 | #include "bncutils.h"
|
---|
[408] | 54 | #include "bncrinex.h"
|
---|
[423] | 55 | #include "bnczerodecoder.h"
|
---|
[1621] | 56 | #include "bncnetqueryv0.h"
|
---|
[1387] | 57 | #include "bncnetqueryv1.h"
|
---|
| 58 | #include "bncnetqueryv2.h"
|
---|
[1410] | 59 | #include "bncnetqueryrtp.h"
|
---|
[1721] | 60 | #include "bncnetqueryudp.h"
|
---|
[1779] | 61 | #include "bncnetqueryudp0.h"
|
---|
[1753] | 62 | #include "bncnetquerys.h"
|
---|
[1535] | 63 | #include "bncsettings.h"
|
---|
[1558] | 64 | #include "latencychecker.h"
|
---|
[2035] | 65 | #include "bncpppclient.h"
|
---|
[3168] | 66 | #include "upload/bncrtnetdecoder.h"
|
---|
[243] | 67 | #include "RTCM/RTCM2Decoder.h"
|
---|
[297] | 68 | #include "RTCM3/RTCM3Decoder.h"
|
---|
[1310] | 69 | #include "GPSS/gpssDecoder.h"
|
---|
[3504] | 70 | #include "GPSS/hassDecoder.h"
|
---|
[1318] | 71 | #include "serial/qextserialport.h"
|
---|
[35] | 72 |
|
---|
| 73 | using namespace std;
|
---|
| 74 |
|
---|
[1143] | 75 | // Constructor 1
|
---|
[35] | 76 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2519] | 77 | bncGetThread::bncGetThread(bncRawFile* rawFile) {
|
---|
[1138] | 78 |
|
---|
[2519] | 79 | _rawFile = rawFile;
|
---|
| 80 | _format = rawFile->format();
|
---|
| 81 | _staID = rawFile->staID();
|
---|
| 82 | _rawOutput = false;
|
---|
[2390] | 83 | _ntripVersion = "N";
|
---|
| 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,
|
---|
[3494] | 95 | const QByteArray& ntripVersion,
|
---|
| 96 | const QByteArray& staIDextra) {
|
---|
[2519] | 97 | _rawFile = 0;
|
---|
[1555] | 98 | _mountPoint = mountPoint;
|
---|
[3003] | 99 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
[3494] | 100 | _staID_extra = staIDextra;
|
---|
[1555] | 101 | _format = format;
|
---|
| 102 | _latitude = latitude;
|
---|
| 103 | _longitude = longitude;
|
---|
| 104 | _nmea = nmea;
|
---|
[1353] | 105 | _ntripVersion = ntripVersion;
|
---|
[1139] | 106 |
|
---|
[2386] | 107 | bncSettings settings;
|
---|
| 108 | if (!settings.value("rawOutFile").toString().isEmpty()) {
|
---|
| 109 | _rawOutput = true;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[1139] | 112 | initialize();
|
---|
[3523] | 113 | initDecoder();
|
---|
[1139] | 114 | }
|
---|
| 115 |
|
---|
[1555] | 116 | // Initialization (common part of the constructor)
|
---|
[1143] | 117 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1139] | 118 | void bncGetThread::initialize() {
|
---|
| 119 |
|
---|
[1555] | 120 | setTerminationEnabled(true);
|
---|
| 121 |
|
---|
[1225] | 122 | bncApp* app = (bncApp*) qApp;
|
---|
| 123 |
|
---|
[1555] | 124 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 125 | app, SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 126 |
|
---|
[1525] | 127 | _isToBeDeleted = false;
|
---|
[1555] | 128 | _query = 0;
|
---|
| 129 | _nextSleep = 0;
|
---|
[2035] | 130 | _PPPclient = 0;
|
---|
[255] | 131 |
|
---|
[1574] | 132 | bncSettings settings;
|
---|
[1595] | 133 |
|
---|
[1574] | 134 | _miscMount = settings.value("miscMount").toString();
|
---|
| 135 |
|
---|
[408] | 136 | // RINEX writer
|
---|
| 137 | // ------------
|
---|
| 138 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
| 139 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
| 140 | _rnx = 0;
|
---|
| 141 | }
|
---|
| 142 | else {
|
---|
[3525] | 143 | _rnx = new bncRinex(_staID, _mountPoint, _latitude, _longitude,
|
---|
| 144 | _nmea, _ntripVersion);
|
---|
[408] | 145 | }
|
---|
| 146 |
|
---|
[1555] | 147 | // Serial Port
|
---|
| 148 | // -----------
|
---|
[1710] | 149 | _serialNMEA = NO_NMEA;
|
---|
| 150 | _serialOutFile = 0;
|
---|
| 151 | _serialPort = 0;
|
---|
| 152 |
|
---|
[1327] | 153 | if (settings.value("serialMountPoint").toString() == _staID) {
|
---|
[1710] | 154 | _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
|
---|
| 155 | _serialPort->setTimeout(0,100);
|
---|
| 156 |
|
---|
| 157 | // Baud Rate
|
---|
| 158 | // ---------
|
---|
[1330] | 159 | QString hlp = settings.value("serialBaudRate").toString();
|
---|
| 160 | if (hlp == "110") {
|
---|
| 161 | _serialPort->setBaudRate(BAUD110);
|
---|
| 162 | }
|
---|
| 163 | else if (hlp == "300") {
|
---|
| 164 | _serialPort->setBaudRate(BAUD300);
|
---|
| 165 | }
|
---|
| 166 | else if (hlp == "600") {
|
---|
| 167 | _serialPort->setBaudRate(BAUD600);
|
---|
| 168 | }
|
---|
| 169 | else if (hlp == "1200") {
|
---|
| 170 | _serialPort->setBaudRate(BAUD1200);
|
---|
| 171 | }
|
---|
| 172 | else if (hlp == "2400") {
|
---|
| 173 | _serialPort->setBaudRate(BAUD2400);
|
---|
| 174 | }
|
---|
| 175 | else if (hlp == "4800") {
|
---|
| 176 | _serialPort->setBaudRate(BAUD4800);
|
---|
| 177 | }
|
---|
| 178 | else if (hlp == "9600") {
|
---|
| 179 | _serialPort->setBaudRate(BAUD9600);
|
---|
| 180 | }
|
---|
| 181 | else if (hlp == "19200") {
|
---|
| 182 | _serialPort->setBaudRate(BAUD19200);
|
---|
| 183 | }
|
---|
| 184 | else if (hlp == "38400") {
|
---|
| 185 | _serialPort->setBaudRate(BAUD38400);
|
---|
| 186 | }
|
---|
| 187 | else if (hlp == "57600") {
|
---|
| 188 | _serialPort->setBaudRate(BAUD57600);
|
---|
| 189 | }
|
---|
| 190 | else if (hlp == "115200") {
|
---|
| 191 | _serialPort->setBaudRate(BAUD115200);
|
---|
| 192 | }
|
---|
[1710] | 193 |
|
---|
| 194 | // Parity
|
---|
| 195 | // ------
|
---|
[1330] | 196 | hlp = settings.value("serialParity").toString();
|
---|
| 197 | if (hlp == "NONE") {
|
---|
| 198 | _serialPort->setParity(PAR_NONE);
|
---|
| 199 | }
|
---|
| 200 | else if (hlp == "ODD") {
|
---|
| 201 | _serialPort->setParity(PAR_ODD);
|
---|
| 202 | }
|
---|
| 203 | else if (hlp == "EVEN") {
|
---|
| 204 | _serialPort->setParity(PAR_EVEN);
|
---|
| 205 | }
|
---|
| 206 | else if (hlp == "SPACE") {
|
---|
| 207 | _serialPort->setParity(PAR_SPACE);
|
---|
| 208 | }
|
---|
[1710] | 209 |
|
---|
| 210 | // Data Bits
|
---|
| 211 | // ---------
|
---|
[1330] | 212 | hlp = settings.value("serialDataBits").toString();
|
---|
| 213 | if (hlp == "5") {
|
---|
| 214 | _serialPort->setDataBits(DATA_5);
|
---|
| 215 | }
|
---|
| 216 | else if (hlp == "6") {
|
---|
| 217 | _serialPort->setDataBits(DATA_6);
|
---|
| 218 | }
|
---|
| 219 | else if (hlp == "7") {
|
---|
| 220 | _serialPort->setDataBits(DATA_7);
|
---|
| 221 | }
|
---|
| 222 | else if (hlp == "8") {
|
---|
| 223 | _serialPort->setDataBits(DATA_8);
|
---|
| 224 | }
|
---|
| 225 | hlp = settings.value("serialStopBits").toString();
|
---|
| 226 | if (hlp == "1") {
|
---|
| 227 | _serialPort->setStopBits(STOP_1);
|
---|
| 228 | }
|
---|
| 229 | else if (hlp == "2") {
|
---|
| 230 | _serialPort->setStopBits(STOP_2);
|
---|
| 231 | }
|
---|
[1710] | 232 |
|
---|
| 233 | // Flow Control
|
---|
| 234 | // ------------
|
---|
| 235 | hlp = settings.value("serialFlowControl").toString();
|
---|
[1711] | 236 | if (hlp == "XONXOFF") {
|
---|
[1710] | 237 | _serialPort->setFlowControl(FLOW_XONXOFF);
|
---|
| 238 | }
|
---|
| 239 | else if (hlp == "HARDWARE") {
|
---|
| 240 | _serialPort->setFlowControl(FLOW_HARDWARE);
|
---|
| 241 | }
|
---|
[1711] | 242 | else {
|
---|
| 243 | _serialPort->setFlowControl(FLOW_OFF);
|
---|
| 244 | }
|
---|
[1710] | 245 |
|
---|
| 246 | // Open Serial Port
|
---|
| 247 | // ----------------
|
---|
[1326] | 248 | _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
|
---|
[1331] | 249 | if (!_serialPort->isOpen()) {
|
---|
| 250 | delete _serialPort;
|
---|
| 251 | _serialPort = 0;
|
---|
[1451] | 252 | emit(newMessage((_staID + ": Cannot open serial port\n"), true));
|
---|
[1331] | 253 | }
|
---|
[1606] | 254 | connect(_serialPort, SIGNAL(readyRead()),
|
---|
| 255 | this, SLOT(slotSerialReadyRead()));
|
---|
| 256 |
|
---|
[1710] | 257 | // Automatic NMEA
|
---|
| 258 | // --------------
|
---|
| 259 | if (settings.value("serialAutoNMEA").toString() == "Auto") {
|
---|
| 260 | _serialNMEA = AUTO_NMEA;
|
---|
| 261 |
|
---|
| 262 | QString fName = settings.value("serialFileNMEA").toString();
|
---|
| 263 | if (!fName.isEmpty()) {
|
---|
| 264 | _serialOutFile = new QFile(fName);
|
---|
| 265 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 266 | _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 267 | }
|
---|
| 268 | else {
|
---|
| 269 | _serialOutFile->open(QIODevice::WriteOnly);
|
---|
| 270 | }
|
---|
[1634] | 271 | }
|
---|
[1606] | 272 | }
|
---|
[1710] | 273 |
|
---|
| 274 | // Manual NMEA
|
---|
| 275 | // -----------
|
---|
| 276 | else {
|
---|
| 277 | _serialNMEA = MANUAL_NMEA;
|
---|
[1636] | 278 | }
|
---|
[1318] | 279 | }
|
---|
| 280 |
|
---|
[2035] | 281 | // Initialize PPP Client?
|
---|
[2004] | 282 | // ----------------------
|
---|
[2290] | 283 | #ifndef MLS_SOFTWARE
|
---|
[2004] | 284 | if (settings.value("pppMount").toString() == _staID) {
|
---|
[2035] | 285 | _PPPclient = new bncPPPclient(_staID);
|
---|
[3027] | 286 | app->_bncPPPclient = _PPPclient;
|
---|
[2144] | 287 | qRegisterMetaType<bncTime>("bncTime");
|
---|
[2145] | 288 | connect(_PPPclient, SIGNAL(newPosition(bncTime, double, double, double)),
|
---|
| 289 | this, SIGNAL(newPosition(bncTime, double, double, double)));
|
---|
[2290] | 290 | connect(_PPPclient, SIGNAL(newNMEAstr(QByteArray)),
|
---|
| 291 | this, SIGNAL(newNMEAstr(QByteArray)));
|
---|
[2004] | 292 | }
|
---|
[2290] | 293 | #endif
|
---|
[1555] | 294 |
|
---|
[3523] | 295 | _latencyChecker = new latencyChecker(_staID);
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | // Instantiate the decoder
|
---|
| 299 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 300 | t_irc bncGetThread::initDecoder() {
|
---|
| 301 |
|
---|
[1744] | 302 | if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
|
---|
| 303 | _format.indexOf("RTCM 2") != -1 ) {
|
---|
[1555] | 304 | emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
|
---|
[3523] | 305 | _decoders[_staID] = new RTCM2Decoder(_staID.data());
|
---|
[1555] | 306 | }
|
---|
[1744] | 307 | else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
|
---|
| 308 | _format.indexOf("RTCM 3") != -1 ) {
|
---|
[1555] | 309 | emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
|
---|
[3523] | 310 | _decoders[_staID] = new RTCM3Decoder(_staID, _rawFile);
|
---|
| 311 | connect((RTCM3Decoder*) decoder(), SIGNAL(newMessage(QByteArray,bool)),
|
---|
[1555] | 312 | this, SIGNAL(newMessage(QByteArray,bool)));
|
---|
| 313 | }
|
---|
| 314 | else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
|
---|
| 315 | emit(newMessage(_staID + ": Get Data in GPSS format", true));
|
---|
[3523] | 316 | _decoders[_staID] = new gpssDecoder();
|
---|
[1555] | 317 | }
|
---|
| 318 | else if (_format.indexOf("ZERO") != -1) {
|
---|
| 319 | emit(newMessage(_staID + ": Get data in original format", true));
|
---|
[3523] | 320 | _decoders[_staID] = new bncZeroDecoder(_staID);
|
---|
[1555] | 321 | }
|
---|
[3168] | 322 | else if (_format.indexOf("RTNET") != -1) {
|
---|
| 323 | emit(newMessage(_staID + ": Get data in RTNet format", true));
|
---|
[3523] | 324 | _decoders[_staID] = new bncRtnetDecoder();
|
---|
[3168] | 325 | }
|
---|
[3509] | 326 | else if (_format.indexOf("HASS2ASCII") != -1) {
|
---|
[3517] | 327 | emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
|
---|
[3523] | 328 | _decoders[_staID] = new hassDecoder(_staID);
|
---|
[3504] | 329 | }
|
---|
[1555] | 330 | else {
|
---|
| 331 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
---|
| 332 | _isToBeDeleted = true;
|
---|
[3523] | 333 | return failure;
|
---|
[1555] | 334 | }
|
---|
| 335 |
|
---|
[319] | 336 | msleep(100); //sleep 0.1 sec
|
---|
[3523] | 337 |
|
---|
| 338 | return success;
|
---|
[35] | 339 | }
|
---|
| 340 |
|
---|
[3523] | 341 | // Current decoder in use
|
---|
| 342 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 343 | GPSDecoder* bncGetThread::decoder() {
|
---|
| 344 | if (_decoders.contains(_staID) || initDecoder() == success) {
|
---|
| 345 | return _decoders.value(_staID);
|
---|
| 346 | }
|
---|
| 347 | else {
|
---|
| 348 | return 0;
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[35] | 352 | // Destructor
|
---|
| 353 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 354 | bncGetThread::~bncGetThread() {
|
---|
[1928] | 355 | if (isRunning()) {
|
---|
| 356 | wait();
|
---|
| 357 | }
|
---|
[1527] | 358 | if (_query) {
|
---|
| 359 | _query->stop();
|
---|
[1708] | 360 | _query->deleteLater();
|
---|
[1527] | 361 | }
|
---|
[2035] | 362 | delete _PPPclient;
|
---|
[3523] | 363 | QMapIterator<QString, GPSDecoder*> it(_decoders);
|
---|
| 364 | while (it.hasNext()) {
|
---|
| 365 | it.next();
|
---|
| 366 | delete it.value();
|
---|
| 367 | }
|
---|
[1044] | 368 | delete _rnx;
|
---|
[2519] | 369 | delete _rawFile;
|
---|
[1607] | 370 | delete _serialOutFile;
|
---|
[1328] | 371 | delete _serialPort;
|
---|
[1557] | 372 | delete _latencyChecker;
|
---|
[1556] | 373 | emit getThreadFinished(_staID);
|
---|
[35] | 374 | }
|
---|
| 375 |
|
---|
[1390] | 376 | //
|
---|
| 377 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 378 | void bncGetThread::terminate() {
|
---|
[1525] | 379 | _isToBeDeleted = true;
|
---|
[1559] | 380 | if (!isRunning()) {
|
---|
| 381 | delete this;
|
---|
| 382 | }
|
---|
[1390] | 383 | }
|
---|
| 384 |
|
---|
[136] | 385 | // Run
|
---|
| 386 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 387 | void bncGetThread::run() {
|
---|
| 388 |
|
---|
[35] | 389 | while (true) {
|
---|
[629] | 390 | try {
|
---|
[1555] | 391 | if (_isToBeDeleted) {
|
---|
| 392 | QThread::exit(0);
|
---|
| 393 | this->deleteLater();
|
---|
| 394 | return;
|
---|
[629] | 395 | }
|
---|
[621] | 396 |
|
---|
[1555] | 397 | if (tryReconnect() != success) {
|
---|
[1572] | 398 | _latencyChecker->checkReconnect();
|
---|
[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;
|
---|
[2525] | 424 | QThread::exit(0);
|
---|
| 425 | this->deleteLater();
|
---|
| 426 | return;
|
---|
[1555] | 427 | }
|
---|
[1138] | 428 | }
|
---|
[1555] | 429 | qint64 nBytes = data.size();
|
---|
[1138] | 430 |
|
---|
[1555] | 431 | // Timeout, reconnect
|
---|
| 432 | // ------------------
|
---|
| 433 | if (nBytes == 0) {
|
---|
[1576] | 434 | _latencyChecker->checkReconnect();
|
---|
[1555] | 435 | emit(newMessage(_staID + ": Data timeout, reconnecting", true));
|
---|
[2355] | 436 | msleep(10000); //sleep 10 sec, G. Weber
|
---|
[1555] | 437 | continue;
|
---|
| 438 | }
|
---|
| 439 | else {
|
---|
[567] | 440 | emit newBytes(_staID, nBytes);
|
---|
[1555] | 441 | }
|
---|
[567] | 442 |
|
---|
[1555] | 443 | // Output Data
|
---|
| 444 | // -----------
|
---|
[2386] | 445 | if (_rawOutput) {
|
---|
| 446 | bncApp* app = (bncApp*) qApp;
|
---|
[2518] | 447 | app->writeRawData(data, _staID, _format);
|
---|
[2386] | 448 | }
|
---|
[2385] | 449 |
|
---|
[1555] | 450 | if (_serialPort) {
|
---|
[1633] | 451 | slotSerialReadyRead();
|
---|
[1555] | 452 | _serialPort->write(data);
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | // Decode Data
|
---|
| 456 | // -----------
|
---|
| 457 | vector<string> errmsg;
|
---|
[3526] | 458 | if (!decoder()) {
|
---|
| 459 | _isToBeDeleted = true;
|
---|
| 460 | continue;
|
---|
| 461 | }
|
---|
[3523] | 462 | decoder()->_obsList.clear();
|
---|
| 463 | t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
|
---|
[1137] | 464 |
|
---|
[1555] | 465 | // Perform various scans and checks
|
---|
| 466 | // --------------------------------
|
---|
[1562] | 467 | _latencyChecker->checkOutage(irc == success);
|
---|
[3523] | 468 | _latencyChecker->checkObsLatency(decoder()->_obsList);
|
---|
| 469 | _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
|
---|
[1567] | 470 |
|
---|
[1973] | 471 | emit newLatency(_staID, _latencyChecker->currentLatency());
|
---|
[1969] | 472 |
|
---|
[1555] | 473 | scanRTCM();
|
---|
[1138] | 474 |
|
---|
[1555] | 475 | // Loop over all observations (observations output)
|
---|
| 476 | // ------------------------------------------------
|
---|
[3523] | 477 | QListIterator<t_obs> it(decoder()->_obsList);
|
---|
[2711] | 478 | bool firstObs = true;
|
---|
[1555] | 479 | while (it.hasNext()) {
|
---|
[2711] | 480 | const t_obs& obs = it.next();
|
---|
| 481 |
|
---|
[3303] | 482 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 483 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
| 484 | long iSec = long(floor(obs.GPSWeeks+0.5));
|
---|
| 485 | long obsTime = obs.GPSWeek * 7*24*3600 + iSec;
|
---|
| 486 |
|
---|
[1555] | 487 | // Check observation epoch
|
---|
| 488 | // -----------------------
|
---|
[3523] | 489 | if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) {
|
---|
[3303] | 490 | int week;
|
---|
[1555] | 491 | double sec;
|
---|
| 492 | currentGPSWeeks(week, sec);
|
---|
[3304] | 493 | long currTime = week * 7*24*3600 + long(sec);
|
---|
[1555] | 494 | const double maxDt = 600.0;
|
---|
[3303] | 495 | if (fabs(currTime - obsTime) > maxDt) {
|
---|
[2308] | 496 | emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
|
---|
[1555] | 497 | continue;
|
---|
[940] | 498 | }
|
---|
[686] | 499 | }
|
---|
[1555] | 500 |
|
---|
[3305] | 501 | // Check observations coming twice (e.g. KOUR0 Problem)
|
---|
| 502 | // ----------------------------------------------------
|
---|
[3303] | 503 | QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
|
---|
[3306] | 504 | if (it != _prnLastEpo.end()) {
|
---|
[3302] | 505 | long oldTime = it.value();
|
---|
[3303] | 506 | if (obsTime < oldTime) {
|
---|
[3302] | 507 | emit( newMessage(_staID +
|
---|
| 508 | ": old observation " + prn.toAscii(), false));
|
---|
| 509 | continue;
|
---|
| 510 | }
|
---|
[3303] | 511 | else if (obsTime == oldTime) {
|
---|
[3302] | 512 | emit( newMessage(_staID +
|
---|
[3305] | 513 | ": observation coming more than once " + prn.toAscii(), false));
|
---|
[3302] | 514 | continue;
|
---|
| 515 | }
|
---|
[3301] | 516 | }
|
---|
[3306] | 517 | _prnLastEpo[prn] = obsTime;
|
---|
[3301] | 518 |
|
---|
[1555] | 519 | // RINEX Output
|
---|
| 520 | // ------------
|
---|
| 521 | if (_rnx) {
|
---|
| 522 | if (_samplingRate == 0 || iSec % _samplingRate == 0) {
|
---|
| 523 | _rnx->deepCopy(obs);
|
---|
[1271] | 524 | }
|
---|
[3525] | 525 | _rnx->dumpEpoch(_format, obsTime);
|
---|
[1271] | 526 | }
|
---|
[1555] | 527 |
|
---|
[2030] | 528 | // PPP Client
|
---|
| 529 | // ----------
|
---|
[2290] | 530 | #ifndef MLS_SOFTWARE
|
---|
[2035] | 531 | if (_PPPclient) {
|
---|
| 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;
|
---|
[1709] | 564 | if (_rnx) {
|
---|
| 565 | _rnx->setReconnectFlag(false);
|
---|
| 566 | }
|
---|
[1555] | 567 | return success;
|
---|
[408] | 568 | }
|
---|
[1555] | 569 |
|
---|
| 570 | // Start a new query
|
---|
| 571 | // -----------------
|
---|
[2519] | 572 | if (!_rawFile) {
|
---|
[1555] | 573 |
|
---|
[138] | 574 | sleep(_nextSleep);
|
---|
[1555] | 575 | if (_nextSleep == 0) {
|
---|
| 576 | _nextSleep = 1;
|
---|
[138] | 577 | }
|
---|
| 578 | else {
|
---|
[1555] | 579 | _nextSleep = 2 * _nextSleep;
|
---|
[442] | 580 | if (_nextSleep > 256) {
|
---|
| 581 | _nextSleep = 256;
|
---|
[152] | 582 | }
|
---|
[1816] | 583 | #ifdef MLS_SOFTWARE
|
---|
[1817] | 584 | if (_nextSleep > 4) {
|
---|
| 585 | _nextSleep = 4;
|
---|
[1816] | 586 | }
|
---|
| 587 | #endif
|
---|
[138] | 588 | }
|
---|
[1555] | 589 |
|
---|
| 590 | delete _query;
|
---|
[1722] | 591 | if (_ntripVersion == "U") {
|
---|
[1721] | 592 | _query = new bncNetQueryUdp();
|
---|
| 593 | }
|
---|
[1722] | 594 | else if (_ntripVersion == "R") {
|
---|
[1555] | 595 | _query = new bncNetQueryRtp();
|
---|
| 596 | }
|
---|
[1744] | 597 | else if (_ntripVersion == "S") {
|
---|
[1753] | 598 | _query = new bncNetQueryS();
|
---|
[1744] | 599 | }
|
---|
[1621] | 600 | else if (_ntripVersion == "N") {
|
---|
| 601 | _query = new bncNetQueryV0();
|
---|
| 602 | }
|
---|
[1779] | 603 | else if (_ntripVersion == "UN") {
|
---|
| 604 | _query = new bncNetQueryUdp0();
|
---|
| 605 | }
|
---|
[1555] | 606 | else if (_ntripVersion == "2") {
|
---|
[3337] | 607 | _query = new bncNetQueryV2(false);
|
---|
[1555] | 608 | }
|
---|
[3334] | 609 | else if (_ntripVersion == "2s") {
|
---|
[3337] | 610 | _query = new bncNetQueryV2(true);
|
---|
[3334] | 611 | }
|
---|
[1555] | 612 | else {
|
---|
| 613 | _query = new bncNetQueryV1();
|
---|
| 614 | }
|
---|
[1710] | 615 | if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
|
---|
| 616 | QByteArray gga = ggaString(_latitude, _longitude, "100.0");
|
---|
[1555] | 617 | _query->startRequest(_mountPoint, gga);
|
---|
| 618 | }
|
---|
| 619 | else {
|
---|
| 620 | _query->startRequest(_mountPoint, "");
|
---|
| 621 | }
|
---|
| 622 | if (_query->status() != bncNetQuery::running) {
|
---|
| 623 | return failure;
|
---|
| 624 | }
|
---|
[138] | 625 | }
|
---|
[658] | 626 |
|
---|
[1555] | 627 | if (_rnx) {
|
---|
| 628 | _rnx->setReconnectFlag(true);
|
---|
[658] | 629 | }
|
---|
[1555] | 630 |
|
---|
| 631 | return success;
|
---|
[658] | 632 | }
|
---|
[1044] | 633 |
|
---|
[1555] | 634 | // RTCM scan output
|
---|
[1044] | 635 | //////////////////////////////////////////////////////////////////////////////
|
---|
[1555] | 636 | void bncGetThread::scanRTCM() {
|
---|
[1044] | 637 |
|
---|
[1555] | 638 | bncSettings settings;
|
---|
[1574] | 639 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
|
---|
| 640 |
|
---|
| 641 | if ( _miscMount == _staID || _miscMount == "ALL" ) {
|
---|
| 642 |
|
---|
[1575] | 643 | // RTCM message types
|
---|
| 644 | // ------------------
|
---|
[3523] | 645 | for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
|
---|
| 646 | QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
|
---|
[1574] | 647 | emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
|
---|
| 648 | }
|
---|
[1044] | 649 |
|
---|
[1574] | 650 | // RTCMv3 antenna descriptor
|
---|
| 651 | // -------------------------
|
---|
[3523] | 652 | for (int ii=0;ii<decoder()->_antType.size();ii++) {
|
---|
| 653 | QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
|
---|
[1574] | 654 | emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
|
---|
| 655 | }
|
---|
[1555] | 656 |
|
---|
[1575] | 657 | // RTCM Antenna Coordinates
|
---|
| 658 | // ------------------------
|
---|
[3523] | 659 | for (int ii=0; ii <decoder()->_antList.size(); ii++) {
|
---|
[1574] | 660 | QByteArray antT;
|
---|
[3523] | 661 | if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
[1574] | 662 | antT = "ARP";
|
---|
| 663 | }
|
---|
[3523] | 664 | else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
[1574] | 665 | antT = "APC";
|
---|
| 666 | }
|
---|
[1575] | 667 | QByteArray ant1, ant2, ant3;
|
---|
[3523] | 668 | ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
|
---|
| 669 | ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
|
---|
| 670 | ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
|
---|
[1575] | 671 | emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
|
---|
| 672 | emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
|
---|
| 673 | emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
|
---|
[3523] | 674 | if (decoder()->_antList[ii].height_f) {
|
---|
| 675 | QByteArray ant4 = QString("%1 ").arg(decoder()->_antList[ii].height,0,'f',4).toAscii();
|
---|
[1575] | 676 | emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
|
---|
| 677 | }
|
---|
[3523] | 678 | emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
|
---|
| 679 | decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
|
---|
[1574] | 680 | antT));
|
---|
[1218] | 681 | }
|
---|
| 682 | }
|
---|
[1044] | 683 | }
|
---|
[1575] | 684 |
|
---|
[1770] | 685 | #ifdef MLS_SOFTWARE
|
---|
[3523] | 686 | for (int ii=0; ii <decoder()->_antList.size(); ii++) {
|
---|
[1770] | 687 | QByteArray antT;
|
---|
[3523] | 688 | if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
[1770] | 689 | antT = "ARP";
|
---|
| 690 | }
|
---|
[3523] | 691 | else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
[1770] | 692 | antT = "APC";
|
---|
| 693 | }
|
---|
[3523] | 694 | emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
|
---|
| 695 | decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
|
---|
[1770] | 696 | antT));
|
---|
| 697 | }
|
---|
[2356] | 698 |
|
---|
[3523] | 699 | for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
|
---|
| 700 | emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
|
---|
[2356] | 701 | }
|
---|
[1770] | 702 | #endif
|
---|
| 703 |
|
---|
| 704 |
|
---|
| 705 |
|
---|
| 706 |
|
---|
[3523] | 707 | decoder()->_typeList.clear();
|
---|
| 708 | decoder()->_antType.clear();
|
---|
| 709 | decoder()->_antList.clear();
|
---|
[1044] | 710 | }
|
---|
[1555] | 711 |
|
---|
[1606] | 712 | // Handle Data from Serial Port
|
---|
| 713 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 714 | void bncGetThread::slotSerialReadyRead() {
|
---|
[1607] | 715 | if (_serialPort) {
|
---|
[1633] | 716 | int nb = _serialPort->bytesAvailable();
|
---|
| 717 | if (nb > 0) {
|
---|
| 718 | QByteArray data = _serialPort->read(nb);
|
---|
[1711] | 719 |
|
---|
| 720 | if (_serialNMEA == AUTO_NMEA) {
|
---|
[1725] | 721 | int i1 = data.indexOf("$GPGGA");
|
---|
| 722 | if (i1 != -1) {
|
---|
| 723 | int i2 = data.indexOf("*", i1);
|
---|
| 724 | if (i2 != -1 && data.size() > i2 + 1) {
|
---|
| 725 | QByteArray gga = data.mid(i1,i2-i1+3);
|
---|
| 726 | _query->sendNMEA(gga);
|
---|
| 727 | }
|
---|
| 728 | }
|
---|
[1711] | 729 | }
|
---|
| 730 |
|
---|
[1633] | 731 | if (_serialOutFile) {
|
---|
| 732 | _serialOutFile->write(data);
|
---|
| 733 | _serialOutFile->flush();
|
---|
| 734 | }
|
---|
[1607] | 735 | }
|
---|
| 736 | }
|
---|
[1606] | 737 | }
|
---|
[1768] | 738 |
|
---|
| 739 | //
|
---|
| 740 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 741 | void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
[3523] | 742 | RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(decoder());
|
---|
| 743 | RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(decoder());
|
---|
[1768] | 744 |
|
---|
[1807] | 745 | if ( decoder2 ) {
|
---|
[1768] | 746 | QMutexLocker locker(&_mutex);
|
---|
| 747 |
|
---|
| 748 | string storedPRN;
|
---|
| 749 | vector<int> IODs;
|
---|
| 750 |
|
---|
[1807] | 751 | if ( decoder2->storeEph(gpseph, storedPRN, IODs) ) {
|
---|
[1768] | 752 | #ifdef DEBUG_RTCM2_2021
|
---|
| 753 | QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
|
---|
| 754 |
|
---|
| 755 | for (unsigned ii = 0; ii < IODs.size(); ii++) {
|
---|
| 756 | msg += QString(" %1").arg(IODs[ii],4);
|
---|
| 757 | }
|
---|
| 758 |
|
---|
| 759 | emit(newMessage(msg.toAscii()));
|
---|
| 760 | #endif
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
[1807] | 763 |
|
---|
| 764 | if ( decoder3 ) {
|
---|
| 765 | QMutexLocker locker(&_mutex);
|
---|
| 766 |
|
---|
| 767 | if ( decoder3->storeEph(gpseph) ) {
|
---|
[1813] | 768 | #ifdef DEBUG_RTCM3
|
---|
[1807] | 769 | QString msg = _staID + QString(": RTCM3Decoder, stored eph for satellite %1").arg(gpseph.satellite);
|
---|
| 770 | emit(newMessage(msg.toAscii(),true));
|
---|
[1813] | 771 | #endif
|
---|
[1807] | 772 | }
|
---|
| 773 | }
|
---|
[1768] | 774 | }
|
---|
| 775 |
|
---|