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

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

try to prevent a crash after failed decoding

File size: 27.3 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
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.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
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
41#include <stdlib.h>
42#include <iomanip>
43#include <sstream>
44
45#include <QFile>
46#include <QTextStream>
47#include <QMutex>
48#include <QtNetwork>
49#include <QTime>
50
51#include "bncgetthread.h"
52#include "bnctabledlg.h"
53#include "bnccore.h"
54#include "bncutils.h"
55#include "bnczerodecoder.h"
56#include "bncnetqueryv0.h"
57#include "bncnetqueryv1.h"
58#include "bncnetqueryv2.h"
59#include "bncnetqueryrtp.h"
60#include "bncnetqueryudp.h"
61#include "bncnetqueryudp0.h"
62#include "bncnetquerys.h"
63#include "bncsettings.h"
64#include "latencychecker.h"
65#include "upload/bncrtnetdecoder.h"
66#include "RTCM/RTCM2Decoder.h"
67#include "RTCM3/RTCM3Decoder.h"
68#include "serial/qextserialport.h"
69
70using namespace std;
71
72// Constructor 1
73////////////////////////////////////////////////////////////////////////////
74bncGetThread::bncGetThread(bncRawFile* rawFile) {
75
76 _rawFile = rawFile;
77 _format = rawFile->format();
78 _staID = rawFile->staID();
79 _rawOutput = false;
80 _ntripVersion = "N";
81
82 initialize();
83}
84
85// Constructor 2
86////////////////////////////////////////////////////////////////////////////
87bncGetThread::bncGetThread(const QUrl& mountPoint,
88 const QByteArray& format,
89 const QByteArray& latitude,
90 const QByteArray& longitude,
91 const QByteArray& nmea,
92 const QByteArray& ntripVersion) {
93 _rawFile = 0;
94 _mountPoint = mountPoint;
95 _staID = mountPoint.path().mid(1).toAscii();
96 _format = format;
97 _latitude = latitude;
98 _longitude = longitude;
99 _nmea = nmea;
100 _ntripVersion = ntripVersion;
101
102 bncSettings settings;
103 if (!settings.value("rawOutFile").toString().isEmpty()) {
104 _rawOutput = true;
105 } else {
106 _rawOutput = false;
107 }
108
109 initialize();
110 initDecoder();
111}
112
113// Initialization (common part of the constructor)
114////////////////////////////////////////////////////////////////////////////
115void bncGetThread::initialize() {
116
117 bncSettings settings;
118
119 setTerminationEnabled(true);
120
121 connect(this, SIGNAL(newMessage(QByteArray,bool)),
122 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
123
124 _isToBeDeleted = false;
125 _query = 0;
126 _nextSleep = 0;
127 _miscMount = settings.value("miscMount").toString();
128 _decoder = 0;
129
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
159 // Serial Port
160 // -----------
161 _serialNMEA = NO_NMEA;
162 _serialOutFile = 0;
163 _serialPort = 0;
164
165 if (!_staID.isEmpty() &&
166 settings.value("serialMountPoint").toString() == _staID) {
167 _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
168 _serialPort->setTimeout(0,100);
169
170 // Baud Rate
171 // ---------
172 QString hlp = settings.value("serialBaudRate").toString();
173 if (hlp == "110") {
174 _serialPort->setBaudRate(BAUD110);
175 }
176 else if (hlp == "300") {
177 _serialPort->setBaudRate(BAUD300);
178 }
179 else if (hlp == "600") {
180 _serialPort->setBaudRate(BAUD600);
181 }
182 else if (hlp == "1200") {
183 _serialPort->setBaudRate(BAUD1200);
184 }
185 else if (hlp == "2400") {
186 _serialPort->setBaudRate(BAUD2400);
187 }
188 else if (hlp == "4800") {
189 _serialPort->setBaudRate(BAUD4800);
190 }
191 else if (hlp == "9600") {
192 _serialPort->setBaudRate(BAUD9600);
193 }
194 else if (hlp == "19200") {
195 _serialPort->setBaudRate(BAUD19200);
196 }
197 else if (hlp == "38400") {
198 _serialPort->setBaudRate(BAUD38400);
199 }
200 else if (hlp == "57600") {
201 _serialPort->setBaudRate(BAUD57600);
202 }
203 else if (hlp == "115200") {
204 _serialPort->setBaudRate(BAUD115200);
205 }
206
207 // Parity
208 // ------
209 hlp = settings.value("serialParity").toString();
210 if (hlp == "NONE") {
211 _serialPort->setParity(PAR_NONE);
212 }
213 else if (hlp == "ODD") {
214 _serialPort->setParity(PAR_ODD);
215 }
216 else if (hlp == "EVEN") {
217 _serialPort->setParity(PAR_EVEN);
218 }
219 else if (hlp == "SPACE") {
220 _serialPort->setParity(PAR_SPACE);
221 }
222
223 // Data Bits
224 // ---------
225 hlp = settings.value("serialDataBits").toString();
226 if (hlp == "5") {
227 _serialPort->setDataBits(DATA_5);
228 }
229 else if (hlp == "6") {
230 _serialPort->setDataBits(DATA_6);
231 }
232 else if (hlp == "7") {
233 _serialPort->setDataBits(DATA_7);
234 }
235 else if (hlp == "8") {
236 _serialPort->setDataBits(DATA_8);
237 }
238 hlp = settings.value("serialStopBits").toString();
239 if (hlp == "1") {
240 _serialPort->setStopBits(STOP_1);
241 }
242 else if (hlp == "2") {
243 _serialPort->setStopBits(STOP_2);
244 }
245
246 // Flow Control
247 // ------------
248 hlp = settings.value("serialFlowControl").toString();
249 if (hlp == "XONXOFF") {
250 _serialPort->setFlowControl(FLOW_XONXOFF);
251 }
252 else if (hlp == "HARDWARE") {
253 _serialPort->setFlowControl(FLOW_HARDWARE);
254 }
255 else {
256 _serialPort->setFlowControl(FLOW_OFF);
257 }
258
259 // Open Serial Port
260 // ----------------
261 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
262 if (!_serialPort->isOpen()) {
263 delete _serialPort;
264 _serialPort = 0;
265 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
266 }
267 connect(_serialPort, SIGNAL(readyRead()),
268 this, SLOT(slotSerialReadyRead()));
269
270 // Automatic NMEA
271 // --------------
272 QString nmeaMode = settings.value("serialAutoNMEA").toString();
273 if (nmeaMode == "Auto") {
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 }
284 }
285 }
286 // Manual NMEA
287 // -----------
288 if ((nmeaMode == "Manual GPGGA") ||(nmeaMode == "Manual GNGGA")) {
289 _serialNMEA = MANUAL_NMEA;
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();
297 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA, nmeaMode);
298 }
299 }
300
301 if (!_staID.isEmpty()) {
302 _latencyChecker = new latencyChecker(_staID);
303 }
304 else {
305 _latencyChecker = 0;
306 }
307}
308
309// Instantiate the decoder
310//////////////////////////////////////////////////////////////////////////////
311t_irc bncGetThread::initDecoder() {
312
313 _decoder = 0;
314
315 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
316 _format.indexOf("RTCM 2") != -1 ) {
317 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
318 _decoder = new RTCM2Decoder(_staID.data());
319 }
320 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
321 _format.indexOf("RTCM 3") != -1 ) {
322 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
323 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
324 _decoder = newDecoder;
325 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
326 this, SIGNAL(newMessage(QByteArray,bool)));
327 }
328 else if (_format.indexOf("ZERO") != -1) {
329 emit(newMessage(_staID + ": Get data in original format", true));
330 _decoder = new bncZeroDecoder(_staID);
331 }
332 else if (_format.indexOf("RTNET") != -1) {
333 emit(newMessage(_staID + ": Get data in RTNet format", true));
334 _decoder = new bncRtnetDecoder();
335 }
336 else {
337 emit(newMessage(_staID + ": Unknown data format " + _format, true));
338 _isToBeDeleted = true;
339 return failure;
340 }
341
342 msleep(100); //sleep 0.1 sec
343
344 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
345 _nmea, _ntripVersion);
346
347 if (_rawFile) {
348 _decodersRaw[_staID] = _decoder;
349 }
350
351 return success;
352}
353
354// Current decoder in use
355////////////////////////////////////////////////////////////////////////////
356GPSDecoder* bncGetThread::decoder() {
357 if (!_rawFile) {
358 return _decoder;
359 }
360 else {
361 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
362 return _decodersRaw[_staID];
363 }
364 }
365 return 0;
366}
367
368// Destructor
369////////////////////////////////////////////////////////////////////////////
370bncGetThread::~bncGetThread() {
371 if (isRunning()) {
372 wait();
373 }
374 if (_query) {
375 _query->stop();
376 _query->deleteLater();
377 }
378 if (_rawFile) {
379 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
380 while (it.hasNext()) {
381 it.next();
382 delete it.value();
383 }
384 }
385 else {
386 delete _decoder;
387 }
388 delete _rawFile;
389 delete _serialOutFile;
390 delete _serialPort;
391 delete _latencyChecker;
392 emit getThreadFinished(_staID);
393}
394
395//
396////////////////////////////////////////////////////////////////////////////
397void bncGetThread::terminate() {
398 _isToBeDeleted = true;
399 if (!isRunning()) {
400 delete this;
401 }
402 _nmeaPortsMap.remove(_staID);
403 delete _nmeaServer;
404 delete _nmeaSockets;
405}
406
407// Run
408////////////////////////////////////////////////////////////////////////////
409void bncGetThread::run() {
410
411 while (true) {
412 try {
413 if (_isToBeDeleted) {
414 QThread::exit(0);
415 this->deleteLater();
416 return;
417 }
418
419 if (tryReconnect() != success) {
420 if (_latencyChecker) {
421 _latencyChecker->checkReconnect();
422 }
423 continue;
424 }
425
426 // Delete old observations
427 // -----------------------
428 if (_rawFile) {
429 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
430 while (itDec.hasNext()) {
431 itDec.next();
432 GPSDecoder* decoder = itDec.value();
433 decoder->_obsList.clear();
434 }
435 }
436 else {
437 _decoder->_obsList.clear();
438 }
439
440 // Read Data
441 // ---------
442 QByteArray data;
443 if (_query) {
444 _query->waitForReadyRead(data);
445 }
446 else if (_rawFile) {
447 data = _rawFile->readChunk();
448 _format = _rawFile->format();
449 _staID = _rawFile->staID();
450
451 QCoreApplication::processEvents();
452
453 if (data.isEmpty()) {
454 cout << "no more data" << endl;
455 BNC_CORE->stopCombination();
456 BNC_CORE->stopPPP();
457 ::exit(0);
458 }
459 }
460 qint64 nBytes = data.size();
461
462 // Timeout, reconnect
463 // ------------------
464 if (nBytes == 0) {
465 if (_latencyChecker) {
466 _latencyChecker->checkReconnect();
467 }
468 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
469 msleep(10000); //sleep 10 sec, G. Weber
470 continue;
471 }
472 else {
473 emit newBytes(_staID, nBytes);
474 emit newRawData(_staID, data);
475 }
476
477 // Output Data
478 // -----------
479 if (_rawOutput) {
480 BNC_CORE->writeRawData(data, _staID, _format);
481 }
482
483 if (_serialPort) {
484 slotSerialReadyRead();
485 _serialPort->write(data);
486 }
487
488 // Decode Data
489 // -----------
490 vector<string> errmsg;
491 if (!decoder()) {
492 _isToBeDeleted = true;
493 continue;
494 }
495 decoder()->_obsList.clear();
496 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
497
498 if (irc == failure) {
499 _isToBeDeleted = true;
500 continue;
501 }
502
503 // Perform various scans and checks
504 // --------------------------------
505 if (_latencyChecker) {
506 _latencyChecker->checkOutage(irc == success);
507 _latencyChecker->checkObsLatency(decoder()->_obsList);
508 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
509
510 emit newLatency(_staID, _latencyChecker->currentLatency());
511 }
512
513 miscScanRTCM();
514
515 // Loop over all observations (observations output)
516 // ------------------------------------------------
517 QListIterator<t_satObs> it(decoder()->_obsList);
518
519 QList<t_satObs> obsListHlp;
520
521 while (it.hasNext()) {
522 const t_satObs& obs = it.next();
523
524 QString prn(obs._prn.toString().c_str());
525 long iSec = long(floor(obs._time.gpssec()+0.5));
526 long obsTime = obs._time.gpsw()*7*24*3600 + iSec;
527
528 // Check observation epoch
529 // -----------------------
530 if (!_rawFile) {
531 int week;
532 double sec;
533 currentGPSWeeks(week, sec);
534 long currTime = week * 7*24*3600 + long(sec);
535 const double maxDt = 600.0;
536 if (fabs(currTime - obsTime) > maxDt) {
537 emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
538 continue;
539 }
540 }
541
542 // Check observations coming twice (e.g. KOUR0 Problem)
543 // ----------------------------------------------------
544 if (!_rawFile) {
545 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
546 if (it != _prnLastEpo.end()) {
547 long oldTime = it.value();
548 if (obsTime < oldTime) {
549 emit( newMessage(_staID +
550 ": old observation " + prn.toAscii(), false));
551 continue;
552 }
553 else if (obsTime == oldTime) {
554 emit( newMessage(_staID +
555 ": observation coming more than once " + prn.toAscii(), false));
556 continue;
557 }
558 }
559 _prnLastEpo[prn] = obsTime;
560 }
561
562 decoder()->dumpRinexEpoch(obs, _format);
563
564 // Save observations
565 // -----------------
566 obsListHlp.append(obs);
567 }
568
569 // Emit signal
570 // -----------
571 if (!_isToBeDeleted && obsListHlp.size() > 0) {
572 emit newObs(_staID, obsListHlp);
573 }
574
575 decoder()->_obsList.clear();
576 }
577 catch (Exception& exc) {
578 emit(newMessage(_staID + " " + exc.what(), true));
579 _isToBeDeleted = true;
580 }
581 catch (...) {
582 emit(newMessage(_staID + " bncGetThread exception", true));
583 _isToBeDeleted = true;
584 }
585 }
586}
587
588// Try Re-Connect
589////////////////////////////////////////////////////////////////////////////
590t_irc bncGetThread::tryReconnect() {
591
592 // Easy Return
593 // -----------
594 if (_query && _query->status() == bncNetQuery::running) {
595 _nextSleep = 0;
596 if (_rawFile) {
597 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
598 while (itDec.hasNext()) {
599 itDec.next();
600 GPSDecoder* decoder = itDec.value();
601 decoder->setRinexReconnectFlag(false);
602 }
603 }
604 else {
605 _decoder->setRinexReconnectFlag(false);
606 }
607 return success;
608 }
609
610 // Start a new query
611 // -----------------
612 if (!_rawFile) {
613
614 sleep(_nextSleep);
615 if (_nextSleep == 0) {
616 _nextSleep = 1;
617 }
618 else {
619 _nextSleep = 2 * _nextSleep;
620 if (_nextSleep > 256) {
621 _nextSleep = 256;
622 }
623#ifdef MLS_SOFTWARE
624 if (_nextSleep > 4) {
625 _nextSleep = 4;
626 }
627#endif
628 }
629
630 delete _query;
631 if (_ntripVersion == "U") {
632 _query = new bncNetQueryUdp();
633 }
634 else if (_ntripVersion == "R") {
635 _query = new bncNetQueryRtp();
636 }
637 else if (_ntripVersion == "S") {
638 _query = new bncNetQueryS();
639 }
640 else if (_ntripVersion == "N") {
641 _query = new bncNetQueryV0();
642 }
643 else if (_ntripVersion == "UN") {
644 _query = new bncNetQueryUdp0();
645 }
646 else if (_ntripVersion == "2") {
647 _query = new bncNetQueryV2(false);
648 }
649 else if (_ntripVersion == "2s") {
650 _query = new bncNetQueryV2(true);
651 }
652 else {
653 _query = new bncNetQueryV1();
654 }
655 if (_nmea == "yes") {
656 if (_serialNMEA == MANUAL_NMEA) {
657 _query->startRequest(_mountPoint, _manualNMEAString);
658 _lastManualNMEA = QDateTime::currentDateTime();
659 }
660 else if (_serialNMEA == AUTO_NMEA) {
661 if (_serialPort) {
662 int nb = _serialPort->bytesAvailable();
663 if (nb > 0) {
664 QByteArray data = _serialPort->read(nb);
665 int i1 = data.indexOf("$GPGGA");
666 if (i1 == -1) {
667 i1 = data.indexOf("$GNGGA");
668 }
669 if (i1 != -1) {
670 int i2 = data.indexOf("*", i1);
671 if (i2 != -1 && data.size() > i2 + 1) {
672 QByteArray gga = data.mid(i1, i2 - i1 + 3);
673 _query->startRequest(_mountPoint, gga);
674 }
675 }
676 }
677 }
678 }
679 }
680 else {
681 _query->startRequest(_mountPoint, "");
682 }
683
684 if (_query->status() != bncNetQuery::running) {
685 return failure;
686 }
687 }
688
689 if (_rawFile) {
690 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
691 while (itDec.hasNext()) {
692 itDec.next();
693 GPSDecoder* decoder = itDec.value();
694 decoder->setRinexReconnectFlag(false);
695 }
696 }
697 else {
698 _decoder->setRinexReconnectFlag(false);
699 }
700
701 return success;
702}
703
704// RTCM scan output
705//////////////////////////////////////////////////////////////////////////////
706void bncGetThread::miscScanRTCM() {
707
708 if ( !decoder() ) {
709 return;
710 }
711
712 bncSettings settings;
713 if ( Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked ) {
714
715 if ( _miscMount == _staID || _miscMount == "ALL" ) {
716 // RTCM message types
717 // ------------------
718 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
719 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
720 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
721 }
722
723 // Check Observation Types
724 // -----------------------
725 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
726 t_satObs& obs = decoder()->_obsList[ii];
727 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
728 bool allFound = true;
729 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
730 if (obs._obs[iFrq]->_codeValid) {
731 QString rnxStr('C');
732 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
733 if (_format.indexOf("RTCM_2") != -1 ||
734 _format.indexOf("RTCM2") != -1 ||
735 _format.indexOf("RTCM 2") != -1 ) {
736 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
737 }
738 if (rnxTypes.indexOf(rnxStr) == -1) {
739 rnxTypes.push_back(rnxStr);
740 allFound = false;
741 }
742 }
743 if (obs._obs[iFrq]->_phaseValid) {
744 QString rnxStr('L');
745 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
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 }
751 if (rnxTypes.indexOf(rnxStr) == -1) {
752 rnxTypes.push_back(rnxStr);
753 allFound = false;
754 }
755 }
756 if (obs._obs[iFrq]->_dopplerValid){
757 QString rnxStr('D');
758 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
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 }
764 if (rnxTypes.indexOf(rnxStr) == -1) {
765 rnxTypes.push_back(rnxStr);
766 allFound = false;
767 }
768 }
769 if (obs._obs[iFrq]->_snrValid){
770 QString rnxStr('S');
771 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
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 }
777 if (rnxTypes.indexOf(rnxStr) == -1) {
778 rnxTypes.push_back(rnxStr);
779 allFound = false;
780 }
781 }
782 }
783 if (!allFound) {
784 QString msg;
785 QTextStream str(&msg);
786 QString s;
787 str << obs._prn.system() << " " << s.sprintf("%2d", rnxTypes.size()) << " ";
788 for (int iType = 0; iType < rnxTypes.size(); iType++) {
789 str << " " << rnxTypes[iType];
790 }
791 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
792 }
793 }
794
795 // RTCMv3 antenna descriptor
796 // -------------------------
797 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
798 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
799 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
800 }
801
802 // RTCM Antenna Coordinates
803 // ------------------------
804 for (int ii=0; ii < decoder()->_antList.size(); ii++) {
805 QByteArray antT;
806 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
807 antT = "ARP";
808 }
809 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
810 antT = "APC";
811 }
812 QByteArray ant1, ant2, ant3;
813 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
814 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
815 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
816 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
817 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
818 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
819 double hh = 0.0;
820 if (decoder()->_antList[ii].height_f) {
821 hh = decoder()->_antList[ii].height;
822 QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
823 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
824 }
825 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
826 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
827 hh, antT));
828 }
829
830 // RTCM GLONASS slots
831 // ------------------
832 if (decoder()->_gloFrq.size()) {
833 bool allFound = true;
834 QString slot = decoder()->_gloFrq;
835 slot.replace(" "," ").replace(" ",":");
836 if (_gloSlots.indexOf(slot) == -1) {
837 _gloSlots.append(slot);
838 allFound = false;
839 }
840 if (!allFound) {
841 _gloSlots.sort();
842 emit(newMessage(_staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toAscii(), true));
843 }
844 }
845 }
846 }
847
848#ifdef MLS_SOFTWARE
849 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
850 QByteArray antT;
851 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
852 antT = "ARP";
853 }
854 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
855 antT = "APC";
856 }
857 double hh = 0.0;
858 if (decoder()->_antList[ii].height_f) {
859 hh = decoder()->_antList[ii].height;
860 }
861 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
862 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
863 hh, antT));
864 }
865
866 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
867 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
868 }
869#endif
870
871 decoder()->_gloFrq.clear();
872 decoder()->_typeList.clear();
873 decoder()->_antType.clear();
874 decoder()->_antList.clear();
875}
876
877// Handle Data from Serial Port
878////////////////////////////////////////////////////////////////////////////
879void bncGetThread::slotSerialReadyRead() {
880
881 if (_serialPort) {
882
883 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
884 if (_manualNMEASampl) {
885 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
886 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
887 _query->sendNMEA(_manualNMEAString);
888 _lastManualNMEA = QDateTime::currentDateTime();
889 }
890 }
891 }
892
893 int nb = _serialPort->bytesAvailable();
894 if (nb > 0) {
895 QByteArray data = _serialPort->read(nb);
896
897 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
898 int i1 = data.indexOf("$GPGGA");
899 if (i1 == -1) {
900 i1 = data.indexOf("$GNGGA");
901 }
902 if (i1 != -1) {
903 int i2 = data.indexOf("*", i1);
904 if (i2 != -1 && data.size() > i2 + 1) {
905 QByteArray gga = data.mid(i1, i2 - i1 + 3);
906 _query->sendNMEA(gga);
907 }
908 }
909 }
910
911 if (_serialOutFile) {
912 _serialOutFile->write(data);
913 _serialOutFile->flush();
914 }
915 }
916 }
917}
918
919void bncGetThread::slotNewNMEAConnection() {
920 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
921 emit( newMessage(QString("New PPP client on port: # %1")
922 .arg(_nmeaSockets->size()).toAscii(), true) );
923}
924
925//
926////////////////////////////////////////////////////////////////////////////
927void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
928 if (_nmeaPortsMap.contains(staID)) {
929 int nmeaPort = _nmeaPortsMap.value(staID);
930 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
931 while (is.hasNext()) {
932 QTcpSocket* sock = is.next();
933 if (sock->localPort() == nmeaPort) {
934 if (sock->state() == QAbstractSocket::ConnectedState) {
935 sock->write(str);
936 }
937 else if (sock->state() != QAbstractSocket::ConnectingState) {
938 delete sock;
939 is.remove();
940 }
941 }
942 }
943 }
944}
Note: See TracBrowser for help on using the repository browser.