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