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

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

minor changes to allow a clean end of program

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