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

Last change on this file since 7858 was 7858, checked in by stuerze, 8 years ago

#BNC_DEBUG added

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