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

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

minor changes

File size: 24.3 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);
270
[1636]271 }
[1318]272 }
273
[3532]274 if (!_staID.isEmpty()) {
275 _latencyChecker = new latencyChecker(_staID);
[2004]276 }
[3532]277 else {
278 _latencyChecker = 0;
279 }
[3523]280}
281
282// Instantiate the decoder
283//////////////////////////////////////////////////////////////////////////////
284t_irc bncGetThread::initDecoder() {
285
[3560]286 _decoder = 0;
287
[1744]288 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
289 _format.indexOf("RTCM 2") != -1 ) {
[1555]290 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
[3560]291 _decoder = new RTCM2Decoder(_staID.data());
[1555]292 }
[1744]293 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
294 _format.indexOf("RTCM 3") != -1 ) {
[1555]295 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
[3558]296 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
[3560]297 _decoder = newDecoder;
[3558]298 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
[1555]299 this, SIGNAL(newMessage(QByteArray,bool)));
300 }
301 else if (_format.indexOf("ZERO") != -1) {
302 emit(newMessage(_staID + ": Get data in original format", true));
[3560]303 _decoder = new bncZeroDecoder(_staID);
[1555]304 }
[3168]305 else if (_format.indexOf("RTNET") != -1) {
306 emit(newMessage(_staID + ": Get data in RTNet format", true));
[3560]307 _decoder = new bncRtnetDecoder();
[3168]308 }
[1555]309 else {
310 emit(newMessage(_staID + ": Unknown data format " + _format, true));
311 _isToBeDeleted = true;
[3523]312 return failure;
[1555]313 }
314
[319]315 msleep(100); //sleep 0.1 sec
[3523]316
[3560]317 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
318 _nmea, _ntripVersion);
319
320 if (_rawFile) {
321 _decodersRaw[_staID] = _decoder;
[3530]322 }
323
[3523]324 return success;
[35]325}
326
[3523]327// Current decoder in use
328////////////////////////////////////////////////////////////////////////////
329GPSDecoder* bncGetThread::decoder() {
[3560]330 if (!_rawFile) {
331 return _decoder;
[3523]332 }
333 else {
[3560]334 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
335 return _decodersRaw[_staID];
336 }
[3523]337 }
[3560]338 return 0;
[3523]339}
340
[35]341// Destructor
342////////////////////////////////////////////////////////////////////////////
343bncGetThread::~bncGetThread() {
[1928]344 if (isRunning()) {
345 wait();
346 }
[1527]347 if (_query) {
348 _query->stop();
[1708]349 _query->deleteLater();
[1527]350 }
[3560]351 if (_rawFile) {
352 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
353 while (it.hasNext()) {
354 it.next();
355 delete it.value();
356 }
[3523]357 }
[3560]358 else {
359 delete _decoder;
360 }
[2519]361 delete _rawFile;
[1607]362 delete _serialOutFile;
[1328]363 delete _serialPort;
[1557]364 delete _latencyChecker;
[1556]365 emit getThreadFinished(_staID);
[35]366}
367
[1390]368//
369////////////////////////////////////////////////////////////////////////////
370void bncGetThread::terminate() {
[1525]371 _isToBeDeleted = true;
[1559]372 if (!isRunning()) {
373 delete this;
374 }
[1390]375}
376
[136]377// Run
378////////////////////////////////////////////////////////////////////////////
379void bncGetThread::run() {
380
[35]381 while (true) {
[629]382 try {
[1555]383 if (_isToBeDeleted) {
384 QThread::exit(0);
385 this->deleteLater();
386 return;
[629]387 }
[621]388
[1555]389 if (tryReconnect() != success) {
[3532]390 if (_latencyChecker) {
391 _latencyChecker->checkReconnect();
392 }
[1555]393 continue;
[621]394 }
[1555]395
396 // Delete old observations
397 // -----------------------
[3560]398 if (_rawFile) {
399 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
400 while (itDec.hasNext()) {
401 itDec.next();
402 GPSDecoder* decoder = itDec.value();
403 decoder->_obsList.clear();
404 }
[3515]405 }
[3560]406 else {
407 _decoder->_obsList.clear();
408 }
[621]409
[1555]410 // Read Data
411 // ---------
[1377]412 QByteArray data;
413 if (_query) {
414 _query->waitForReadyRead(data);
[1138]415 }
[2519]416 else if (_rawFile) {
[2527]417 data = _rawFile->readChunk();
[3523]418 _format = _rawFile->format();
419 _staID = _rawFile->staID();
[2388]420
[5903]421 QCoreApplication::processEvents();
422
[1555]423 if (data.isEmpty()) {
424 cout << "no more data" << endl;
[5068]425 BNC_CORE->stopCombination();
[5900]426 BNC_CORE->stopPPP();
[5903]427 ::exit(0);
[1555]428 }
[1138]429 }
[1555]430 qint64 nBytes = data.size();
[1138]431
[1555]432 // Timeout, reconnect
433 // ------------------
434 if (nBytes == 0) {
[3532]435 if (_latencyChecker) {
436 _latencyChecker->checkReconnect();
437 }
[1555]438 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
[2355]439 msleep(10000); //sleep 10 sec, G. Weber
[1555]440 continue;
441 }
442 else {
[567]443 emit newBytes(_staID, nBytes);
[5648]444 emit newRawData(_staID, data);
[1555]445 }
[567]446
[1555]447 // Output Data
448 // -----------
[2386]449 if (_rawOutput) {
[5068]450 BNC_CORE->writeRawData(data, _staID, _format);
[2386]451 }
[2385]452
[1555]453 if (_serialPort) {
[1633]454 slotSerialReadyRead();
[1555]455 _serialPort->write(data);
456 }
[5647]457
[1555]458 // Decode Data
459 // -----------
460 vector<string> errmsg;
[3526]461 if (!decoder()) {
462 _isToBeDeleted = true;
463 continue;
464 }
[3523]465 decoder()->_obsList.clear();
466 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
[1137]467
[1555]468 // Perform various scans and checks
469 // --------------------------------
[3532]470 if (_latencyChecker) {
471 _latencyChecker->checkOutage(irc == success);
472 _latencyChecker->checkObsLatency(decoder()->_obsList);
473 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
474
475 emit newLatency(_staID, _latencyChecker->currentLatency());
476 }
[1567]477
[1555]478 scanRTCM();
[1138]479
[1555]480 // Loop over all observations (observations output)
481 // ------------------------------------------------
[6137]482 QListIterator<t_satObs> it(decoder()->_obsList);
[5524]483
[6137]484 QList<t_satObs> obsListHlp;
[5524]485
[1555]486 while (it.hasNext()) {
[6137]487 const t_satObs& obs = it.next();
[2711]488
[6137]489 QString prn(obs._prn.toString().c_str());
490 long iSec = long(floor(obs._time.gpssec()+0.5));
491 long obsTime = obs._time.gpsw()*7*24*3600 + iSec;
[3303]492
[1555]493 // Check observation epoch
494 // -----------------------
[5739]495 if (!_rawFile) {
[3303]496 int week;
[1555]497 double sec;
498 currentGPSWeeks(week, sec);
[3304]499 long currTime = week * 7*24*3600 + long(sec);
[1555]500 const double maxDt = 600.0;
[3303]501 if (fabs(currTime - obsTime) > maxDt) {
[2308]502 emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
[1555]503 continue;
[940]504 }
[686]505 }
[1555]506
[3305]507 // Check observations coming twice (e.g. KOUR0 Problem)
508 // ----------------------------------------------------
[3535]509 if (!_rawFile) {
510 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
511 if (it != _prnLastEpo.end()) {
512 long oldTime = it.value();
513 if (obsTime < oldTime) {
514 emit( newMessage(_staID +
515 ": old observation " + prn.toAscii(), false));
516 continue;
517 }
518 else if (obsTime == oldTime) {
519 emit( newMessage(_staID +
520 ": observation coming more than once " + prn.toAscii(), false));
521 continue;
522 }
[3302]523 }
[3535]524 _prnLastEpo[prn] = obsTime;
[3301]525 }
526
[3528]527 decoder()->dumpRinexEpoch(obs, _format);
528
[5524]529 // Save observations
530 // -----------------
531 obsListHlp.append(obs);
532 }
[2030]533
[5524]534 // Emit signal
535 // -----------
536 if (!_isToBeDeleted && obsListHlp.size() > 0) {
537 emit newObs(_staID, obsListHlp);
[249]538 }
[5524]539
[3523]540 decoder()->_obsList.clear();
[35]541 }
[3311]542 catch (Exception& exc) {
543 emit(newMessage(_staID + " " + exc.what(), true));
544 _isToBeDeleted = true;
545 }
[1555]546 catch (...) {
[3311]547 emit(newMessage(_staID + " bncGetThread exception", true));
[1559]548 _isToBeDeleted = true;
[1555]549 }
[35]550 }
551}
552
[136]553// Try Re-Connect
554////////////////////////////////////////////////////////////////////////////
[1555]555t_irc bncGetThread::tryReconnect() {
556
557 // Easy Return
558 // -----------
559 if (_query && _query->status() == bncNetQuery::running) {
560 _nextSleep = 0;
[3560]561 if (_rawFile) {
562 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
563 while (itDec.hasNext()) {
564 itDec.next();
565 GPSDecoder* decoder = itDec.value();
566 decoder->setRinexReconnectFlag(false);
567 }
[1709]568 }
[3560]569 else {
570 _decoder->setRinexReconnectFlag(false);
571 }
[1555]572 return success;
[408]573 }
[1555]574
575 // Start a new query
576 // -----------------
[2519]577 if (!_rawFile) {
[1555]578
[138]579 sleep(_nextSleep);
[1555]580 if (_nextSleep == 0) {
581 _nextSleep = 1;
[138]582 }
583 else {
[1555]584 _nextSleep = 2 * _nextSleep;
[442]585 if (_nextSleep > 256) {
586 _nextSleep = 256;
[152]587 }
[1816]588#ifdef MLS_SOFTWARE
[1817]589 if (_nextSleep > 4) {
590 _nextSleep = 4;
[1816]591 }
592#endif
[138]593 }
[1555]594
595 delete _query;
[1722]596 if (_ntripVersion == "U") {
[1721]597 _query = new bncNetQueryUdp();
598 }
[1722]599 else if (_ntripVersion == "R") {
[1555]600 _query = new bncNetQueryRtp();
601 }
[1744]602 else if (_ntripVersion == "S") {
[1753]603 _query = new bncNetQueryS();
[1744]604 }
[1621]605 else if (_ntripVersion == "N") {
606 _query = new bncNetQueryV0();
607 }
[1779]608 else if (_ntripVersion == "UN") {
609 _query = new bncNetQueryUdp0();
610 }
[1555]611 else if (_ntripVersion == "2") {
[3337]612 _query = new bncNetQueryV2(false);
[1555]613 }
[3334]614 else if (_ntripVersion == "2s") {
[3337]615 _query = new bncNetQueryV2(true);
[3334]616 }
[1555]617 else {
618 _query = new bncNetQueryV1();
619 }
[6685]620 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
[6751]621 _query->startRequest(_mountPoint, _manualNMEAString);
622 _lastManualNMEA = QDateTime::currentDateTime();
[1555]623 }
624 else {
625 _query->startRequest(_mountPoint, "");
626 }
627 if (_query->status() != bncNetQuery::running) {
628 return failure;
629 }
[138]630 }
[658]631
[3560]632 if (_rawFile) {
633 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
634 while (itDec.hasNext()) {
635 itDec.next();
636 GPSDecoder* decoder = itDec.value();
637 decoder->setRinexReconnectFlag(false);
638 }
[658]639 }
[3560]640 else {
641 _decoder->setRinexReconnectFlag(false);
642 }
[1555]643
644 return success;
[658]645}
[1044]646
[1555]647// RTCM scan output
[1044]648//////////////////////////////////////////////////////////////////////////////
[1555]649void bncGetThread::scanRTCM() {
[1044]650
[4476]651 if ( !decoder() ) {
[3558]652 return;
653 }
654
[1555]655 bncSettings settings;
[1574]656 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
657
658 if ( _miscMount == _staID || _miscMount == "ALL" ) {
[1575]659 // RTCM message types
660 // ------------------
[4476]661 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
[3523]662 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
[1574]663 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
664 }
[1044]665
[4476]666 // Check Observation Types
667 // -----------------------
668 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
[6137]669 t_satObs& obs = decoder()->_obsList[ii];
670 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
[4476]671 bool allFound = true;
[6137]672 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
[6579]673 if (obs._obs[iFrq]->_codeValid) {
674 QString rnxStr('C');
675 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]676 if (_format.indexOf("RTCM_2") != -1 ||
677 _format.indexOf("RTCM2") != -1 ||
678 _format.indexOf("RTCM 2") != -1 ) {
679 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
680 }
[6579]681 if (rnxTypes.indexOf(rnxStr) == -1) {
682 rnxTypes.push_back(rnxStr);
683 allFound = false;
684 }
[4476]685 }
[6579]686 if (obs._obs[iFrq]->_phaseValid) {
687 QString rnxStr('L');
688 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]689 if (_format.indexOf("RTCM_2") != -1 ||
690 _format.indexOf("RTCM2") != -1 ||
691 _format.indexOf("RTCM 2") != -1 ) {
692 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
693 }
[6579]694 if (rnxTypes.indexOf(rnxStr) == -1) {
695 rnxTypes.push_back(rnxStr);
696 allFound = false;
697 }
698 }
699 if (obs._obs[iFrq]->_dopplerValid){
700 QString rnxStr('D');
701 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]702 if (_format.indexOf("RTCM_2") != -1 ||
703 _format.indexOf("RTCM2") != -1 ||
704 _format.indexOf("RTCM 2") != -1 ) {
705 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
706 }
[6579]707 if (rnxTypes.indexOf(rnxStr) == -1) {
708 rnxTypes.push_back(rnxStr);
709 allFound = false;
710 }
711 }
712 if (obs._obs[iFrq]->_snrValid){
713 QString rnxStr('S');
714 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]715 if (_format.indexOf("RTCM_2") != -1 ||
716 _format.indexOf("RTCM2") != -1 ||
717 _format.indexOf("RTCM 2") != -1 ) {
718 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
719 }
[6579]720 if (rnxTypes.indexOf(rnxStr) == -1) {
721 rnxTypes.push_back(rnxStr);
722 allFound = false;
723 }
724 }
[4476]725 }
726 if (!allFound) {
[4477]727 QString msg;
728 QTextStream str(&msg);
[6579]729 QString s;
730 str << obs._prn.system() << " " << s.sprintf("%2d", rnxTypes.size()) << " ";
[4476]731 for (int iType = 0; iType < rnxTypes.size(); iType++) {
[4478]732 str << " " << rnxTypes[iType];
[4476]733 }
[4477]734 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
[4476]735 }
736 }
737
[1574]738 // RTCMv3 antenna descriptor
739 // -------------------------
[4476]740 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
[3523]741 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
[1574]742 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
743 }
[1555]744
[1575]745 // RTCM Antenna Coordinates
746 // ------------------------
[4476]747 for (int ii=0; ii < decoder()->_antList.size(); ii++) {
[1574]748 QByteArray antT;
[3523]749 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1574]750 antT = "ARP";
751 }
[3523]752 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1574]753 antT = "APC";
754 }
[1575]755 QByteArray ant1, ant2, ant3;
[3523]756 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
757 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
758 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
[1575]759 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
760 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
761 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
[3595]762 double hh = 0.0;
[3523]763 if (decoder()->_antList[ii].height_f) {
[3595]764 hh = decoder()->_antList[ii].height;
765 QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
[1575]766 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
767 }
[3523]768 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
769 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]770 hh, antT));
[1218]771 }
772 }
[1044]773 }
[1575]774
[1770]775#ifdef MLS_SOFTWARE
[3523]776 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
[1770]777 QByteArray antT;
[3523]778 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1770]779 antT = "ARP";
780 }
[3523]781 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1770]782 antT = "APC";
783 }
[3595]784 double hh = 0.0;
785 if (decoder()->_antList[ii].height_f) {
786 hh = decoder()->_antList[ii].height;
787 }
[3523]788 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
789 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]790 hh, antT));
[1770]791 }
[2356]792
[3523]793 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
794 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
[2356]795 }
[1770]796#endif
797
[3523]798 decoder()->_typeList.clear();
799 decoder()->_antType.clear();
800 decoder()->_antList.clear();
[1044]801}
[1555]802
[1606]803// Handle Data from Serial Port
804////////////////////////////////////////////////////////////////////////////
805void bncGetThread::slotSerialReadyRead() {
[1607]806 if (_serialPort) {
[1633]807 int nb = _serialPort->bytesAvailable();
808 if (nb > 0) {
809 QByteArray data = _serialPort->read(nb);
[1711]810
[6695]811 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
[1725]812 int i1 = data.indexOf("$GPGGA");
[6651]813 if (i1 == -1) {
814 i1 = data.indexOf("$GNGGA");
815 }
[1725]816 if (i1 != -1) {
[6751]817 int i2 = data.indexOf("*", i1);
[1725]818 if (i2 != -1 && data.size() > i2 + 1) {
[6751]819 QByteArray gga = data.mid(i1, i2 - i1 + 3);
[1725]820 _query->sendNMEA(gga);
[6751]821 }
822 }
[1711]823 }
824
[6751]825 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
826 if (_manualNMEASampl) {
827 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
[6753]828 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
[6751]829 _query->sendNMEA(_manualNMEAString);
830 _lastManualNMEA = QDateTime::currentDateTime();
831 }
832 }
833 }
834
[1633]835 if (_serialOutFile) {
836 _serialOutFile->write(data);
837 _serialOutFile->flush();
838 }
[1607]839 }
840 }
[1606]841}
Note: See TracBrowser for help on using the repository browser.