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

Last change on this file since 8622 was 8418, checked in by stuerze, 6 years ago

some changes to allow 10 Hz observation data real-time processing

File size: 30.4 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 _oldSsrEpoch = 0;
302 _ssrEpoch = 0;
303 } else {
304 _latencyChecker = 0;
305 }
306}
307
308// Instantiate the decoder
309//////////////////////////////////////////////////////////////////////////////
310t_irc bncGetThread::initDecoder() {
311
312 _decoder = 0;
313
314 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1
315 || _format.indexOf("RTCM 2") != -1) {
316 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
317 _decoder = new RTCM2Decoder(_staID.data());
318 } else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1
319 || _format.indexOf("RTCM 3") != -1) {
320 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
321 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
322 _decoder = newDecoder;
323 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
324 this, SIGNAL(newMessage(QByteArray,bool)));
325 } else if (_format.indexOf("ZERO") != -1) {
326 emit(newMessage(_staID + ": Get data in original format", true));
327 _decoder = new bncZeroDecoder(_staID);
328 } else if (_format.indexOf("RTNET") != -1) {
329 emit(newMessage(_staID + ": Get data in RTNet format", true));
330 _decoder = new bncRtnetDecoder();
331 } else {
332 emit(newMessage(_staID + ": Unknown data format " + _format, true));
333 _isToBeDeleted = true;
334 return failure;
335 }
336
337 msleep(100); //sleep 0.1 sec
338
339 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
340 _ntripVersion);
341
342 if (_rawFile) {
343 _decodersRaw[_staID] = _decoder;
344 }
345
346 return success;
347}
348
349// Current decoder in use
350////////////////////////////////////////////////////////////////////////////
351GPSDecoder* bncGetThread::decoder() {
352 if (!_rawFile) {
353 return _decoder;
354 } else {
355 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
356 return _decodersRaw[_staID];
357 }
358 }
359 return 0;
360}
361
362// Destructor
363////////////////////////////////////////////////////////////////////////////
364bncGetThread::~bncGetThread() {
365 if (isRunning()) {
366 wait();
367 }
368 if (_query) {
369 _query->stop();
370 _query->deleteLater();
371 }
372 if (_rawFile) {
373 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
374 while (it.hasNext()) {
375 it.next();
376 delete it.value();
377 }
378 } else {
379 delete _decoder;
380 }
381 delete _rawFile;
382 delete _serialOutFile;
383 delete _serialPort;
384 delete _latencyChecker;
385 emit getThreadFinished(_staID);
386}
387
388//
389////////////////////////////////////////////////////////////////////////////
390void bncGetThread::terminate() {
391 _isToBeDeleted = true;
392
393 if (_nmeaPortsMap.contains(_staID)) {
394 _nmeaPortsMap.remove(_staID);
395 }
396 if (_nmeaServer) {
397 delete _nmeaServer;
398 }
399 if (_nmeaSockets) {
400 delete _nmeaSockets;
401 }
402
403#ifdef BNC_DEBUG
404 if (BNC_CORE->mode() != t_bncCore::interactive) {
405 while (!isFinished()) {
406 wait();
407 }
408 delete this;
409 } else {
410 if (!isRunning()) {
411 delete this;
412 }
413 }
414#else
415 if (!isRunning()) {delete this;}
416#endif
417
418}
419
420// Run
421////////////////////////////////////////////////////////////////////////////
422void bncGetThread::run() {
423
424 while (true) {
425 try {
426 if (_isToBeDeleted) {
427 QThread::exit(0);
428 this->deleteLater();
429 return;
430 }
431
432 if (tryReconnect() != success) {
433 if (_latencyChecker) {
434 _latencyChecker->checkReconnect();
435 }
436 continue;
437 }
438
439 // Delete old observations
440 // -----------------------
441 if (_rawFile) {
442 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
443 while (itDec.hasNext()) {
444 itDec.next();
445 GPSDecoder* decoder = itDec.value();
446 decoder->_obsList.clear();
447 }
448 } else {
449 _decoder->_obsList.clear();
450 }
451
452 // Read Data
453 // ---------
454 QByteArray data;
455 if (_query) {
456 _query->waitForReadyRead(data);
457 } else if (_rawFile) {
458 data = _rawFile->readChunk();
459 _format = _rawFile->format();
460 _staID = _rawFile->staID();
461
462 QCoreApplication::processEvents();
463
464 if (data.isEmpty() || BNC_CORE->sigintReceived) {
465 cout << "no more data or Ctrl-C received" << endl;
466 BNC_CORE->stopCombination();
467 BNC_CORE->stopPPP();
468 ::exit(0);
469 }
470 }
471 qint64 nBytes = data.size();
472
473 // Timeout, reconnect
474 // ------------------
475 if (nBytes == 0) {
476 if (_latencyChecker) {
477 _latencyChecker->checkReconnect();
478 }
479 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
480 msleep(10000); //sleep 10 sec, G. Weber
481 continue;
482 } else {
483 emit newBytes(_staID, nBytes);
484 emit newRawData(_staID, data);
485 }
486
487 // Output Data
488 // -----------
489 if (_rawOutput) {
490 BNC_CORE->writeRawData(data, _staID, _format);
491 }
492
493 if (_serialPort) {
494 slotSerialReadyRead();
495 _serialPort->write(data);
496 }
497
498 // Decode Data
499 // -----------
500 vector<string> errmsg;
501 if (!decoder()) {
502 _isToBeDeleted = true;
503 continue;
504 }
505
506 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
507
508 if (irc != success) {
509 continue;
510 }
511 // Perform various scans and checks
512 // --------------------------------
513 if (_latencyChecker) {
514 _latencyChecker->checkOutage(irc);
515 QListIterator<int> it(decoder()->_typeList);
516 _ssrEpoch = static_cast<int>(decoder()->corrGPSEpochTime());
517 if (_oldSsrEpoch != -1 && _ssrEpoch != _oldSsrEpoch) {
518 if (ssrOrb) {
519 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1057);
520 ssrOrb = false;
521 }
522 if (ssrClk) {
523 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1058);
524 ssrClk = false;
525 }
526 if (ssrOrbClk) {
527 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1060);
528 ssrOrbClk = false;
529 }
530 if (ssrCbi) {
531 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1059);
532 ssrCbi = false;
533 }
534 if (ssrPbi) {
535 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1265);
536 ssrPbi = false;
537 }
538 if (ssrVtec) {
539 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1264);
540 ssrVtec = false;
541 }
542 if (ssrUra) {
543 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1061);
544 ssrUra = false;
545 }
546 if (ssrHr) {
547 _latencyChecker->checkCorrLatency(_oldSsrEpoch, 1062);
548 ssrHr = false;
549 }
550 }
551 while (it.hasNext()) {
552 int rtcmType = it.next();
553 if ((rtcmType >= 1001 && rtcmType <= 1004) || // legacy RTCM OBS
554 (rtcmType >= 1009 && rtcmType <= 1012) || // legacy RTCM OBS
555 (rtcmType >= 1071 && rtcmType <= 1127)) { // MSM RTCM OBS
556 obs = true;
557 } else if ((rtcmType >= 1057 && rtcmType <= 1068) ||
558 (rtcmType >= 1240 && rtcmType <= 1270)) {
559 switch (rtcmType) {
560 case 1057: case 1063: case 1240: case 1246: case 1252: case 1258:
561 ssrOrb = true;
562 break;
563 case 1058: case 1064: case 1241: case 1247: case 1253: case 1259:
564 ssrClk = true;
565 break;
566 case 1060: case 1066: case 1243: case 1249: case 1255: case 1261:
567 ssrOrbClk = true;
568 break;
569 case 1059: case 1065: case 1242: case 1248: case 1254: case 1260:
570 ssrCbi = true;
571 break;
572 case 1265: case 1266: case 1267: case 1268: case 1269: case 1270:
573 ssrPbi = true;
574 break;
575 case 1264:
576 ssrVtec = true;
577 break;
578 case 1061: case 1067: case 1244: case 1250: case 1256: case 1262:
579 ssrUra = true;
580 break;
581 case 1062: case 1068: case 1245: case 1251: case 1257: case 1263:
582 ssrHr = true;
583 break;
584 }
585 }
586 }
587 if (obs) {
588 _latencyChecker->checkObsLatency(decoder()->_obsList);
589 }
590 if (_ssrEpoch != -1) {
591 _oldSsrEpoch = _ssrEpoch;
592 }
593 emit newLatency(_staID, _latencyChecker->currentLatency());
594 }
595 miscScanRTCM();
596
597 // Loop over all observations (observations output)
598 // ------------------------------------------------
599 QListIterator<t_satObs> it(decoder()->_obsList);
600
601 QList<t_satObs> obsListHlp;
602
603 while (it.hasNext()) {
604 const t_satObs& obs = it.next();
605
606 // Check observation epoch
607 // -----------------------
608 if (!_rawFile) {
609 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
610 if (wrongObservationEpoch) {
611 QString prn(obs._prn.toString().c_str());
612 emit(newMessage(
613 _staID + " (" + prn.toAscii() + ")"
614 + ": Wrong observation epoch(s)", false));
615 continue;
616 }
617 }
618
619 // Check observations coming twice (e.g. KOUR0 Problem)
620 // ----------------------------------------------------
621 if (!_rawFile) {
622 QString prn(obs._prn.toString().c_str());
623 bncTime obsTime = obs._time;
624 QMap<QString, bncTime>::const_iterator it = _prnLastEpo.find(prn);
625 if (it != _prnLastEpo.end()) {
626 bncTime oldTime = it.value();
627 if (obsTime < oldTime) {
628 emit(newMessage(_staID + ": old observation " + prn.toLatin1(), false));
629 continue;
630 } else if (obsTime == oldTime) {
631 emit(newMessage(_staID + ": observation coming more than once "
632 + prn.toLatin1(), false));
633 continue;
634 }
635 }
636 _prnLastEpo[prn] = obsTime;
637 }
638
639
640 decoder()->dumpRinexEpoch(obs, _format);
641
642 // Save observations
643 // -----------------
644 obsListHlp.append(obs);
645 }
646
647 // Emit signal
648 // -----------
649 if (!_isToBeDeleted && obsListHlp.size() > 0) {
650 emit newObs(_staID, obsListHlp);
651 }
652
653 } catch (Exception& exc) {
654 emit(newMessage(_staID + " " + exc.what(), true));
655 _isToBeDeleted = true;
656 } catch (...) {
657 emit(newMessage(_staID + " bncGetThread exception", true));
658 _isToBeDeleted = true;
659 }
660 }
661}
662
663// Try Re-Connect
664////////////////////////////////////////////////////////////////////////////
665t_irc bncGetThread::tryReconnect() {
666
667 // Easy Return
668 // -----------
669 if (_query && _query->status() == bncNetQuery::running) {
670 _nextSleep = 0;
671 if (_rawFile) {
672 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
673 while (itDec.hasNext()) {
674 itDec.next();
675 GPSDecoder* decoder = itDec.value();
676 decoder->setRinexReconnectFlag(false);
677 }
678 } else {
679 _decoder->setRinexReconnectFlag(false);
680 }
681 return success;
682 }
683
684 // Start a new query
685 // -----------------
686 if (!_rawFile) {
687
688 sleep(_nextSleep);
689 if (_nextSleep == 0) {
690 _nextSleep = 1;
691 } else {
692 _nextSleep = 2 * _nextSleep;
693 if (_nextSleep > 256) {
694 _nextSleep = 256;
695 }
696#ifdef MLS_SOFTWARE
697 if (_nextSleep > 4) {
698 _nextSleep = 4;
699 }
700#endif
701 }
702 delete _query;
703 if (_ntripVersion == "U") {
704 _query = new bncNetQueryUdp();
705 } else if (_ntripVersion == "R") {
706 _query = new bncNetQueryRtp();
707 } else if (_ntripVersion == "S") {
708 _query = new bncNetQueryS();
709 } else if (_ntripVersion == "N") {
710 _query = new bncNetQueryV0();
711 } else if (_ntripVersion == "UN") {
712 _query = new bncNetQueryUdp0();
713 } else if (_ntripVersion == "2") {
714 _query = new bncNetQueryV2(false);
715 } else if (_ntripVersion == "2s") {
716 _query = new bncNetQueryV2(true);
717 } else {
718 _query = new bncNetQueryV1();
719 }
720 if (_nmea == "yes") {
721 if (_serialNMEA == MANUAL_NMEA) {
722 _query->startRequest(_mountPoint, _manualNMEAString);
723 _lastManualNMEA = QDateTime::currentDateTime();
724 } else if (_serialNMEA == AUTO_NMEA) {
725 if (_serialPort) {
726 int nb = _serialPort->bytesAvailable();
727 if (nb > 0) {
728 QByteArray data = _serialPort->read(nb);
729 int i1 = data.indexOf("$GPGGA");
730 if (i1 == -1) {
731 i1 = data.indexOf("$GNGGA");
732 }
733 if (i1 != -1) {
734 int i2 = data.indexOf("*", i1);
735 if (i2 != -1 && data.size() > i2 + 1) {
736 QByteArray gga = data.mid(i1, i2 - i1 + 3);
737 _query->startRequest(_mountPoint, gga);
738 }
739 }
740 }
741 }
742 }
743 } else {
744 _query->startRequest(_mountPoint, "");
745 }
746
747 if (_query->status() != bncNetQuery::running) {
748 return failure;
749 }
750 }
751
752 if (_rawFile) {
753 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
754 while (itDec.hasNext()) {
755 itDec.next();
756 GPSDecoder* decoder = itDec.value();
757 decoder->setRinexReconnectFlag(false);
758 }
759 } else {
760 _decoder->setRinexReconnectFlag(false);
761 }
762
763 return success;
764}
765
766// RTCM scan output
767//////////////////////////////////////////////////////////////////////////////
768void bncGetThread::miscScanRTCM() {
769
770 if (!decoder()) {
771 return;
772 }
773
774 bncSettings settings;
775 if (Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked) {
776
777 if (_miscMount == _staID || _miscMount == "ALL") {
778 // RTCM message types
779 // ------------------
780 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
781 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
782 emit(newMessage(_staID + ": Received message type " + type.toAscii(),
783 true));
784 }
785
786 // Check Observation Types
787 // -----------------------
788 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
789 t_satObs& obs = decoder()->_obsList[ii];
790 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
791 bool allFound = true;
792 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
793 if (obs._obs[iFrq]->_codeValid) {
794 QString rnxStr('C');
795 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
796 if (_format.indexOf("RTCM_2") != -1
797 || _format.indexOf("RTCM2") != -1
798 || _format.indexOf("RTCM 2") != -1) {
799 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
800 }
801 if (rnxTypes.indexOf(rnxStr) == -1) {
802 rnxTypes.push_back(rnxStr);
803 allFound = false;
804 }
805 }
806 if (obs._obs[iFrq]->_phaseValid) {
807 QString rnxStr('L');
808 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
809 if (_format.indexOf("RTCM_2") != -1
810 || _format.indexOf("RTCM2") != -1
811 || _format.indexOf("RTCM 2") != -1) {
812 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
813 }
814 if (rnxTypes.indexOf(rnxStr) == -1) {
815 rnxTypes.push_back(rnxStr);
816 allFound = false;
817 }
818 }
819 if (obs._obs[iFrq]->_dopplerValid) {
820 QString rnxStr('D');
821 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
822 if (_format.indexOf("RTCM_2") != -1
823 || _format.indexOf("RTCM2") != -1
824 || _format.indexOf("RTCM 2") != -1) {
825 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
826 }
827 if (rnxTypes.indexOf(rnxStr) == -1) {
828 rnxTypes.push_back(rnxStr);
829 allFound = false;
830 }
831 }
832 if (obs._obs[iFrq]->_snrValid) {
833 QString rnxStr('S');
834 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
835 if (_format.indexOf("RTCM_2") != -1
836 || _format.indexOf("RTCM2") != -1
837 || _format.indexOf("RTCM 2") != -1) {
838 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
839 }
840 if (rnxTypes.indexOf(rnxStr) == -1) {
841 rnxTypes.push_back(rnxStr);
842 allFound = false;
843 }
844 }
845 }
846 if (!allFound) {
847 QString msg;
848 QTextStream str(&msg);
849 QString s;
850 str << obs._prn.system() << " "
851 << s.sprintf("%2d", rnxTypes.size()) << " ";
852 for (int iType = 0; iType < rnxTypes.size(); iType++) {
853 str << " " << rnxTypes[iType];
854 }
855 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(),
856 true));
857 }
858 }
859
860 // RTCMv3 antenna descriptor
861 // -------------------------
862 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
863 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
864 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
865 }
866
867 // RTCM Antenna Coordinates
868 // ------------------------
869 for (int ii = 0; ii < decoder()->_antList.size(); ii++) {
870 QByteArray antT;
871 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
872 antT = "ARP";
873 } else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
874 antT = "APC";
875 }
876 QByteArray ant1, ant2, ant3;
877 ant1 =
878 QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).toAscii();
879 ant2 =
880 QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).toAscii();
881 ant3 =
882 QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).toAscii();
883 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
884 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
885 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
886 double hh = 0.0;
887 if (decoder()->_antList[ii].height_f) {
888 hh = decoder()->_antList[ii].height;
889 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toAscii();
890 emit(newMessage(
891 _staID + ": Antenna height above marker " + ant4 + "m", true));
892 }
893 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
894 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, hh, antT));
895 }
896
897 // RTCMv3 receiver descriptor
898 // --------------------------
899 for (int ii = 0; ii < decoder()->_recType.size(); ii++) {
900 QString rec1 = QString("%1 ").arg(decoder()->_recType[ii]);
901 emit(newMessage(_staID + ": Receiver descriptor " + rec1.toLatin1(), true));
902 }
903
904 // RTCM GLONASS slots
905 // ------------------
906 if (decoder()->_gloFrq.size()) {
907 bool allFound = true;
908 QString slot = decoder()->_gloFrq;
909 slot.replace(" ", " ").replace(" ", ":");
910 if (_gloSlots.indexOf(slot) == -1) {
911 _gloSlots.append(slot);
912 allFound = false;
913 }
914 if (!allFound) {
915 _gloSlots.sort();
916 emit(newMessage(
917 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toAscii(),
918 true));
919 }
920 }
921 }
922 }
923
924#ifdef MLS_SOFTWARE
925 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
926 QByteArray antT;
927 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
928 antT = "ARP";
929 }
930 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
931 antT = "APC";
932 }
933 double hh = 0.0;
934 if (decoder()->_antList[ii].height_f) {
935 hh = decoder()->_antList[ii].height;
936 }
937 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
938 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
939 hh, antT));
940 }
941
942 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
943 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
944 }
945#endif
946
947 decoder()->_gloFrq.clear();
948 decoder()->_typeList.clear();
949 decoder()->_antType.clear();
950 decoder()->_recType.clear();
951 decoder()->_antList.clear();
952}
953
954// Handle Data from Serial Port
955////////////////////////////////////////////////////////////////////////////
956void bncGetThread::slotSerialReadyRead() {
957
958 if (_serialPort) {
959
960 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
961 if (_manualNMEASampl) {
962 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
963 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
964 _query->sendNMEA(_manualNMEAString);
965 _lastManualNMEA = QDateTime::currentDateTime();
966 }
967 }
968 }
969
970 int nb = _serialPort->bytesAvailable();
971 if (nb > 0) {
972 QByteArray data = _serialPort->read(nb);
973
974 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
975 int i1 = data.indexOf("$GPGGA");
976 if (i1 == -1) {
977 i1 = data.indexOf("$GNGGA");
978 }
979 if (i1 != -1) {
980 int i2 = data.indexOf("*", i1);
981 if (i2 != -1 && data.size() > i2 + 1) {
982 QByteArray gga = data.mid(i1, i2 - i1 + 3);
983 _query->sendNMEA(gga);
984 }
985 }
986 }
987
988 if (_serialOutFile) {
989 _serialOutFile->write(data);
990 _serialOutFile->flush();
991 }
992 }
993 }
994}
995
996void bncGetThread::slotNewNMEAConnection() {
997 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
998 emit(newMessage(
999 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toAscii(),
1000 true));
1001}
1002
1003//
1004////////////////////////////////////////////////////////////////////////////
1005void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
1006 if (_nmeaPortsMap.contains(staID)) {
1007 int nmeaPort = _nmeaPortsMap.value(staID);
1008 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
1009 while (is.hasNext()) {
1010 QTcpSocket* sock = is.next();
1011 if (sock->localPort() == nmeaPort) {
1012 if (sock->state() == QAbstractSocket::ConnectedState) {
1013 sock->write(str);
1014 } else if (sock->state() != QAbstractSocket::ConnectingState) {
1015 delete sock;
1016 is.remove();
1017 }
1018 }
1019 }
1020 }
1021}
Note: See TracBrowser for help on using the repository browser.