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

Last change on this file since 10417 was 9286, checked in by stuerze, 4 years ago

minor changes

File size: 30.8 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 _rtcmObs = false;
293 _rtcmSsrOrb = false;
294 _rtcmSsrClk = false;
295 _rtcmSsrOrbClk = false;
296 _rtcmSsrCbi = false;
297 _rtcmSsrPbi = false;
298 _rtcmSsrVtec = false;
299 _rtcmSsrUra = false;
300 _rtcmSsrHr = false;
301 _rtcmSsrIgs = false;
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 sleep(1);
469 ::exit(0);
470 }
471 }
472 qint64 nBytes = data.size();
473
474 // Timeout, reconnect
475 // ------------------
476 if (nBytes == 0) {
477 if (_latencyChecker) {
478 _latencyChecker->checkReconnect();
479 }
480 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
481 msleep(10000); //sleep 10 sec, G. Weber
482 continue;
483 } else {
484 emit newBytes(_staID, nBytes);
485 emit newRawData(_staID, data);
486 }
487
488 // Output Data
489 // -----------
490 if (_rawOutput) {
491 BNC_CORE->writeRawData(data, _staID, _format);
492 }
493
494 if (_serialPort) {
495 slotSerialReadyRead();
496 _serialPort->write(data);
497 }
498
499 // Decode Data
500 // -----------
501 vector<string> errmsg;
502 if (!decoder()) {
503 _isToBeDeleted = true;
504 continue;
505 }
506
507 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
508
509 if (irc != success) {
510 continue;
511 }
512 // Perform various scans and checks
513 // --------------------------------
514 if (_latencyChecker) {
515 _latencyChecker->checkOutage(irc);
516 QListIterator<int> it(decoder()->_typeList);
517 _ssrEpoch = static_cast<int>(decoder()->corrGPSEpochTime());
518 if (_ssrEpoch != -1) {
519 if (_rtcmSsrOrb) {
520 _latencyChecker->checkCorrLatency(_ssrEpoch, 1057);
521 _rtcmSsrOrb = false;
522 }
523 if (_rtcmSsrClk) {
524 _latencyChecker->checkCorrLatency(_ssrEpoch, 1058);
525 _rtcmSsrClk = false;
526 }
527 if (_rtcmSsrOrbClk) {
528 _latencyChecker->checkCorrLatency(_ssrEpoch, 1060);
529 _rtcmSsrOrbClk = false;
530 }
531 if (_rtcmSsrCbi) {
532 _latencyChecker->checkCorrLatency(_ssrEpoch, 1059);
533 _rtcmSsrCbi = false;
534 }
535 if (_rtcmSsrPbi) {
536 _latencyChecker->checkCorrLatency(_ssrEpoch, 1265);
537 _rtcmSsrPbi = false;
538 }
539 if (_rtcmSsrVtec) {
540 _latencyChecker->checkCorrLatency(_ssrEpoch, 1264);
541 _rtcmSsrVtec = false;
542 }
543 if (_rtcmSsrUra) {
544 _latencyChecker->checkCorrLatency(_ssrEpoch, 1061);
545 _rtcmSsrUra = false;
546 }
547 if (_rtcmSsrHr) {
548 _latencyChecker->checkCorrLatency(_ssrEpoch, 1062);
549 _rtcmSsrHr = false;
550 }
551 if (_rtcmSsrIgs) {
552 _latencyChecker->checkCorrLatency(_ssrEpoch, 4076);
553 _rtcmSsrIgs = false;
554 }
555 }
556 while (it.hasNext()) {
557 int rtcmType = it.next();
558 if ((rtcmType >= 1001 && rtcmType <= 1004) || // legacy RTCM OBS
559 (rtcmType >= 1009 && rtcmType <= 1012) || // legacy RTCM OBS
560 (rtcmType >= 1070 && rtcmType <= 1137)) { // MSM RTCM OBS
561 _rtcmObs = true;
562 } else if ((rtcmType >= 1057 && rtcmType <= 1068) ||
563 (rtcmType >= 1240 && rtcmType <= 1270) ||
564 (rtcmType == 4076)) {
565 switch (rtcmType) {
566 case 1057: case 1063: case 1240: case 1246: case 1252: case 1258:
567 _rtcmSsrOrb = true;
568 break;
569 case 1058: case 1064: case 1241: case 1247: case 1253: case 1259:
570 _rtcmSsrClk = true;
571 break;
572 case 1060: case 1066: case 1243: case 1249: case 1255: case 1261:
573 _rtcmSsrOrbClk = true;
574 break;
575 case 1059: case 1065: case 1242: case 1248: case 1254: case 1260:
576 _rtcmSsrCbi = true;
577 break;
578 case 1265: case 1266: case 1267: case 1268: case 1269: case 1270:
579 _rtcmSsrPbi = true;
580 break;
581 case 1264:
582 _rtcmSsrVtec = true;
583 break;
584 case 1061: case 1067: case 1244: case 1250: case 1256: case 1262:
585 _rtcmSsrUra = true;
586 break;
587 case 1062: case 1068: case 1245: case 1251: case 1257: case 1263:
588 _rtcmSsrHr = true;
589 break;
590 case 4076:
591 _rtcmSsrIgs = true;
592 break;
593 }
594 }
595 }
596 if (_rtcmObs) {
597 _latencyChecker->checkObsLatency(decoder()->_obsList);
598 }
599 emit newLatency(_staID, _latencyChecker->currentLatency());
600 }
601 miscScanRTCM();
602
603 // Loop over all observations (observations output)
604 // ------------------------------------------------
605 QListIterator<t_satObs> it(decoder()->_obsList);
606
607 QList<t_satObs> obsListHlp;
608
609 while (it.hasNext()) {
610 const t_satObs& obs = it.next();
611
612 // Check observation epoch
613 // -----------------------
614 if (!_rawFile) {
615 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
616 if (wrongObservationEpoch) {
617 QString prn(obs._prn.toString().c_str());
618 emit(newMessage(
619 _staID + " (" + prn.toAscii() + ")"
620 + ": Wrong observation epoch(s)", false));
621 continue;
622 }
623 }
624
625 // Check observations coming twice (e.g. KOUR0 Problem)
626 // ----------------------------------------------------
627 if (!_rawFile) {
628 QString prn(obs._prn.toString().c_str());
629 bncTime obsTime = obs._time;
630 QMap<QString, bncTime>::const_iterator it = _prnLastEpo.find(prn);
631 if (it != _prnLastEpo.end()) {
632 bncTime oldTime = it.value();
633 if (obsTime < oldTime) {
634 emit(newMessage(_staID + ": old observation " + prn.toLatin1(), false));
635 continue;
636 } else if (obsTime == oldTime) {
637 emit(newMessage(_staID + ": observation coming more than once "
638 + prn.toLatin1(), false));
639 continue;
640 }
641 }
642 _prnLastEpo[prn] = obsTime;
643 }
644
645 decoder()->dumpRinexEpoch(obs, _format);
646
647 // Save observations
648 // -----------------
649 obsListHlp.append(obs);
650 }
651
652 // Emit signal
653 // -----------
654 if (!_isToBeDeleted && obsListHlp.size() > 0) {
655 emit newObs(_staID, obsListHlp);
656 }
657
658 } catch (Exception& exc) {
659 emit(newMessage(_staID + " " + exc.what(), true));
660 _isToBeDeleted = true;
661 } catch (...) {
662 emit(newMessage(_staID + " bncGetThread exception", true));
663 _isToBeDeleted = true;
664 }
665 }
666}
667
668// Try Re-Connect
669////////////////////////////////////////////////////////////////////////////
670t_irc bncGetThread::tryReconnect() {
671
672 // Easy Return
673 // -----------
674 if (_query && _query->status() == bncNetQuery::running) {
675 _nextSleep = 0;
676 if (_rawFile) {
677 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
678 while (itDec.hasNext()) {
679 itDec.next();
680 GPSDecoder* decoder = itDec.value();
681 decoder->setRinexReconnectFlag(false);
682 }
683 } else {
684 _decoder->setRinexReconnectFlag(false);
685 }
686 return success;
687 }
688
689 // Start a new query
690 // -----------------
691 if (!_rawFile) {
692
693 sleep(_nextSleep);
694 if (_nextSleep == 0) {
695 _nextSleep = 1;
696 } else {
697 _nextSleep = 2 * _nextSleep;
698 if (_nextSleep > 256) {
699 _nextSleep = 256;
700 }
701#ifdef MLS_SOFTWARE
702 if (_nextSleep > 4) {
703 _nextSleep = 4;
704 }
705#endif
706 }
707 delete _query;
708 if (_ntripVersion == "U") {
709 _query = new bncNetQueryUdp();
710 } else if (_ntripVersion == "R") {
711 _query = new bncNetQueryRtp();
712 } else if (_ntripVersion == "S") {
713 _query = new bncNetQueryS();
714 } else if (_ntripVersion == "N") {
715 _query = new bncNetQueryV0();
716 } else if (_ntripVersion == "UN") {
717 _query = new bncNetQueryUdp0();
718 } else if (_ntripVersion == "2") {
719 _query = new bncNetQueryV2(false);
720 } else if (_ntripVersion == "2s") {
721 _query = new bncNetQueryV2(true);
722 } else {
723 _query = new bncNetQueryV1();
724 }
725 if (_nmea == "yes") {
726 if (_serialNMEA == MANUAL_NMEA) {
727 _query->startRequest(_mountPoint, _manualNMEAString);
728 _lastManualNMEA = QDateTime::currentDateTime();
729 } else if (_serialNMEA == AUTO_NMEA) {
730 if (_serialPort) {
731 int nb = _serialPort->bytesAvailable();
732 if (nb > 0) {
733 QByteArray data = _serialPort->read(nb);
734 int i1 = data.indexOf("$GPGGA");
735 if (i1 == -1) {
736 i1 = data.indexOf("$GNGGA");
737 }
738 if (i1 != -1) {
739 int i2 = data.indexOf("*", i1);
740 if (i2 != -1 && data.size() > i2 + 1) {
741 QByteArray gga = data.mid(i1, i2 - i1 + 3);
742 _query->startRequest(_mountPoint, gga);
743 }
744 }
745 }
746 }
747 }
748 } else {
749 _query->startRequest(_mountPoint, "");
750 }
751
752 if (_query->status() != bncNetQuery::running) {
753 return failure;
754 }
755 }
756
757 if (_rawFile) {
758 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
759 while (itDec.hasNext()) {
760 itDec.next();
761 GPSDecoder* decoder = itDec.value();
762 decoder->setRinexReconnectFlag(false);
763 }
764 } else {
765 _decoder->setRinexReconnectFlag(false);
766 }
767
768 return success;
769}
770
771// RTCM scan output
772//////////////////////////////////////////////////////////////////////////////
773void bncGetThread::miscScanRTCM() {
774
775 if (!decoder()) {
776 return;
777 }
778
779 bncSettings settings;
780 if (Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked) {
781
782 if (_miscMount == _staID || _miscMount == "ALL") {
783 // RTCM message types
784 // ------------------
785 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
786 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
787 emit(newMessage(_staID + ": Received message type " + type.toAscii(),
788 true));
789 }
790
791 // Check Observation Types
792 // -----------------------
793 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
794 t_satObs& obs = decoder()->_obsList[ii];
795 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
796 bool allFound = true;
797 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
798 if (obs._obs[iFrq]->_codeValid) {
799 QString rnxStr('C');
800 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
801 if (_format.indexOf("RTCM_2") != -1
802 || _format.indexOf("RTCM2") != -1
803 || _format.indexOf("RTCM 2") != -1) {
804 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
805 }
806 if (rnxTypes.indexOf(rnxStr) == -1) {
807 rnxTypes.push_back(rnxStr);
808 allFound = false;
809 }
810 }
811 if (obs._obs[iFrq]->_phaseValid) {
812 QString rnxStr('L');
813 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
814 if (_format.indexOf("RTCM_2") != -1
815 || _format.indexOf("RTCM2") != -1
816 || _format.indexOf("RTCM 2") != -1) {
817 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
818 }
819 if (rnxTypes.indexOf(rnxStr) == -1) {
820 rnxTypes.push_back(rnxStr);
821 allFound = false;
822 }
823 }
824 if (obs._obs[iFrq]->_dopplerValid) {
825 QString rnxStr('D');
826 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
827 if (_format.indexOf("RTCM_2") != -1
828 || _format.indexOf("RTCM2") != -1
829 || _format.indexOf("RTCM 2") != -1) {
830 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
831 }
832 if (rnxTypes.indexOf(rnxStr) == -1) {
833 rnxTypes.push_back(rnxStr);
834 allFound = false;
835 }
836 }
837 if (obs._obs[iFrq]->_snrValid) {
838 QString rnxStr('S');
839 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
840 if (_format.indexOf("RTCM_2") != -1
841 || _format.indexOf("RTCM2") != -1
842 || _format.indexOf("RTCM 2") != -1) {
843 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
844 }
845 if (rnxTypes.indexOf(rnxStr) == -1) {
846 rnxTypes.push_back(rnxStr);
847 allFound = false;
848 }
849 }
850 }
851 if (!allFound) {
852 QString msg;
853 QTextStream str(&msg);
854 QString s;
855 str << obs._prn.system() << " "
856 << s.sprintf("%2d", rnxTypes.size()) << " ";
857 for (int iType = 0; iType < rnxTypes.size(); iType++) {
858 str << " " << rnxTypes[iType];
859 }
860 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(),
861 true));
862 }
863 }
864
865 // RTCMv3 antenna descriptor
866 // -------------------------
867 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
868 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
869 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
870 }
871
872 // RTCM Antenna Coordinates
873 // ------------------------
874 for (int ii = 0; ii < decoder()->_antList.size(); ii++) {
875 QByteArray antT;
876 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
877 antT = "ARP";
878 } else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
879 antT = "APC";
880 }
881 QByteArray ant1, ant2, ant3;
882 ant1 =
883 QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).toAscii();
884 ant2 =
885 QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).toAscii();
886 ant3 =
887 QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).toAscii();
888 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
889 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
890 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
891 double hh = 0.0;
892 if (decoder()->_antList[ii].height_f) {
893 hh = decoder()->_antList[ii].height;
894 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toAscii();
895 emit(newMessage(
896 _staID + ": Antenna height above marker " + ant4 + "m", true));
897 }
898 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
899 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, hh, antT));
900 }
901
902 // RTCMv3 receiver descriptor
903 // --------------------------
904 for (int ii = 0; ii < decoder()->_recType.size(); ii++) {
905 QString rec1 = QString("%1 ").arg(decoder()->_recType[ii]);
906 emit(newMessage(_staID + ": Receiver descriptor " + rec1.toLatin1(), true));
907 }
908
909 // RTCM GLONASS slots
910 // ------------------
911 if (decoder()->_gloFrq.size()) {
912 bool allFound = true;
913 QString slot = decoder()->_gloFrq;
914 slot.replace(" ", " ").replace(" ", ":");
915 if (_gloSlots.indexOf(slot) == -1) {
916 _gloSlots.append(slot);
917 allFound = false;
918 }
919 if (!allFound) {
920 _gloSlots.sort();
921 emit(newMessage(
922 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toAscii(),
923 true));
924 }
925 }
926 }
927 }
928
929#ifdef MLS_SOFTWARE
930 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
931 QByteArray antT;
932 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
933 antT = "ARP";
934 }
935 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
936 antT = "APC";
937 }
938 double hh = 0.0;
939 if (decoder()->_antList[ii].height_f) {
940 hh = decoder()->_antList[ii].height;
941 }
942 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
943 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
944 hh, antT));
945 }
946
947 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
948 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
949 }
950#endif
951
952 decoder()->_gloFrq.clear();
953 decoder()->_typeList.clear();
954 decoder()->_antType.clear();
955 decoder()->_recType.clear();
956 decoder()->_antList.clear();
957}
958
959// Handle Data from Serial Port
960////////////////////////////////////////////////////////////////////////////
961void bncGetThread::slotSerialReadyRead() {
962
963 if (_serialPort) {
964
965 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
966 if (_manualNMEASampl) {
967 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
968 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
969 _query->sendNMEA(_manualNMEAString);
970 _lastManualNMEA = QDateTime::currentDateTime();
971 }
972 }
973 }
974
975 int nb = _serialPort->bytesAvailable();
976 if (nb > 0) {
977 QByteArray data = _serialPort->read(nb);
978
979 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
980 int i1 = data.indexOf("$GPGGA");
981 if (i1 == -1) {
982 i1 = data.indexOf("$GNGGA");
983 }
984 if (i1 != -1) {
985 int i2 = data.indexOf("*", i1);
986 if (i2 != -1 && data.size() > i2 + 1) {
987 QByteArray gga = data.mid(i1, i2 - i1 + 3);
988 _query->sendNMEA(gga);
989 }
990 }
991 }
992
993 if (_serialOutFile) {
994 _serialOutFile->write(data);
995 _serialOutFile->flush();
996 }
997 }
998 }
999}
1000
1001void bncGetThread::slotNewNMEAConnection() {
1002 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
1003 emit(newMessage(
1004 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toAscii(),
1005 true));
1006}
1007
1008//
1009////////////////////////////////////////////////////////////////////////////
1010void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
1011 if (_nmeaPortsMap.contains(staID)) {
1012 int nmeaPort = _nmeaPortsMap.value(staID);
1013 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
1014 while (is.hasNext()) {
1015 QTcpSocket* sock = is.next();
1016 if (sock->localPort() == nmeaPort) {
1017 if (sock->state() == QAbstractSocket::ConnectedState) {
1018 sock->write(str);
1019 } else if (sock->state() != QAbstractSocket::ConnectingState) {
1020 delete sock;
1021 is.remove();
1022 }
1023 }
1024 }
1025 }
1026}
Note: See TracBrowser for help on using the repository browser.