source: ntrip/branches/BNC_2.12/src/bncgetthread.cpp@ 9010

Last change on this file since 9010 was 9010, checked in by stuerze, 22 months ago

some updates regarding IRNSS mesage numbers

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