source: ntrip/trunk/BNC/bncgetthread.cpp@ 2032

Last change on this file since 2032 was 2032, checked in by mervart, 14 years ago

* empty log message *

File size: 20.5 KB
RevLine 
[280]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[280]3//
[464]4// Copyright (C) 2007
[280]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[280]8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
[35]24
25/* -------------------------------------------------------------------------
[93]26 * BKG NTRIP Client
[35]27 * -------------------------------------------------------------------------
28 *
29 * Class: bncGetThread
30 *
31 * Purpose: Thread that retrieves data from NTRIP caster
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Dec-2005
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
[277]41#include <stdlib.h>
[1044]42#include <iomanip>
[1218]43#include <sstream>
[277]44
[35]45#include <QFile>
46#include <QTextStream>
47#include <QtNetwork>
[356]48#include <QTime>
[35]49
50#include "bncgetthread.h"
[192]51#include "bnctabledlg.h"
[243]52#include "bncapp.h"
[352]53#include "bncutils.h"
[408]54#include "bncrinex.h"
[423]55#include "bnczerodecoder.h"
[1621]56#include "bncnetqueryv0.h"
[1387]57#include "bncnetqueryv1.h"
58#include "bncnetqueryv2.h"
[1410]59#include "bncnetqueryrtp.h"
[1721]60#include "bncnetqueryudp.h"
[1779]61#include "bncnetqueryudp0.h"
[1753]62#include "bncnetquerys.h"
[1535]63#include "bncsettings.h"
[1558]64#include "latencychecker.h"
[2000]65#include "bncpppthread.h"
[65]66
[243]67#include "RTCM/RTCM2Decoder.h"
[297]68#include "RTCM3/RTCM3Decoder.h"
[293]69#include "RTIGS/RTIGSDecoder.h"
[1310]70#include "GPSS/gpssDecoder.h"
[1318]71#include "serial/qextserialport.h"
[35]72
73using namespace std;
74
[1143]75// Constructor 1
[35]76////////////////////////////////////////////////////////////////////////////
[1138]77bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
78 const QByteArray& format) {
79
80 _rawInpFile = new QFile(rawInpFileName);
81 _rawInpFile->open(QIODevice::ReadOnly);
[1555]82 _format = format;
83 _staID = rawInpFileName.mid(
84 rawInpFileName.lastIndexOf(QDir::separator())+1,4);
[1147]85
[1555]86 initialize();
[1138]87}
88
[1143]89// Constructor 2
90////////////////////////////////////////////////////////////////////////////
[278]91bncGetThread::bncGetThread(const QUrl& mountPoint,
[366]92 const QByteArray& format,
93 const QByteArray& latitude,
94 const QByteArray& longitude,
[1353]95 const QByteArray& nmea,
[1770]96 const QByteArray& ntripVersion, const QByteArray& extraStaID) {
[1555]97 _rawInpFile = 0;
98 _mountPoint = mountPoint;
[1770]99 _staID = (extraStaID.size() == 0 ? mountPoint.path().mid(1).toAscii() : extraStaID);
[1555]100 _format = format;
101 _latitude = latitude;
102 _longitude = longitude;
103 _nmea = nmea;
[1353]104 _ntripVersion = ntripVersion;
[1139]105
106 initialize();
107}
108
[1555]109// Initialization (common part of the constructor)
[1143]110////////////////////////////////////////////////////////////////////////////
[1139]111void bncGetThread::initialize() {
112
[1555]113 setTerminationEnabled(true);
114
[1225]115 bncApp* app = (bncApp*) qApp;
116
[1555]117 connect(this, SIGNAL(newMessage(QByteArray,bool)),
118 app, SLOT(slotMessage(const QByteArray,bool)));
119
[1525]120 _isToBeDeleted = false;
[1555]121 _decoder = 0;
122 _query = 0;
123 _nextSleep = 0;
124 _rawOutFile = 0;
[2000]125 _PPPthread = 0;
[255]126
[1574]127 bncSettings settings;
[1595]128
[1574]129 _miscMount = settings.value("miscMount").toString();
130
[408]131 // RINEX writer
132 // ------------
133 _samplingRate = settings.value("rnxSampl").toInt();
134 if ( settings.value("rnxPath").toString().isEmpty() ) {
135 _rnx = 0;
[1555]136 if (_rawInpFile) {
137 cerr << "no RINEX path specified" << endl;
138 ::exit(1);
139 }
[408]140 }
141 else {
[1353]142 _rnx = new bncRinex(_staID, _mountPoint, _format, _latitude,
[1639]143 _longitude, _nmea, _ntripVersion);
[408]144 }
145
[1555]146 // Serial Port
147 // -----------
[1710]148 _serialNMEA = NO_NMEA;
149 _serialOutFile = 0;
150 _serialPort = 0;
151
[1327]152 if (settings.value("serialMountPoint").toString() == _staID) {
[1710]153 _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
154 _serialPort->setTimeout(0,100);
155
156 // Baud Rate
157 // ---------
[1330]158 QString hlp = settings.value("serialBaudRate").toString();
159 if (hlp == "110") {
160 _serialPort->setBaudRate(BAUD110);
161 }
162 else if (hlp == "300") {
163 _serialPort->setBaudRate(BAUD300);
164 }
165 else if (hlp == "600") {
166 _serialPort->setBaudRate(BAUD600);
167 }
168 else if (hlp == "1200") {
169 _serialPort->setBaudRate(BAUD1200);
170 }
171 else if (hlp == "2400") {
172 _serialPort->setBaudRate(BAUD2400);
173 }
174 else if (hlp == "4800") {
175 _serialPort->setBaudRate(BAUD4800);
176 }
177 else if (hlp == "9600") {
178 _serialPort->setBaudRate(BAUD9600);
179 }
180 else if (hlp == "19200") {
181 _serialPort->setBaudRate(BAUD19200);
182 }
183 else if (hlp == "38400") {
184 _serialPort->setBaudRate(BAUD38400);
185 }
186 else if (hlp == "57600") {
187 _serialPort->setBaudRate(BAUD57600);
188 }
189 else if (hlp == "115200") {
190 _serialPort->setBaudRate(BAUD115200);
191 }
[1710]192
193 // Parity
194 // ------
[1330]195 hlp = settings.value("serialParity").toString();
196 if (hlp == "NONE") {
197 _serialPort->setParity(PAR_NONE);
198 }
199 else if (hlp == "ODD") {
200 _serialPort->setParity(PAR_ODD);
201 }
202 else if (hlp == "EVEN") {
203 _serialPort->setParity(PAR_EVEN);
204 }
205 else if (hlp == "SPACE") {
206 _serialPort->setParity(PAR_SPACE);
207 }
[1710]208
209 // Data Bits
210 // ---------
[1330]211 hlp = settings.value("serialDataBits").toString();
212 if (hlp == "5") {
213 _serialPort->setDataBits(DATA_5);
214 }
215 else if (hlp == "6") {
216 _serialPort->setDataBits(DATA_6);
217 }
218 else if (hlp == "7") {
219 _serialPort->setDataBits(DATA_7);
220 }
221 else if (hlp == "8") {
222 _serialPort->setDataBits(DATA_8);
223 }
224 hlp = settings.value("serialStopBits").toString();
225 if (hlp == "1") {
226 _serialPort->setStopBits(STOP_1);
227 }
228 else if (hlp == "2") {
229 _serialPort->setStopBits(STOP_2);
230 }
[1710]231
232 // Flow Control
233 // ------------
234 hlp = settings.value("serialFlowControl").toString();
[1711]235 if (hlp == "XONXOFF") {
[1710]236 _serialPort->setFlowControl(FLOW_XONXOFF);
237 }
238 else if (hlp == "HARDWARE") {
239 _serialPort->setFlowControl(FLOW_HARDWARE);
240 }
[1711]241 else {
242 _serialPort->setFlowControl(FLOW_OFF);
243 }
[1710]244
245 // Open Serial Port
246 // ----------------
[1326]247 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
[1331]248 if (!_serialPort->isOpen()) {
249 delete _serialPort;
250 _serialPort = 0;
[1451]251 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
[1331]252 }
[1606]253 connect(_serialPort, SIGNAL(readyRead()),
254 this, SLOT(slotSerialReadyRead()));
255
[1710]256 // Automatic NMEA
257 // --------------
258 if (settings.value("serialAutoNMEA").toString() == "Auto") {
259 _serialNMEA = AUTO_NMEA;
260
261 QString fName = settings.value("serialFileNMEA").toString();
262 if (!fName.isEmpty()) {
263 _serialOutFile = new QFile(fName);
264 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
265 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
266 }
267 else {
268 _serialOutFile->open(QIODevice::WriteOnly);
269 }
[1634]270 }
[1606]271 }
[1710]272
273 // Manual NMEA
274 // -----------
275 else {
276 _serialNMEA = MANUAL_NMEA;
[1636]277 }
[1318]278 }
279
[1137]280 // Raw Output
281 // ----------
[1140]282 // QByteArray rawOutFileName = "./" + _staID + ".raw";
283 // _rawOutFile = new QFile(rawOutFileName);
284 // _rawOutFile->open(QIODevice::WriteOnly);
[1137]285
[2004]286 // Initialize PPP Clinet?
287 // ----------------------
288 bool pppClient = false;
289 if (settings.value("pppMount").toString() == _staID) {
290 pppClient = true;
291 }
[1555]292
293 // Instantiate the decoder
294 // -----------------------
[1744]295 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
296 _format.indexOf("RTCM 2") != -1 ) {
[1555]297 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
298 _decoder = new RTCM2Decoder(_staID.data());
[2004]299 if (pppClient) {
300 _PPPthread = new bncPPPthread(_staID);
301 }
[1555]302 }
[1744]303 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
304 _format.indexOf("RTCM 3") != -1 ) {
[1555]305 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
306 _decoder = new RTCM3Decoder(_staID);
307 connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
308 this, SIGNAL(newMessage(QByteArray,bool)));
[2004]309 if (pppClient) {
310 _PPPthread = new bncPPPthread(_staID);
311 }
[1555]312 }
313 else if (_format.indexOf("RTIGS") != -1) {
314 emit(newMessage(_staID + ": Get data in RTIGS format", true));
315 _decoder = new RTIGSDecoder();
[2004]316 if (pppClient) {
317 _PPPthread = new bncPPPthread(_staID);
318 }
[1555]319 }
320 else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
321 emit(newMessage(_staID + ": Get Data in GPSS format", true));
322 _decoder = new gpssDecoder();
323 }
324 else if (_format.indexOf("ZERO") != -1) {
325 emit(newMessage(_staID + ": Get data in original format", true));
326 _decoder = new bncZeroDecoder(_staID);
327 }
328 else {
329 emit(newMessage(_staID + ": Unknown data format " + _format, true));
330 _isToBeDeleted = true;
331 }
332
[1558]333 _latencyChecker = new latencyChecker(_staID);
[1557]334
[2030]335 if (_PPPthread) {
336 connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
337 _PPPthread, SLOT(slotNewEphGPS(gpsephemeris)));
338 connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
339 _PPPthread, SLOT(slotNewCorrections(QList<QString>)));
[2032]340 //// _PPPthread->start(); // currently processing in the same thread
[2030]341 }
342
[319]343 msleep(100); //sleep 0.1 sec
[35]344}
345
346// Destructor
347////////////////////////////////////////////////////////////////////////////
348bncGetThread::~bncGetThread() {
[1928]349
[2000]350 if (_PPPthread) {
351 _PPPthread->terminate();
352 }
353
[1928]354 if (isRunning()) {
355 wait();
356 }
357
[1527]358 if (_query) {
359 _query->stop();
[1708]360 _query->deleteLater();
[1527]361 }
[617]362 delete _decoder;
[1044]363 delete _rnx;
[1138]364 delete _rawInpFile;
365 delete _rawOutFile;
[1607]366 delete _serialOutFile;
[1328]367 delete _serialPort;
[1557]368 delete _latencyChecker;
[1556]369 emit getThreadFinished(_staID);
[35]370}
371
[1390]372//
373////////////////////////////////////////////////////////////////////////////
374void bncGetThread::terminate() {
[1525]375 _isToBeDeleted = true;
[1559]376 if (!isRunning()) {
377 delete this;
378 }
[1390]379}
380
[136]381// Run
382////////////////////////////////////////////////////////////////////////////
383void bncGetThread::run() {
384
[35]385 while (true) {
[629]386 try {
[1555]387 if (_isToBeDeleted) {
388 QThread::exit(0);
389 this->deleteLater();
390 return;
[629]391 }
[621]392
[1555]393 if (tryReconnect() != success) {
[1572]394 _latencyChecker->checkReconnect();
[1555]395 continue;
[621]396 }
[1555]397
398 // Delete old observations
399 // -----------------------
400 QListIterator<p_obs> itOld(_decoder->_obsList);
401 while (itOld.hasNext()) {
402 delete itOld.next();
403 }
[621]404 _decoder->_obsList.clear();
405
[1555]406 // Read Data
407 // ---------
[1377]408 QByteArray data;
409 if (_query) {
410 _query->waitForReadyRead(data);
[1138]411 }
412 else if (_rawInpFile) {
[1146]413 const qint64 maxBytes = 1024;
[1555]414 data = _rawInpFile->read(maxBytes);
415 if (data.isEmpty()) {
416 cout << "no more data" << endl;
417 ::exit(0);
418 }
[1138]419 }
[1555]420 qint64 nBytes = data.size();
[1138]421
[1555]422 // Timeout, reconnect
423 // ------------------
424 if (nBytes == 0) {
[1576]425 _latencyChecker->checkReconnect();
[1555]426 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
427 continue;
428 }
429 else {
[567]430 emit newBytes(_staID, nBytes);
[1555]431 }
[567]432
[1555]433 // Output Data
434 // -----------
435 if (_rawOutFile) {
436 _rawOutFile->write(data);
437 _rawOutFile->flush();
438 }
439 if (_serialPort) {
[1633]440 slotSerialReadyRead();
[1555]441 _serialPort->write(data);
442 }
443
444 // Decode Data
445 // -----------
446 vector<string> errmsg;
[1562]447 t_irc irc = _decoder->Decode(data.data(), data.size(), errmsg);
[1137]448
[1555]449 // Perform various scans and checks
450 // --------------------------------
[1562]451 _latencyChecker->checkOutage(irc == success);
452 _latencyChecker->checkObsLatency(_decoder->_obsList);
[1567]453 _latencyChecker->checkCorrLatency(_decoder->corrGPSEpochTime());
454
[1973]455 emit newLatency(_staID, _latencyChecker->currentLatency());
[1969]456
[1555]457 scanRTCM();
[1138]458
[1555]459 // Loop over all observations (observations output)
460 // ------------------------------------------------
461 QListIterator<p_obs> it(_decoder->_obsList);
462 while (it.hasNext()) {
463 p_obs obs = it.next();
464
465 // Check observation epoch
466 // -----------------------
467 if (!_rawInpFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
468 int week;
469 double sec;
470 currentGPSWeeks(week, sec);
471 const double secPerWeek = 7.0 * 24.0 * 3600.0;
472
473 if (week < obs->_o.GPSWeek) {
474 week += 1;
475 sec -= secPerWeek;
[1218]476 }
[1555]477 if (week > obs->_o.GPSWeek) {
478 week -= 1;
479 sec += secPerWeek;
[650]480 }
[1555]481 double dt = fabs(sec - obs->_o.GPSWeeks);
482 const double maxDt = 600.0;
483 if (week != obs->_o.GPSWeek || dt > maxDt) {
484 emit( newMessage(_staID + ": Wrong observation epoch(s)", true) );
485 delete obs;
486 continue;
[940]487 }
[686]488 }
[1555]489
490 // RINEX Output
491 // ------------
492 if (_rnx) {
493 long iSec = long(floor(obs->_o.GPSWeeks+0.5));
494 long newTime = obs->_o.GPSWeek * 7*24*3600 + iSec;
495 if (_samplingRate == 0 || iSec % _samplingRate == 0) {
496 _rnx->deepCopy(obs);
[1271]497 }
[1555]498 _rnx->dumpEpoch(newTime);
[1271]499 }
[1555]500
[2030]501 // PPP Client
502 // ----------
503 if (_PPPthread) {
504 _PPPthread->putNewObs(obs);
505 }
506
[1555]507 // Emit new observation signal
508 // ---------------------------
509 bool firstObs = (obs == _decoder->_obsList.first());
510 obs->_status = t_obs::posted;
511 emit newObs(_staID, firstObs, obs);
[249]512 }
[1555]513 _decoder->_obsList.clear();
[35]514 }
[1555]515 catch (...) {
[1559]516 emit(newMessage(_staID + "bncGetThread exception", true));
517 _isToBeDeleted = true;
[1555]518 }
[35]519 }
520}
521
[136]522// Try Re-Connect
523////////////////////////////////////////////////////////////////////////////
[1555]524t_irc bncGetThread::tryReconnect() {
525
526 // Easy Return
527 // -----------
528 if (_query && _query->status() == bncNetQuery::running) {
529 _nextSleep = 0;
[1709]530 if (_rnx) {
531 _rnx->setReconnectFlag(false);
532 }
[1555]533 return success;
[408]534 }
[1555]535
536 // Start a new query
537 // -----------------
538 if (!_rawInpFile) {
539
[138]540 sleep(_nextSleep);
[1555]541 if (_nextSleep == 0) {
542 _nextSleep = 1;
[138]543 }
544 else {
[1555]545 _nextSleep = 2 * _nextSleep;
[442]546 if (_nextSleep > 256) {
547 _nextSleep = 256;
[152]548 }
[1816]549#ifdef MLS_SOFTWARE
[1817]550 if (_nextSleep > 4) {
551 _nextSleep = 4;
[1816]552 }
553#endif
[138]554 }
[1555]555
556 delete _query;
[1722]557 if (_ntripVersion == "U") {
[1721]558 _query = new bncNetQueryUdp();
559 }
[1722]560 else if (_ntripVersion == "R") {
[1555]561 _query = new bncNetQueryRtp();
562 }
[1744]563 else if (_ntripVersion == "S") {
[1753]564 _query = new bncNetQueryS();
[1744]565 }
[1621]566 else if (_ntripVersion == "N") {
567 _query = new bncNetQueryV0();
568 }
[1779]569 else if (_ntripVersion == "UN") {
570 _query = new bncNetQueryUdp0();
571 }
[1555]572 else if (_ntripVersion == "2") {
573 _query = new bncNetQueryV2();
574 }
575 else {
576 _query = new bncNetQueryV1();
577 }
[1710]578 if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
579 QByteArray gga = ggaString(_latitude, _longitude, "100.0");
[1555]580 _query->startRequest(_mountPoint, gga);
581 }
582 else {
583 _query->startRequest(_mountPoint, "");
584 }
585 if (_query->status() != bncNetQuery::running) {
586 return failure;
587 }
[138]588 }
[658]589
[1555]590 if (_rnx) {
591 _rnx->setReconnectFlag(true);
[658]592 }
[1555]593
594 return success;
[658]595}
[1044]596
[1555]597// RTCM scan output
[1044]598//////////////////////////////////////////////////////////////////////////////
[1555]599void bncGetThread::scanRTCM() {
[1044]600
[1555]601 bncSettings settings;
[1574]602 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
603
604 if ( _miscMount == _staID || _miscMount == "ALL" ) {
605
[1575]606 // RTCM message types
607 // ------------------
[1574]608 for (int ii = 0; ii <_decoder->_typeList.size(); ii++) {
609 QString type = QString("%1 ").arg(_decoder->_typeList[ii]);
610 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
611 }
[1044]612
[1574]613 // RTCMv3 antenna descriptor
614 // -------------------------
615 for (int ii=0;ii<_decoder->_antType.size();ii++) {
616 QString ant1 = QString("%1 ").arg(_decoder->_antType[ii]);
617 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
618 }
[1555]619
[1575]620 // RTCM Antenna Coordinates
621 // ------------------------
[1574]622 for (int ii=0; ii <_decoder->_antList.size(); ii++) {
623 QByteArray antT;
624 if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
625 antT = "ARP";
626 }
627 else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
628 antT = "APC";
629 }
[1575]630 QByteArray ant1, ant2, ant3;
631 ant1 = QString("%1 ").arg(_decoder->_antList[ii].xx,0,'f',4).toAscii();
632 ant2 = QString("%1 ").arg(_decoder->_antList[ii].yy,0,'f',4).toAscii();
633 ant3 = QString("%1 ").arg(_decoder->_antList[ii].zz,0,'f',4).toAscii();
634 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
635 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
636 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
637 if (_decoder->_antList[ii].height_f) {
638 QByteArray ant4 = QString("%1 ").arg(_decoder->_antList[ii].height,0,'f',4).toAscii();
639 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
640 }
[1574]641 emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
642 _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
643 antT));
[1218]644 }
645 }
[1044]646 }
[1575]647
[1770]648#ifdef MLS_SOFTWARE
649 for (int ii=0; ii <_decoder->_antList.size(); ii++) {
650 QByteArray antT;
651 if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
652 antT = "ARP";
653 }
654 else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
655 antT = "APC";
656 }
657 emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
658 _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
659 antT));
660 }
661#endif
662
663
664
665
[1555]666 _decoder->_typeList.clear();
667 _decoder->_antType.clear();
668 _decoder->_antList.clear();
[1044]669}
[1555]670
[1606]671// Handle Data from Serial Port
672////////////////////////////////////////////////////////////////////////////
673void bncGetThread::slotSerialReadyRead() {
[1607]674 if (_serialPort) {
[1633]675 int nb = _serialPort->bytesAvailable();
676 if (nb > 0) {
677 QByteArray data = _serialPort->read(nb);
[1711]678
679 if (_serialNMEA == AUTO_NMEA) {
[1725]680 int i1 = data.indexOf("$GPGGA");
681 if (i1 != -1) {
682 int i2 = data.indexOf("*", i1);
683 if (i2 != -1 && data.size() > i2 + 1) {
684 QByteArray gga = data.mid(i1,i2-i1+3);
685 _query->sendNMEA(gga);
686 }
687 }
[1711]688 }
689
[1633]690 if (_serialOutFile) {
691 _serialOutFile->write(data);
692 _serialOutFile->flush();
693 }
[1607]694 }
695 }
[1606]696}
[1768]697
698//
699//////////////////////////////////////////////////////////////////////////////
700void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
[1807]701 RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
702 RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(_decoder);
[1768]703
[1807]704 if ( decoder2 ) {
[1768]705 QMutexLocker locker(&_mutex);
706
707 string storedPRN;
708 vector<int> IODs;
709
[1807]710 if ( decoder2->storeEph(gpseph, storedPRN, IODs) ) {
[1768]711#ifdef DEBUG_RTCM2_2021
712 QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
713
714 for (unsigned ii = 0; ii < IODs.size(); ii++) {
715 msg += QString(" %1").arg(IODs[ii],4);
716 }
717
718 emit(newMessage(msg.toAscii()));
719#endif
720 }
721 }
[1807]722
723 if ( decoder3 ) {
724 QMutexLocker locker(&_mutex);
725
726 if ( decoder3->storeEph(gpseph) ) {
[1813]727#ifdef DEBUG_RTCM3
[1807]728 QString msg = _staID + QString(": RTCM3Decoder, stored eph for satellite %1").arg(gpseph.satellite);
729 emit(newMessage(msg.toAscii(),true));
[1813]730#endif
[1807]731 }
732 }
[1768]733}
734
Note: See TracBrowser for help on using the repository browser.