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

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

minor changes for sending manual nmea

File size: 24.9 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 // Serial Port
131 // -----------
132 _serialNMEA = NO_NMEA;
133 _serialOutFile = 0;
134 _serialPort = 0;
135
136 if (!_staID.isEmpty() &&
137 settings.value("serialMountPoint").toString() == _staID) {
138 _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
139 _serialPort->setTimeout(0,100);
140
141 // Baud Rate
142 // ---------
143 QString hlp = settings.value("serialBaudRate").toString();
144 if (hlp == "110") {
145 _serialPort->setBaudRate(BAUD110);
146 }
147 else if (hlp == "300") {
148 _serialPort->setBaudRate(BAUD300);
149 }
150 else if (hlp == "600") {
151 _serialPort->setBaudRate(BAUD600);
152 }
153 else if (hlp == "1200") {
154 _serialPort->setBaudRate(BAUD1200);
155 }
156 else if (hlp == "2400") {
157 _serialPort->setBaudRate(BAUD2400);
158 }
159 else if (hlp == "4800") {
160 _serialPort->setBaudRate(BAUD4800);
161 }
162 else if (hlp == "9600") {
163 _serialPort->setBaudRate(BAUD9600);
164 }
165 else if (hlp == "19200") {
166 _serialPort->setBaudRate(BAUD19200);
167 }
168 else if (hlp == "38400") {
169 _serialPort->setBaudRate(BAUD38400);
170 }
171 else if (hlp == "57600") {
172 _serialPort->setBaudRate(BAUD57600);
173 }
174 else if (hlp == "115200") {
175 _serialPort->setBaudRate(BAUD115200);
176 }
177
178 // Parity
179 // ------
180 hlp = settings.value("serialParity").toString();
181 if (hlp == "NONE") {
182 _serialPort->setParity(PAR_NONE);
183 }
184 else if (hlp == "ODD") {
185 _serialPort->setParity(PAR_ODD);
186 }
187 else if (hlp == "EVEN") {
188 _serialPort->setParity(PAR_EVEN);
189 }
190 else if (hlp == "SPACE") {
191 _serialPort->setParity(PAR_SPACE);
192 }
193
194 // Data Bits
195 // ---------
196 hlp = settings.value("serialDataBits").toString();
197 if (hlp == "5") {
198 _serialPort->setDataBits(DATA_5);
199 }
200 else if (hlp == "6") {
201 _serialPort->setDataBits(DATA_6);
202 }
203 else if (hlp == "7") {
204 _serialPort->setDataBits(DATA_7);
205 }
206 else if (hlp == "8") {
207 _serialPort->setDataBits(DATA_8);
208 }
209 hlp = settings.value("serialStopBits").toString();
210 if (hlp == "1") {
211 _serialPort->setStopBits(STOP_1);
212 }
213 else if (hlp == "2") {
214 _serialPort->setStopBits(STOP_2);
215 }
216
217 // Flow Control
218 // ------------
219 hlp = settings.value("serialFlowControl").toString();
220 if (hlp == "XONXOFF") {
221 _serialPort->setFlowControl(FLOW_XONXOFF);
222 }
223 else if (hlp == "HARDWARE") {
224 _serialPort->setFlowControl(FLOW_HARDWARE);
225 }
226 else {
227 _serialPort->setFlowControl(FLOW_OFF);
228 }
229
230 // Open Serial Port
231 // ----------------
232 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
233 if (!_serialPort->isOpen()) {
234 delete _serialPort;
235 _serialPort = 0;
236 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
237 }
238 connect(_serialPort, SIGNAL(readyRead()),
239 this, SLOT(slotSerialReadyRead()));
240
241 // Automatic NMEA
242 // --------------
243 if (settings.value("serialAutoNMEA").toString() == "Auto") {
244 _serialNMEA = AUTO_NMEA;
245
246 QString fName = settings.value("serialFileNMEA").toString();
247 if (!fName.isEmpty()) {
248 _serialOutFile = new QFile(fName);
249 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
250 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
251 }
252 else {
253 _serialOutFile->open(QIODevice::WriteOnly);
254 }
255 }
256 }
257
258 // Manual NMEA
259 // -----------
260 if (settings.value("serialAutoNMEA").toString() == "Manual") {
261 _serialNMEA = MANUAL_NMEA;
262 bncSettings settings;
263 _manualNMEASampl = settings.value("serialManualNMEASampling").toInt();
264 QString hlp = settings.value("serialHeightNMEA").toString();
265 if (hlp.isEmpty()) {
266 hlp = "0.0";
267 }
268 QByteArray _serialHeightNMEA = hlp.toAscii();
269 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA);
270 }
271 }
272
273 if (!_staID.isEmpty()) {
274 _latencyChecker = new latencyChecker(_staID);
275 }
276 else {
277 _latencyChecker = 0;
278 }
279}
280
281// Instantiate the decoder
282//////////////////////////////////////////////////////////////////////////////
283t_irc bncGetThread::initDecoder() {
284
285 _decoder = 0;
286
287 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
288 _format.indexOf("RTCM 2") != -1 ) {
289 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
290 _decoder = new RTCM2Decoder(_staID.data());
291 }
292 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
293 _format.indexOf("RTCM 3") != -1 ) {
294 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
295 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
296 _decoder = newDecoder;
297 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
298 this, SIGNAL(newMessage(QByteArray,bool)));
299 }
300 else if (_format.indexOf("ZERO") != -1) {
301 emit(newMessage(_staID + ": Get data in original format", true));
302 _decoder = new bncZeroDecoder(_staID);
303 }
304 else if (_format.indexOf("RTNET") != -1) {
305 emit(newMessage(_staID + ": Get data in RTNet format", true));
306 _decoder = new bncRtnetDecoder();
307 }
308 else {
309 emit(newMessage(_staID + ": Unknown data format " + _format, true));
310 _isToBeDeleted = true;
311 return failure;
312 }
313
314 msleep(100); //sleep 0.1 sec
315
316 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
317 _nmea, _ntripVersion);
318
319 if (_rawFile) {
320 _decodersRaw[_staID] = _decoder;
321 }
322
323 return success;
324}
325
326// Current decoder in use
327////////////////////////////////////////////////////////////////////////////
328GPSDecoder* bncGetThread::decoder() {
329 if (!_rawFile) {
330 return _decoder;
331 }
332 else {
333 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
334 return _decodersRaw[_staID];
335 }
336 }
337 return 0;
338}
339
340// Destructor
341////////////////////////////////////////////////////////////////////////////
342bncGetThread::~bncGetThread() {
343 if (isRunning()) {
344 wait();
345 }
346 if (_query) {
347 _query->stop();
348 _query->deleteLater();
349 }
350 if (_rawFile) {
351 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
352 while (it.hasNext()) {
353 it.next();
354 delete it.value();
355 }
356 }
357 else {
358 delete _decoder;
359 }
360 delete _rawFile;
361 delete _serialOutFile;
362 delete _serialPort;
363 delete _latencyChecker;
364 emit getThreadFinished(_staID);
365}
366
367//
368////////////////////////////////////////////////////////////////////////////
369void bncGetThread::terminate() {
370 _isToBeDeleted = true;
371 if (!isRunning()) {
372 delete this;
373 }
374}
375
376// Run
377////////////////////////////////////////////////////////////////////////////
378void bncGetThread::run() {
379
380 while (true) {
381 try {
382 if (_isToBeDeleted) {
383 QThread::exit(0);
384 this->deleteLater();
385 return;
386 }
387
388 if (tryReconnect() != success) {
389 if (_latencyChecker) {
390 _latencyChecker->checkReconnect();
391 }
392 continue;
393 }
394
395 // Delete old observations
396 // -----------------------
397 if (_rawFile) {
398 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
399 while (itDec.hasNext()) {
400 itDec.next();
401 GPSDecoder* decoder = itDec.value();
402 decoder->_obsList.clear();
403 }
404 }
405 else {
406 _decoder->_obsList.clear();
407 }
408
409 // Read Data
410 // ---------
411 QByteArray data;
412 if (_query) {
413 _query->waitForReadyRead(data);
414 }
415 else if (_rawFile) {
416 data = _rawFile->readChunk();
417 _format = _rawFile->format();
418 _staID = _rawFile->staID();
419
420 QCoreApplication::processEvents();
421
422 if (data.isEmpty()) {
423 cout << "no more data" << endl;
424 BNC_CORE->stopCombination();
425 BNC_CORE->stopPPP();
426 ::exit(0);
427 }
428 }
429 qint64 nBytes = data.size();
430
431 // Timeout, reconnect
432 // ------------------
433 if (nBytes == 0) {
434 if (_latencyChecker) {
435 _latencyChecker->checkReconnect();
436 }
437 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
438 msleep(10000); //sleep 10 sec, G. Weber
439 continue;
440 }
441 else {
442 emit newBytes(_staID, nBytes);
443 emit newRawData(_staID, data);
444 }
445
446 // Output Data
447 // -----------
448 if (_rawOutput) {
449 BNC_CORE->writeRawData(data, _staID, _format);
450 }
451
452 if (_serialPort) {
453 slotSerialReadyRead();
454 _serialPort->write(data);
455 }
456
457 // Decode Data
458 // -----------
459 vector<string> errmsg;
460 if (!decoder()) {
461 _isToBeDeleted = true;
462 continue;
463 }
464 decoder()->_obsList.clear();
465 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
466
467 // Perform various scans and checks
468 // --------------------------------
469 if (_latencyChecker) {
470 _latencyChecker->checkOutage(irc == success);
471 _latencyChecker->checkObsLatency(decoder()->_obsList);
472 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
473
474 emit newLatency(_staID, _latencyChecker->currentLatency());
475 }
476
477 scanRTCM();
478
479 // Loop over all observations (observations output)
480 // ------------------------------------------------
481 QListIterator<t_satObs> it(decoder()->_obsList);
482
483 QList<t_satObs> obsListHlp;
484
485 while (it.hasNext()) {
486 const t_satObs& obs = it.next();
487
488 QString prn(obs._prn.toString().c_str());
489 long iSec = long(floor(obs._time.gpssec()+0.5));
490 long obsTime = obs._time.gpsw()*7*24*3600 + iSec;
491
492 // Check observation epoch
493 // -----------------------
494 if (!_rawFile) {
495 int week;
496 double sec;
497 currentGPSWeeks(week, sec);
498 long currTime = week * 7*24*3600 + long(sec);
499 const double maxDt = 600.0;
500 if (fabs(currTime - obsTime) > maxDt) {
501 emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
502 continue;
503 }
504 }
505
506 // Check observations coming twice (e.g. KOUR0 Problem)
507 // ----------------------------------------------------
508 if (!_rawFile) {
509 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
510 if (it != _prnLastEpo.end()) {
511 long oldTime = it.value();
512 if (obsTime < oldTime) {
513 emit( newMessage(_staID +
514 ": old observation " + prn.toAscii(), false));
515 continue;
516 }
517 else if (obsTime == oldTime) {
518 emit( newMessage(_staID +
519 ": observation coming more than once " + prn.toAscii(), false));
520 continue;
521 }
522 }
523 _prnLastEpo[prn] = obsTime;
524 }
525
526 decoder()->dumpRinexEpoch(obs, _format);
527
528 // Save observations
529 // -----------------
530 obsListHlp.append(obs);
531 }
532
533 // Emit signal
534 // -----------
535 if (!_isToBeDeleted && obsListHlp.size() > 0) {
536 emit newObs(_staID, obsListHlp);
537 }
538
539 decoder()->_obsList.clear();
540 }
541 catch (Exception& exc) {
542 emit(newMessage(_staID + " " + exc.what(), true));
543 _isToBeDeleted = true;
544 }
545 catch (...) {
546 emit(newMessage(_staID + " bncGetThread exception", true));
547 _isToBeDeleted = true;
548 }
549 }
550}
551
552// Try Re-Connect
553////////////////////////////////////////////////////////////////////////////
554t_irc bncGetThread::tryReconnect() {
555
556 // Easy Return
557 // -----------
558 if (_query && _query->status() == bncNetQuery::running) {
559 _nextSleep = 0;
560 if (_rawFile) {
561 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
562 while (itDec.hasNext()) {
563 itDec.next();
564 GPSDecoder* decoder = itDec.value();
565 decoder->setRinexReconnectFlag(false);
566 }
567 }
568 else {
569 _decoder->setRinexReconnectFlag(false);
570 }
571 return success;
572 }
573
574 // Start a new query
575 // -----------------
576 if (!_rawFile) {
577
578 sleep(_nextSleep);
579 if (_nextSleep == 0) {
580 _nextSleep = 1;
581 }
582 else {
583 _nextSleep = 2 * _nextSleep;
584 if (_nextSleep > 256) {
585 _nextSleep = 256;
586 }
587#ifdef MLS_SOFTWARE
588 if (_nextSleep > 4) {
589 _nextSleep = 4;
590 }
591#endif
592 }
593
594 delete _query;
595 if (_ntripVersion == "U") {
596 _query = new bncNetQueryUdp();
597 }
598 else if (_ntripVersion == "R") {
599 _query = new bncNetQueryRtp();
600 }
601 else if (_ntripVersion == "S") {
602 _query = new bncNetQueryS();
603 }
604 else if (_ntripVersion == "N") {
605 _query = new bncNetQueryV0();
606 }
607 else if (_ntripVersion == "UN") {
608 _query = new bncNetQueryUdp0();
609 }
610 else if (_ntripVersion == "2") {
611 _query = new bncNetQueryV2(false);
612 }
613 else if (_ntripVersion == "2s") {
614 _query = new bncNetQueryV2(true);
615 }
616 else {
617 _query = new bncNetQueryV1();
618 }
619 if (_nmea == "yes") {
620 if (_serialNMEA == MANUAL_NMEA) {
621 _query->startRequest(_mountPoint, _manualNMEAString);
622 _lastManualNMEA = QDateTime::currentDateTime();
623 }
624 else if (_serialNMEA == AUTO_NMEA) {
625 if (_serialPort) {
626 int nb = _serialPort->bytesAvailable();
627 if (nb > 0) {
628 QByteArray data = _serialPort->read(nb);
629 int i1 = data.indexOf("$GPGGA");
630 if (i1 == -1) {
631 i1 = data.indexOf("$GNGGA");
632 }
633 if (i1 != -1) {
634 int i2 = data.indexOf("*", i1);
635 if (i2 != -1 && data.size() > i2 + 1) {
636 QByteArray gga = data.mid(i1, i2 - i1 + 3);
637 _query->startRequest(_mountPoint, gga);
638 }
639 }
640 }
641 }
642 }
643 }
644 else {
645 _query->startRequest(_mountPoint, "");
646 }
647
648 if (_query->status() != bncNetQuery::running) {
649 return failure;
650 }
651 }
652
653 if (_rawFile) {
654 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
655 while (itDec.hasNext()) {
656 itDec.next();
657 GPSDecoder* decoder = itDec.value();
658 decoder->setRinexReconnectFlag(false);
659 }
660 }
661 else {
662 _decoder->setRinexReconnectFlag(false);
663 }
664
665 return success;
666}
667
668// RTCM scan output
669//////////////////////////////////////////////////////////////////////////////
670void bncGetThread::scanRTCM() {
671
672 if ( !decoder() ) {
673 return;
674 }
675
676 bncSettings settings;
677 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
678
679 if ( _miscMount == _staID || _miscMount == "ALL" ) {
680 // RTCM message types
681 // ------------------
682 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
683 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
684 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
685 }
686
687 // Check Observation Types
688 // -----------------------
689 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
690 t_satObs& obs = decoder()->_obsList[ii];
691 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
692 bool allFound = true;
693 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
694 if (obs._obs[iFrq]->_codeValid) {
695 QString rnxStr('C');
696 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
697 if (_format.indexOf("RTCM_2") != -1 ||
698 _format.indexOf("RTCM2") != -1 ||
699 _format.indexOf("RTCM 2") != -1 ) {
700 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
701 }
702 if (rnxTypes.indexOf(rnxStr) == -1) {
703 rnxTypes.push_back(rnxStr);
704 allFound = false;
705 }
706 }
707 if (obs._obs[iFrq]->_phaseValid) {
708 QString rnxStr('L');
709 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
710 if (_format.indexOf("RTCM_2") != -1 ||
711 _format.indexOf("RTCM2") != -1 ||
712 _format.indexOf("RTCM 2") != -1 ) {
713 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
714 }
715 if (rnxTypes.indexOf(rnxStr) == -1) {
716 rnxTypes.push_back(rnxStr);
717 allFound = false;
718 }
719 }
720 if (obs._obs[iFrq]->_dopplerValid){
721 QString rnxStr('D');
722 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
723 if (_format.indexOf("RTCM_2") != -1 ||
724 _format.indexOf("RTCM2") != -1 ||
725 _format.indexOf("RTCM 2") != -1 ) {
726 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
727 }
728 if (rnxTypes.indexOf(rnxStr) == -1) {
729 rnxTypes.push_back(rnxStr);
730 allFound = false;
731 }
732 }
733 if (obs._obs[iFrq]->_snrValid){
734 QString rnxStr('S');
735 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
736 if (_format.indexOf("RTCM_2") != -1 ||
737 _format.indexOf("RTCM2") != -1 ||
738 _format.indexOf("RTCM 2") != -1 ) {
739 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
740 }
741 if (rnxTypes.indexOf(rnxStr) == -1) {
742 rnxTypes.push_back(rnxStr);
743 allFound = false;
744 }
745 }
746 }
747 if (!allFound) {
748 QString msg;
749 QTextStream str(&msg);
750 QString s;
751 str << obs._prn.system() << " " << s.sprintf("%2d", rnxTypes.size()) << " ";
752 for (int iType = 0; iType < rnxTypes.size(); iType++) {
753 str << " " << rnxTypes[iType];
754 }
755 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
756 }
757 }
758
759 // RTCMv3 antenna descriptor
760 // -------------------------
761 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
762 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
763 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
764 }
765
766 // RTCM Antenna Coordinates
767 // ------------------------
768 for (int ii=0; ii < decoder()->_antList.size(); ii++) {
769 QByteArray antT;
770 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
771 antT = "ARP";
772 }
773 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
774 antT = "APC";
775 }
776 QByteArray ant1, ant2, ant3;
777 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
778 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
779 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
780 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
781 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
782 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
783 double hh = 0.0;
784 if (decoder()->_antList[ii].height_f) {
785 hh = decoder()->_antList[ii].height;
786 QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
787 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
788 }
789 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
790 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
791 hh, antT));
792 }
793 }
794 }
795
796#ifdef MLS_SOFTWARE
797 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
798 QByteArray antT;
799 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
800 antT = "ARP";
801 }
802 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
803 antT = "APC";
804 }
805 double hh = 0.0;
806 if (decoder()->_antList[ii].height_f) {
807 hh = decoder()->_antList[ii].height;
808 }
809 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
810 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
811 hh, antT));
812 }
813
814 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
815 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
816 }
817#endif
818
819 decoder()->_typeList.clear();
820 decoder()->_antType.clear();
821 decoder()->_antList.clear();
822}
823
824// Handle Data from Serial Port
825////////////////////////////////////////////////////////////////////////////
826void bncGetThread::slotSerialReadyRead() {
827
828 if (_serialPort) {
829
830 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
831 if (_manualNMEASampl) {
832 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
833 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
834 _query->sendNMEA(_manualNMEAString);
835 _lastManualNMEA = QDateTime::currentDateTime();
836 }
837 }
838 }
839
840 int nb = _serialPort->bytesAvailable();
841 if (nb > 0) {
842 QByteArray data = _serialPort->read(nb);
843
844 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
845 int i1 = data.indexOf("$GPGGA");
846 if (i1 == -1) {
847 i1 = data.indexOf("$GNGGA");
848 }
849 if (i1 != -1) {
850 int i2 = data.indexOf("*", i1);
851 if (i2 != -1 && data.size() > i2 + 1) {
852 QByteArray gga = data.mid(i1, i2 - i1 + 3);
853 _query->sendNMEA(gga);
854 }
855 }
856 }
857
858 if (_serialOutFile) {
859 _serialOutFile->write(data);
860 _serialOutFile->flush();
861 }
862 }
863 }
864}
Note: See TracBrowser for help on using the repository browser.