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

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