source: ntrip/trunk/BNC/src/bncgetthread.cpp@ 6770

Last change on this file since 6770 was 6770, checked in by stuerze, 9 years ago

add initial GGA string for NMEA auto mode

File size: 24.9 KB
RevLine 
[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>
[5524]47#include <QMutex>
[35]48#include <QtNetwork>
[356]49#include <QTime>
[35]50
51#include "bncgetthread.h"
[192]52#include "bnctabledlg.h"
[5070]53#include "bnccore.h"
[352]54#include "bncutils.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"
[3168]65#include "upload/bncrtnetdecoder.h"
[243]66#include "RTCM/RTCM2Decoder.h"
[297]67#include "RTCM3/RTCM3Decoder.h"
[1318]68#include "serial/qextserialport.h"
[35]69
70using namespace std;
71
[1143]72// Constructor 1
[35]73////////////////////////////////////////////////////////////////////////////
[2519]74bncGetThread::bncGetThread(bncRawFile* rawFile) {
[1138]75
[2519]76 _rawFile = rawFile;
77 _format = rawFile->format();
[3548]78 _staID = rawFile->staID();
[2519]79 _rawOutput = false;
[2390]80 _ntripVersion = "N";
81
[1555]82 initialize();
[1138]83}
84
[1143]85// Constructor 2
86////////////////////////////////////////////////////////////////////////////
[278]87bncGetThread::bncGetThread(const QUrl& mountPoint,
[366]88 const QByteArray& format,
89 const QByteArray& latitude,
90 const QByteArray& longitude,
[1353]91 const QByteArray& nmea,
[3527]92 const QByteArray& ntripVersion) {
[2519]93 _rawFile = 0;
[1555]94 _mountPoint = mountPoint;
[3003]95 _staID = mountPoint.path().mid(1).toAscii();
[1555]96 _format = format;
97 _latitude = latitude;
98 _longitude = longitude;
99 _nmea = nmea;
[1353]100 _ntripVersion = ntripVersion;
[1139]101
[2386]102 bncSettings settings;
103 if (!settings.value("rawOutFile").toString().isEmpty()) {
104 _rawOutput = true;
[3734]105 } else {
106 _rawOutput = false;
[2386]107 }
108
[1139]109 initialize();
[3523]110 initDecoder();
[1139]111}
112
[1555]113// Initialization (common part of the constructor)
[1143]114////////////////////////////////////////////////////////////////////////////
[1139]115void bncGetThread::initialize() {
116
[3528]117 bncSettings settings;
118
[1555]119 setTerminationEnabled(true);
120
121 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[5068]122 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[1555]123
[1525]124 _isToBeDeleted = false;
[1555]125 _query = 0;
126 _nextSleep = 0;
[3528]127 _miscMount = settings.value("miscMount").toString();
[3560]128 _decoder = 0;
[255]129
[1555]130 // Serial Port
131 // -----------
[1710]132 _serialNMEA = NO_NMEA;
133 _serialOutFile = 0;
134 _serialPort = 0;
135
[3532]136 if (!_staID.isEmpty() &&
137 settings.value("serialMountPoint").toString() == _staID) {
[1710]138 _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
139 _serialPort->setTimeout(0,100);
140
141 // Baud Rate
142 // ---------
[1330]143 QString hlp = settings.value("serialBaudRate").toString();
144 if (hlp == "110") {
145 _serialPort->setBaudRate(BAUD110);
146 }
147 else if (hlp == "300") {
148 _serialPort->setBaudRate(BAUD300);
149 }
150 else if (hlp == "600") {
151 _serialPort->setBaudRate(BAUD600);
152 }
153 else if (hlp == "1200") {
154 _serialPort->setBaudRate(BAUD1200);
155 }
156 else if (hlp == "2400") {
157 _serialPort->setBaudRate(BAUD2400);
158 }
159 else if (hlp == "4800") {
160 _serialPort->setBaudRate(BAUD4800);
161 }
162 else if (hlp == "9600") {
163 _serialPort->setBaudRate(BAUD9600);
164 }
165 else if (hlp == "19200") {
166 _serialPort->setBaudRate(BAUD19200);
167 }
168 else if (hlp == "38400") {
169 _serialPort->setBaudRate(BAUD38400);
170 }
171 else if (hlp == "57600") {
172 _serialPort->setBaudRate(BAUD57600);
173 }
174 else if (hlp == "115200") {
175 _serialPort->setBaudRate(BAUD115200);
176 }
[1710]177
178 // Parity
179 // ------
[1330]180 hlp = settings.value("serialParity").toString();
181 if (hlp == "NONE") {
182 _serialPort->setParity(PAR_NONE);
183 }
184 else if (hlp == "ODD") {
185 _serialPort->setParity(PAR_ODD);
186 }
187 else if (hlp == "EVEN") {
188 _serialPort->setParity(PAR_EVEN);
189 }
190 else if (hlp == "SPACE") {
191 _serialPort->setParity(PAR_SPACE);
192 }
[1710]193
194 // Data Bits
195 // ---------
[1330]196 hlp = settings.value("serialDataBits").toString();
197 if (hlp == "5") {
198 _serialPort->setDataBits(DATA_5);
199 }
200 else if (hlp == "6") {
201 _serialPort->setDataBits(DATA_6);
202 }
203 else if (hlp == "7") {
204 _serialPort->setDataBits(DATA_7);
205 }
206 else if (hlp == "8") {
207 _serialPort->setDataBits(DATA_8);
208 }
209 hlp = settings.value("serialStopBits").toString();
210 if (hlp == "1") {
211 _serialPort->setStopBits(STOP_1);
212 }
213 else if (hlp == "2") {
214 _serialPort->setStopBits(STOP_2);
215 }
[1710]216
217 // Flow Control
218 // ------------
219 hlp = settings.value("serialFlowControl").toString();
[1711]220 if (hlp == "XONXOFF") {
[1710]221 _serialPort->setFlowControl(FLOW_XONXOFF);
222 }
223 else if (hlp == "HARDWARE") {
224 _serialPort->setFlowControl(FLOW_HARDWARE);
225 }
[1711]226 else {
227 _serialPort->setFlowControl(FLOW_OFF);
228 }
[1710]229
230 // Open Serial Port
231 // ----------------
[1326]232 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
[1331]233 if (!_serialPort->isOpen()) {
234 delete _serialPort;
235 _serialPort = 0;
[1451]236 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
[1331]237 }
[1606]238 connect(_serialPort, SIGNAL(readyRead()),
239 this, SLOT(slotSerialReadyRead()));
240
[1710]241 // Automatic NMEA
242 // --------------
243 if (settings.value("serialAutoNMEA").toString() == "Auto") {
244 _serialNMEA = AUTO_NMEA;
245
246 QString fName = settings.value("serialFileNMEA").toString();
247 if (!fName.isEmpty()) {
248 _serialOutFile = new QFile(fName);
249 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
250 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
251 }
252 else {
253 _serialOutFile->open(QIODevice::WriteOnly);
254 }
[1634]255 }
[1606]256 }
[1710]257
258 // Manual NMEA
259 // -----------
[6685]260 if (settings.value("serialAutoNMEA").toString() == "Manual") {
[1710]261 _serialNMEA = MANUAL_NMEA;
[6751]262 bncSettings settings;
263 _manualNMEASampl = settings.value("serialManualNMEASampling").toInt();
264 QString hlp = settings.value("serialHeightNMEA").toString();
265 if (hlp.isEmpty()) {
266 hlp = "0.0";
267 }
268 QByteArray _serialHeightNMEA = hlp.toAscii();
269 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA);
[1636]270 }
[1318]271 }
272
[3532]273 if (!_staID.isEmpty()) {
274 _latencyChecker = new latencyChecker(_staID);
[2004]275 }
[3532]276 else {
277 _latencyChecker = 0;
278 }
[3523]279}
280
281// Instantiate the decoder
282//////////////////////////////////////////////////////////////////////////////
283t_irc bncGetThread::initDecoder() {
284
[3560]285 _decoder = 0;
286
[1744]287 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
288 _format.indexOf("RTCM 2") != -1 ) {
[1555]289 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
[3560]290 _decoder = new RTCM2Decoder(_staID.data());
[1555]291 }
[1744]292 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
293 _format.indexOf("RTCM 3") != -1 ) {
[1555]294 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
[3558]295 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
[3560]296 _decoder = newDecoder;
[3558]297 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
[1555]298 this, SIGNAL(newMessage(QByteArray,bool)));
299 }
300 else if (_format.indexOf("ZERO") != -1) {
301 emit(newMessage(_staID + ": Get data in original format", true));
[3560]302 _decoder = new bncZeroDecoder(_staID);
[1555]303 }
[3168]304 else if (_format.indexOf("RTNET") != -1) {
305 emit(newMessage(_staID + ": Get data in RTNet format", true));
[3560]306 _decoder = new bncRtnetDecoder();
[3168]307 }
[1555]308 else {
309 emit(newMessage(_staID + ": Unknown data format " + _format, true));
310 _isToBeDeleted = true;
[3523]311 return failure;
[1555]312 }
313
[319]314 msleep(100); //sleep 0.1 sec
[3523]315
[3560]316 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
317 _nmea, _ntripVersion);
318
319 if (_rawFile) {
320 _decodersRaw[_staID] = _decoder;
[3530]321 }
322
[3523]323 return success;
[35]324}
325
[3523]326// Current decoder in use
327////////////////////////////////////////////////////////////////////////////
328GPSDecoder* bncGetThread::decoder() {
[3560]329 if (!_rawFile) {
330 return _decoder;
[3523]331 }
332 else {
[3560]333 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
334 return _decodersRaw[_staID];
335 }
[3523]336 }
[3560]337 return 0;
[3523]338}
339
[35]340// Destructor
341////////////////////////////////////////////////////////////////////////////
342bncGetThread::~bncGetThread() {
[1928]343 if (isRunning()) {
344 wait();
345 }
[1527]346 if (_query) {
347 _query->stop();
[1708]348 _query->deleteLater();
[1527]349 }
[3560]350 if (_rawFile) {
351 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
352 while (it.hasNext()) {
353 it.next();
354 delete it.value();
355 }
[3523]356 }
[3560]357 else {
358 delete _decoder;
359 }
[2519]360 delete _rawFile;
[1607]361 delete _serialOutFile;
[1328]362 delete _serialPort;
[1557]363 delete _latencyChecker;
[1556]364 emit getThreadFinished(_staID);
[35]365}
366
[1390]367//
368////////////////////////////////////////////////////////////////////////////
369void bncGetThread::terminate() {
[1525]370 _isToBeDeleted = true;
[1559]371 if (!isRunning()) {
372 delete this;
373 }
[1390]374}
375
[136]376// Run
377////////////////////////////////////////////////////////////////////////////
378void bncGetThread::run() {
379
[35]380 while (true) {
[629]381 try {
[1555]382 if (_isToBeDeleted) {
383 QThread::exit(0);
384 this->deleteLater();
385 return;
[629]386 }
[621]387
[1555]388 if (tryReconnect() != success) {
[3532]389 if (_latencyChecker) {
390 _latencyChecker->checkReconnect();
391 }
[1555]392 continue;
[621]393 }
[1555]394
395 // Delete old observations
396 // -----------------------
[3560]397 if (_rawFile) {
398 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
399 while (itDec.hasNext()) {
400 itDec.next();
401 GPSDecoder* decoder = itDec.value();
402 decoder->_obsList.clear();
403 }
[3515]404 }
[3560]405 else {
406 _decoder->_obsList.clear();
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
[5903]420 QCoreApplication::processEvents();
421
[1555]422 if (data.isEmpty()) {
423 cout << "no more data" << endl;
[5068]424 BNC_CORE->stopCombination();
[5900]425 BNC_CORE->stopPPP();
[5903]426 ::exit(0);
[1555]427 }
[1138]428 }
[1555]429 qint64 nBytes = data.size();
[1138]430
[1555]431 // Timeout, reconnect
432 // ------------------
433 if (nBytes == 0) {
[3532]434 if (_latencyChecker) {
435 _latencyChecker->checkReconnect();
436 }
[1555]437 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
[2355]438 msleep(10000); //sleep 10 sec, G. Weber
[1555]439 continue;
440 }
441 else {
[567]442 emit newBytes(_staID, nBytes);
[5648]443 emit newRawData(_staID, data);
[1555]444 }
[567]445
[1555]446 // Output Data
447 // -----------
[2386]448 if (_rawOutput) {
[5068]449 BNC_CORE->writeRawData(data, _staID, _format);
[2386]450 }
[2385]451
[1555]452 if (_serialPort) {
[1633]453 slotSerialReadyRead();
[1555]454 _serialPort->write(data);
455 }
[5647]456
[1555]457 // Decode Data
458 // -----------
459 vector<string> errmsg;
[3526]460 if (!decoder()) {
461 _isToBeDeleted = true;
462 continue;
463 }
[3523]464 decoder()->_obsList.clear();
465 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
[1137]466
[1555]467 // Perform various scans and checks
468 // --------------------------------
[3532]469 if (_latencyChecker) {
470 _latencyChecker->checkOutage(irc == success);
471 _latencyChecker->checkObsLatency(decoder()->_obsList);
472 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
473
474 emit newLatency(_staID, _latencyChecker->currentLatency());
475 }
[1567]476
[1555]477 scanRTCM();
[1138]478
[1555]479 // Loop over all observations (observations output)
480 // ------------------------------------------------
[6137]481 QListIterator<t_satObs> it(decoder()->_obsList);
[5524]482
[6137]483 QList<t_satObs> obsListHlp;
[5524]484
[1555]485 while (it.hasNext()) {
[6137]486 const t_satObs& obs = it.next();
[2711]487
[6137]488 QString prn(obs._prn.toString().c_str());
489 long iSec = long(floor(obs._time.gpssec()+0.5));
490 long obsTime = obs._time.gpsw()*7*24*3600 + iSec;
[3303]491
[1555]492 // Check observation epoch
493 // -----------------------
[5739]494 if (!_rawFile) {
[3303]495 int week;
[1555]496 double sec;
497 currentGPSWeeks(week, sec);
[3304]498 long currTime = week * 7*24*3600 + long(sec);
[1555]499 const double maxDt = 600.0;
[3303]500 if (fabs(currTime - obsTime) > maxDt) {
[2308]501 emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
[1555]502 continue;
[940]503 }
[686]504 }
[1555]505
[3305]506 // Check observations coming twice (e.g. KOUR0 Problem)
507 // ----------------------------------------------------
[3535]508 if (!_rawFile) {
509 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
510 if (it != _prnLastEpo.end()) {
511 long oldTime = it.value();
512 if (obsTime < oldTime) {
513 emit( newMessage(_staID +
514 ": old observation " + prn.toAscii(), false));
515 continue;
516 }
517 else if (obsTime == oldTime) {
518 emit( newMessage(_staID +
519 ": observation coming more than once " + prn.toAscii(), false));
520 continue;
521 }
[3302]522 }
[3535]523 _prnLastEpo[prn] = obsTime;
[3301]524 }
525
[3528]526 decoder()->dumpRinexEpoch(obs, _format);
527
[5524]528 // Save observations
529 // -----------------
530 obsListHlp.append(obs);
531 }
[2030]532
[5524]533 // Emit signal
534 // -----------
535 if (!_isToBeDeleted && obsListHlp.size() > 0) {
536 emit newObs(_staID, obsListHlp);
[249]537 }
[5524]538
[3523]539 decoder()->_obsList.clear();
[35]540 }
[3311]541 catch (Exception& exc) {
542 emit(newMessage(_staID + " " + exc.what(), true));
543 _isToBeDeleted = true;
544 }
[1555]545 catch (...) {
[3311]546 emit(newMessage(_staID + " bncGetThread exception", true));
[1559]547 _isToBeDeleted = true;
[1555]548 }
[35]549 }
550}
551
[136]552// Try Re-Connect
553////////////////////////////////////////////////////////////////////////////
[1555]554t_irc bncGetThread::tryReconnect() {
555
556 // Easy Return
557 // -----------
558 if (_query && _query->status() == bncNetQuery::running) {
559 _nextSleep = 0;
[3560]560 if (_rawFile) {
561 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
562 while (itDec.hasNext()) {
563 itDec.next();
564 GPSDecoder* decoder = itDec.value();
565 decoder->setRinexReconnectFlag(false);
566 }
[1709]567 }
[3560]568 else {
569 _decoder->setRinexReconnectFlag(false);
570 }
[1555]571 return success;
[408]572 }
[1555]573
574 // Start a new query
575 // -----------------
[2519]576 if (!_rawFile) {
[1555]577
[138]578 sleep(_nextSleep);
[1555]579 if (_nextSleep == 0) {
580 _nextSleep = 1;
[138]581 }
582 else {
[1555]583 _nextSleep = 2 * _nextSleep;
[442]584 if (_nextSleep > 256) {
585 _nextSleep = 256;
[152]586 }
[1816]587#ifdef MLS_SOFTWARE
[1817]588 if (_nextSleep > 4) {
589 _nextSleep = 4;
[1816]590 }
591#endif
[138]592 }
[1555]593
594 delete _query;
[1722]595 if (_ntripVersion == "U") {
[1721]596 _query = new bncNetQueryUdp();
597 }
[1722]598 else if (_ntripVersion == "R") {
[1555]599 _query = new bncNetQueryRtp();
600 }
[1744]601 else if (_ntripVersion == "S") {
[1753]602 _query = new bncNetQueryS();
[1744]603 }
[1621]604 else if (_ntripVersion == "N") {
605 _query = new bncNetQueryV0();
606 }
[1779]607 else if (_ntripVersion == "UN") {
608 _query = new bncNetQueryUdp0();
609 }
[1555]610 else if (_ntripVersion == "2") {
[3337]611 _query = new bncNetQueryV2(false);
[1555]612 }
[3334]613 else if (_ntripVersion == "2s") {
[3337]614 _query = new bncNetQueryV2(true);
[3334]615 }
[1555]616 else {
617 _query = new bncNetQueryV1();
618 }
[6770]619 if (_nmea == "yes") {
620 if (_serialNMEA == MANUAL_NMEA) {
621 _query->startRequest(_mountPoint, _manualNMEAString);
622 _lastManualNMEA = QDateTime::currentDateTime();
623 }
624 else if (_serialNMEA == AUTO_NMEA) {
625 if (_serialPort) {
626 int nb = _serialPort->bytesAvailable();
627 if (nb > 0) {
628 QByteArray data = _serialPort->read(nb);
629 int i1 = data.indexOf("$GPGGA");
630 if (i1 == -1) {
631 i1 = data.indexOf("$GNGGA");
632 }
633 if (i1 != -1) {
634 int i2 = data.indexOf("*", i1);
635 if (i2 != -1 && data.size() > i2 + 1) {
636 QByteArray gga = data.mid(i1, i2 - i1 + 3);
637 _query->startRequest(_mountPoint, gga);
638 }
639 }
640 }
641 }
642 }
[1555]643 }
644 else {
645 _query->startRequest(_mountPoint, "");
646 }
[6770]647
[1555]648 if (_query->status() != bncNetQuery::running) {
649 return failure;
650 }
[138]651 }
[658]652
[3560]653 if (_rawFile) {
654 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
655 while (itDec.hasNext()) {
656 itDec.next();
657 GPSDecoder* decoder = itDec.value();
658 decoder->setRinexReconnectFlag(false);
659 }
[658]660 }
[3560]661 else {
662 _decoder->setRinexReconnectFlag(false);
663 }
[1555]664
665 return success;
[658]666}
[1044]667
[1555]668// RTCM scan output
[1044]669//////////////////////////////////////////////////////////////////////////////
[1555]670void bncGetThread::scanRTCM() {
[1044]671
[4476]672 if ( !decoder() ) {
[3558]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" ) {
[1575]680 // RTCM message types
681 // ------------------
[4476]682 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
[3523]683 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
[1574]684 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
685 }
[1044]686
[4476]687 // Check Observation Types
688 // -----------------------
689 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
[6137]690 t_satObs& obs = decoder()->_obsList[ii];
691 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
[4476]692 bool allFound = true;
[6137]693 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
[6579]694 if (obs._obs[iFrq]->_codeValid) {
695 QString rnxStr('C');
696 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]697 if (_format.indexOf("RTCM_2") != -1 ||
698 _format.indexOf("RTCM2") != -1 ||
699 _format.indexOf("RTCM 2") != -1 ) {
700 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
701 }
[6579]702 if (rnxTypes.indexOf(rnxStr) == -1) {
703 rnxTypes.push_back(rnxStr);
704 allFound = false;
705 }
[4476]706 }
[6579]707 if (obs._obs[iFrq]->_phaseValid) {
708 QString rnxStr('L');
709 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]710 if (_format.indexOf("RTCM_2") != -1 ||
711 _format.indexOf("RTCM2") != -1 ||
712 _format.indexOf("RTCM 2") != -1 ) {
713 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
714 }
[6579]715 if (rnxTypes.indexOf(rnxStr) == -1) {
716 rnxTypes.push_back(rnxStr);
717 allFound = false;
718 }
719 }
720 if (obs._obs[iFrq]->_dopplerValid){
721 QString rnxStr('D');
722 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]723 if (_format.indexOf("RTCM_2") != -1 ||
724 _format.indexOf("RTCM2") != -1 ||
725 _format.indexOf("RTCM 2") != -1 ) {
726 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
727 }
[6579]728 if (rnxTypes.indexOf(rnxStr) == -1) {
729 rnxTypes.push_back(rnxStr);
730 allFound = false;
731 }
732 }
733 if (obs._obs[iFrq]->_snrValid){
734 QString rnxStr('S');
735 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]736 if (_format.indexOf("RTCM_2") != -1 ||
737 _format.indexOf("RTCM2") != -1 ||
738 _format.indexOf("RTCM 2") != -1 ) {
739 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
740 }
[6579]741 if (rnxTypes.indexOf(rnxStr) == -1) {
742 rnxTypes.push_back(rnxStr);
743 allFound = false;
744 }
745 }
[4476]746 }
747 if (!allFound) {
[4477]748 QString msg;
749 QTextStream str(&msg);
[6579]750 QString s;
751 str << obs._prn.system() << " " << s.sprintf("%2d", rnxTypes.size()) << " ";
[4476]752 for (int iType = 0; iType < rnxTypes.size(); iType++) {
[4478]753 str << " " << rnxTypes[iType];
[4476]754 }
[4477]755 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
[4476]756 }
757 }
758
[1574]759 // RTCMv3 antenna descriptor
760 // -------------------------
[4476]761 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
[3523]762 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
[1574]763 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
764 }
[1555]765
[1575]766 // RTCM Antenna Coordinates
767 // ------------------------
[4476]768 for (int ii=0; ii < decoder()->_antList.size(); ii++) {
[1574]769 QByteArray antT;
[3523]770 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1574]771 antT = "ARP";
772 }
[3523]773 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1574]774 antT = "APC";
775 }
[1575]776 QByteArray ant1, ant2, ant3;
[3523]777 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
778 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
779 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
[1575]780 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
781 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
782 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
[3595]783 double hh = 0.0;
[3523]784 if (decoder()->_antList[ii].height_f) {
[3595]785 hh = decoder()->_antList[ii].height;
786 QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
[1575]787 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
788 }
[3523]789 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
790 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]791 hh, antT));
[1218]792 }
793 }
[1044]794 }
[1575]795
[1770]796#ifdef MLS_SOFTWARE
[3523]797 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
[1770]798 QByteArray antT;
[3523]799 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1770]800 antT = "ARP";
801 }
[3523]802 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1770]803 antT = "APC";
804 }
[3595]805 double hh = 0.0;
806 if (decoder()->_antList[ii].height_f) {
807 hh = decoder()->_antList[ii].height;
808 }
[3523]809 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
810 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]811 hh, antT));
[1770]812 }
[2356]813
[3523]814 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
815 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
[2356]816 }
[1770]817#endif
818
[3523]819 decoder()->_typeList.clear();
820 decoder()->_antType.clear();
821 decoder()->_antList.clear();
[1044]822}
[1555]823
[1606]824// Handle Data from Serial Port
825////////////////////////////////////////////////////////////////////////////
826void bncGetThread::slotSerialReadyRead() {
[6770]827
[1607]828 if (_serialPort) {
[6770]829
[1633]830 int nb = _serialPort->bytesAvailable();
[6770]831
[1633]832 if (nb > 0) {
833 QByteArray data = _serialPort->read(nb);
[1711]834
[6695]835 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
[1725]836 int i1 = data.indexOf("$GPGGA");
[6651]837 if (i1 == -1) {
838 i1 = data.indexOf("$GNGGA");
839 }
[1725]840 if (i1 != -1) {
[6751]841 int i2 = data.indexOf("*", i1);
[1725]842 if (i2 != -1 && data.size() > i2 + 1) {
[6751]843 QByteArray gga = data.mid(i1, i2 - i1 + 3);
[1725]844 _query->sendNMEA(gga);
[6751]845 }
846 }
[1711]847 }
848
[6751]849 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
850 if (_manualNMEASampl) {
851 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
[6753]852 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
[6751]853 _query->sendNMEA(_manualNMEAString);
854 _lastManualNMEA = QDateTime::currentDateTime();
855 }
856 }
857 }
858
[1633]859 if (_serialOutFile) {
860 _serialOutFile->write(data);
861 _serialOutFile->flush();
862 }
[1607]863 }
864 }
[1606]865}
Note: See TracBrowser for help on using the repository browser.