source: ntrip/branches/BNC_LM/bncgetthread.cpp@ 8282

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