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

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