source: ntrip/trunk/BNC/src/bncgetthread.cpp@ 10580

Last change on this file since 10580 was 10571, checked in by stuerze, 3 weeks ago

minor changes regarding bengetthread

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