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

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

satellite information added to "Wrong observation epoch" message

File size: 27.5 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
[7859]411 if (BNC_CORE->mode() != t_bncCore::interactive) {
412 while (!isFinished()) {wait();}
413 delete this;
[7858]414 }
[7859]415 else {
416 if (!isRunning()) {delete this;}
417 }
[7858]418#else
[7859]419 if (!isRunning()) {delete this;}
[7858]420#endif
421
[1390]422}
423
[136]424// Run
425////////////////////////////////////////////////////////////////////////////
426void bncGetThread::run() {
427
[35]428 while (true) {
[629]429 try {
[1555]430 if (_isToBeDeleted) {
431 QThread::exit(0);
432 this->deleteLater();
433 return;
[629]434 }
[621]435
[1555]436 if (tryReconnect() != success) {
[3532]437 if (_latencyChecker) {
438 _latencyChecker->checkReconnect();
439 }
[1555]440 continue;
[621]441 }
[1555]442
443 // Delete old observations
444 // -----------------------
[3560]445 if (_rawFile) {
446 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
447 while (itDec.hasNext()) {
448 itDec.next();
449 GPSDecoder* decoder = itDec.value();
450 decoder->_obsList.clear();
451 }
[3515]452 }
[3560]453 else {
454 _decoder->_obsList.clear();
455 }
[621]456
[1555]457 // Read Data
458 // ---------
[1377]459 QByteArray data;
460 if (_query) {
461 _query->waitForReadyRead(data);
[1138]462 }
[2519]463 else if (_rawFile) {
[2527]464 data = _rawFile->readChunk();
[3523]465 _format = _rawFile->format();
466 _staID = _rawFile->staID();
[2388]467
[5903]468 QCoreApplication::processEvents();
469
[7976]470 if (data.isEmpty() || BNC_CORE->sigintReceived) {
471 cout << "no more data or Ctrl-C received" << endl;
[5068]472 BNC_CORE->stopCombination();
[5900]473 BNC_CORE->stopPPP();
[5903]474 ::exit(0);
[1555]475 }
[1138]476 }
[1555]477 qint64 nBytes = data.size();
[1138]478
[1555]479 // Timeout, reconnect
480 // ------------------
481 if (nBytes == 0) {
[3532]482 if (_latencyChecker) {
483 _latencyChecker->checkReconnect();
484 }
[1555]485 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
[2355]486 msleep(10000); //sleep 10 sec, G. Weber
[1555]487 continue;
488 }
489 else {
[567]490 emit newBytes(_staID, nBytes);
[5648]491 emit newRawData(_staID, data);
[1555]492 }
[567]493
[1555]494 // Output Data
495 // -----------
[2386]496 if (_rawOutput) {
[7486]497 BNC_CORE->writeRawData(data, _staID, _format);
[2386]498 }
[2385]499
[1555]500 if (_serialPort) {
[1633]501 slotSerialReadyRead();
[1555]502 _serialPort->write(data);
503 }
[7486]504
[1555]505 // Decode Data
506 // -----------
507 vector<string> errmsg;
[3526]508 if (!decoder()) {
509 _isToBeDeleted = true;
510 continue;
511 }
[7753]512
[3523]513 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
[1137]514
[7753]515 if (irc != success) {
516 continue;
517 }
[1555]518 // Perform various scans and checks
519 // --------------------------------
[3532]520 if (_latencyChecker) {
521 _latencyChecker->checkOutage(irc == success);
522 _latencyChecker->checkObsLatency(decoder()->_obsList);
523 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
[7486]524
[3532]525 emit newLatency(_staID, _latencyChecker->currentLatency());
526 }
[1567]527
[7753]528 miscScanRTCM();
[1138]529
[1555]530 // Loop over all observations (observations output)
531 // ------------------------------------------------
[6137]532 QListIterator<t_satObs> it(decoder()->_obsList);
[5524]533
[6137]534 QList<t_satObs> obsListHlp;
[5524]535
[1555]536 while (it.hasNext()) {
[6137]537 const t_satObs& obs = it.next();
[2711]538
[1555]539 // Check observation epoch
540 // -----------------------
[5739]541 if (!_rawFile) {
[8011]542 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
543 if (wrongObservationEpoch) {
[8021]544 QString prn(obs._prn.toString().c_str());
545 emit( newMessage(_staID + " (" + prn.toAscii() + ")" + ": Wrong observation epoch(s)", false) );
[1555]546 continue;
[940]547 }
[686]548 }
[6812]549
[3305]550 // Check observations coming twice (e.g. KOUR0 Problem)
551 // ----------------------------------------------------
[3535]552 if (!_rawFile) {
[8011]553 QString prn(obs._prn.toString().c_str());
554 long iSec = long(floor(obs._time.gpssec()+0.5));
555 long obsTime = obs._time.gpsw()*7*24*3600 + iSec;
[3535]556 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
557 if (it != _prnLastEpo.end()) {
558 long oldTime = it.value();
559 if (obsTime < oldTime) {
[7486]560 emit( newMessage(_staID +
[3535]561 ": old observation " + prn.toAscii(), false));
562 continue;
563 }
564 else if (obsTime == oldTime) {
[7486]565 emit( newMessage(_staID +
[3535]566 ": observation coming more than once " + prn.toAscii(), false));
567 continue;
568 }
[3302]569 }
[3535]570 _prnLastEpo[prn] = obsTime;
[3301]571 }
572
[3528]573 decoder()->dumpRinexEpoch(obs, _format);
574
[5524]575 // Save observations
576 // -----------------
577 obsListHlp.append(obs);
578 }
[2030]579
[5524]580 // Emit signal
581 // -----------
582 if (!_isToBeDeleted && obsListHlp.size() > 0) {
583 emit newObs(_staID, obsListHlp);
[249]584 }
[5524]585
[35]586 }
[3311]587 catch (Exception& exc) {
588 emit(newMessage(_staID + " " + exc.what(), true));
589 _isToBeDeleted = true;
590 }
[1555]591 catch (...) {
[3311]592 emit(newMessage(_staID + " bncGetThread exception", true));
[1559]593 _isToBeDeleted = true;
[1555]594 }
[35]595 }
596}
597
[7486]598// Try Re-Connect
[136]599////////////////////////////////////////////////////////////////////////////
[1555]600t_irc bncGetThread::tryReconnect() {
601
602 // Easy Return
603 // -----------
604 if (_query && _query->status() == bncNetQuery::running) {
605 _nextSleep = 0;
[3560]606 if (_rawFile) {
607 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
608 while (itDec.hasNext()) {
609 itDec.next();
610 GPSDecoder* decoder = itDec.value();
611 decoder->setRinexReconnectFlag(false);
612 }
[1709]613 }
[3560]614 else {
615 _decoder->setRinexReconnectFlag(false);
616 }
[1555]617 return success;
[408]618 }
[1555]619
620 // Start a new query
621 // -----------------
[2519]622 if (!_rawFile) {
[1555]623
[138]624 sleep(_nextSleep);
[1555]625 if (_nextSleep == 0) {
626 _nextSleep = 1;
[138]627 }
628 else {
[1555]629 _nextSleep = 2 * _nextSleep;
[442]630 if (_nextSleep > 256) {
631 _nextSleep = 256;
[152]632 }
[1816]633#ifdef MLS_SOFTWARE
[1817]634 if (_nextSleep > 4) {
635 _nextSleep = 4;
[1816]636 }
637#endif
[138]638 }
[7888]639 if (_query) {
640 delete _query;
641 }
[1722]642 if (_ntripVersion == "U") {
[1721]643 _query = new bncNetQueryUdp();
644 }
[1722]645 else if (_ntripVersion == "R") {
[1555]646 _query = new bncNetQueryRtp();
647 }
[1744]648 else if (_ntripVersion == "S") {
[1753]649 _query = new bncNetQueryS();
[1744]650 }
[1621]651 else if (_ntripVersion == "N") {
652 _query = new bncNetQueryV0();
653 }
[1779]654 else if (_ntripVersion == "UN") {
655 _query = new bncNetQueryUdp0();
656 }
[1555]657 else if (_ntripVersion == "2") {
[3337]658 _query = new bncNetQueryV2(false);
[1555]659 }
[3334]660 else if (_ntripVersion == "2s") {
[3337]661 _query = new bncNetQueryV2(true);
[3334]662 }
[1555]663 else {
664 _query = new bncNetQueryV1();
665 }
[6770]666 if (_nmea == "yes") {
667 if (_serialNMEA == MANUAL_NMEA) {
668 _query->startRequest(_mountPoint, _manualNMEAString);
669 _lastManualNMEA = QDateTime::currentDateTime();
670 }
671 else if (_serialNMEA == AUTO_NMEA) {
672 if (_serialPort) {
673 int nb = _serialPort->bytesAvailable();
674 if (nb > 0) {
675 QByteArray data = _serialPort->read(nb);
676 int i1 = data.indexOf("$GPGGA");
677 if (i1 == -1) {
678 i1 = data.indexOf("$GNGGA");
679 }
680 if (i1 != -1) {
681 int i2 = data.indexOf("*", i1);
682 if (i2 != -1 && data.size() > i2 + 1) {
683 QByteArray gga = data.mid(i1, i2 - i1 + 3);
684 _query->startRequest(_mountPoint, gga);
685 }
686 }
687 }
688 }
689 }
[1555]690 }
691 else {
692 _query->startRequest(_mountPoint, "");
693 }
[6770]694
[1555]695 if (_query->status() != bncNetQuery::running) {
696 return failure;
697 }
[138]698 }
[658]699
[3560]700 if (_rawFile) {
701 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
702 while (itDec.hasNext()) {
703 itDec.next();
704 GPSDecoder* decoder = itDec.value();
705 decoder->setRinexReconnectFlag(false);
706 }
[658]707 }
[3560]708 else {
709 _decoder->setRinexReconnectFlag(false);
710 }
[1555]711
712 return success;
[658]713}
[1044]714
[1555]715// RTCM scan output
[1044]716//////////////////////////////////////////////////////////////////////////////
[7423]717void bncGetThread::miscScanRTCM() {
[1044]718
[4476]719 if ( !decoder() ) {
[3558]720 return;
721 }
722
[1555]723 bncSettings settings;
[7423]724 if ( Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked ) {
[1574]725
726 if ( _miscMount == _staID || _miscMount == "ALL" ) {
[1575]727 // RTCM message types
728 // ------------------
[4476]729 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
[3523]730 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
[1574]731 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
732 }
[7486]733
[4476]734 // Check Observation Types
735 // -----------------------
736 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
[6137]737 t_satObs& obs = decoder()->_obsList[ii];
738 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
[4476]739 bool allFound = true;
[6137]740 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
[6579]741 if (obs._obs[iFrq]->_codeValid) {
742 QString rnxStr('C');
743 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]744 if (_format.indexOf("RTCM_2") != -1 ||
745 _format.indexOf("RTCM2") != -1 ||
746 _format.indexOf("RTCM 2") != -1 ) {
747 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
748 }
[6579]749 if (rnxTypes.indexOf(rnxStr) == -1) {
750 rnxTypes.push_back(rnxStr);
751 allFound = false;
752 }
[4476]753 }
[6579]754 if (obs._obs[iFrq]->_phaseValid) {
755 QString rnxStr('L');
756 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]757 if (_format.indexOf("RTCM_2") != -1 ||
758 _format.indexOf("RTCM2") != -1 ||
759 _format.indexOf("RTCM 2") != -1 ) {
760 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
761 }
[6579]762 if (rnxTypes.indexOf(rnxStr) == -1) {
763 rnxTypes.push_back(rnxStr);
764 allFound = false;
765 }
766 }
767 if (obs._obs[iFrq]->_dopplerValid){
768 QString rnxStr('D');
769 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]770 if (_format.indexOf("RTCM_2") != -1 ||
771 _format.indexOf("RTCM2") != -1 ||
772 _format.indexOf("RTCM 2") != -1 ) {
773 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
774 }
[6579]775 if (rnxTypes.indexOf(rnxStr) == -1) {
776 rnxTypes.push_back(rnxStr);
777 allFound = false;
778 }
779 }
780 if (obs._obs[iFrq]->_snrValid){
781 QString rnxStr('S');
782 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
[6580]783 if (_format.indexOf("RTCM_2") != -1 ||
784 _format.indexOf("RTCM2") != -1 ||
785 _format.indexOf("RTCM 2") != -1 ) {
786 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
787 }
[6579]788 if (rnxTypes.indexOf(rnxStr) == -1) {
789 rnxTypes.push_back(rnxStr);
790 allFound = false;
791 }
792 }
[4476]793 }
794 if (!allFound) {
[7486]795 QString msg;
[4477]796 QTextStream str(&msg);
[6579]797 QString s;
798 str << obs._prn.system() << " " << s.sprintf("%2d", rnxTypes.size()) << " ";
[4476]799 for (int iType = 0; iType < rnxTypes.size(); iType++) {
[4478]800 str << " " << rnxTypes[iType];
[4476]801 }
[4477]802 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
[4476]803 }
804 }
805
[1574]806 // RTCMv3 antenna descriptor
807 // -------------------------
[4476]808 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
[3523]809 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
[1574]810 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
811 }
[1555]812
[1575]813 // RTCM Antenna Coordinates
814 // ------------------------
[4476]815 for (int ii=0; ii < decoder()->_antList.size(); ii++) {
[1574]816 QByteArray antT;
[3523]817 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1574]818 antT = "ARP";
819 }
[3523]820 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1574]821 antT = "APC";
822 }
[1575]823 QByteArray ant1, ant2, ant3;
[3523]824 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
825 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
826 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
[1575]827 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
828 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
829 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
[3595]830 double hh = 0.0;
[3523]831 if (decoder()->_antList[ii].height_f) {
[3595]832 hh = decoder()->_antList[ii].height;
833 QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
[1575]834 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
835 }
[7486]836 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
837 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]838 hh, antT));
[1218]839 }
[6864]840
841 // RTCM GLONASS slots
842 // ------------------
843 if (decoder()->_gloFrq.size()) {
844 bool allFound = true;
845 QString slot = decoder()->_gloFrq;
[7153]846 slot.replace(" "," ").replace(" ",":");
[6864]847 if (_gloSlots.indexOf(slot) == -1) {
848 _gloSlots.append(slot);
849 allFound = false;
850 }
851 if (!allFound) {
852 _gloSlots.sort();
[7153]853 emit(newMessage(_staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toAscii(), true));
[6864]854 }
855 }
[1218]856 }
[1044]857 }
[1575]858
[1770]859#ifdef MLS_SOFTWARE
[3523]860 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
[1770]861 QByteArray antT;
[3523]862 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1770]863 antT = "ARP";
864 }
[3523]865 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1770]866 antT = "APC";
867 }
[3595]868 double hh = 0.0;
869 if (decoder()->_antList[ii].height_f) {
870 hh = decoder()->_antList[ii].height;
871 }
[7486]872 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
873 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]874 hh, antT));
[1770]875 }
[2356]876
[3523]877 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
878 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
[2356]879 }
[1770]880#endif
881
[6864]882 decoder()->_gloFrq.clear();
[3523]883 decoder()->_typeList.clear();
884 decoder()->_antType.clear();
885 decoder()->_antList.clear();
[1044]886}
[1555]887
[1606]888// Handle Data from Serial Port
889////////////////////////////////////////////////////////////////////////////
890void bncGetThread::slotSerialReadyRead() {
[6770]891
[1607]892 if (_serialPort) {
[6770]893
[6773]894 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
895 if (_manualNMEASampl) {
896 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
897 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
898 _query->sendNMEA(_manualNMEAString);
899 _lastManualNMEA = QDateTime::currentDateTime();
900 }
901 }
902 }
903
[1633]904 int nb = _serialPort->bytesAvailable();
905 if (nb > 0) {
906 QByteArray data = _serialPort->read(nb);
[1711]907
[6695]908 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
[1725]909 int i1 = data.indexOf("$GPGGA");
[6651]910 if (i1 == -1) {
911 i1 = data.indexOf("$GNGGA");
912 }
[1725]913 if (i1 != -1) {
[6751]914 int i2 = data.indexOf("*", i1);
[1725]915 if (i2 != -1 && data.size() > i2 + 1) {
[6751]916 QByteArray gga = data.mid(i1, i2 - i1 + 3);
[1725]917 _query->sendNMEA(gga);
[6751]918 }
919 }
[1711]920 }
921
[1633]922 if (_serialOutFile) {
923 _serialOutFile->write(data);
924 _serialOutFile->flush();
925 }
[1607]926 }
927 }
[1606]928}
[7180]929
930void bncGetThread::slotNewNMEAConnection() {
931 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
932 emit( newMessage(QString("New PPP client on port: # %1")
933 .arg(_nmeaSockets->size()).toAscii(), true) );
934}
935
936//
937////////////////////////////////////////////////////////////////////////////
938void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
939 if (_nmeaPortsMap.contains(staID)) {
940 int nmeaPort = _nmeaPortsMap.value(staID);
941 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
942 while (is.hasNext()) {
943 QTcpSocket* sock = is.next();
944 if (sock->localPort() == nmeaPort) {
945 if (sock->state() == QAbstractSocket::ConnectedState) {
946 sock->write(str);
947 }
948 else if (sock->state() != QAbstractSocket::ConnectingState) {
949 delete sock;
950 is.remove();
951 }
952 }
953 }
954 }
955}
Note: See TracBrowser for help on using the repository browser.