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

Last change on this file since 10689 was 10688, checked in by stuerze, 7 days ago

RTCM message 1230 (on-change) and the size of each RTCM message is added in scanRTCM

File size: 36.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 <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 msleep(100); //sleep 0.1 sec
258 if (!_serialPort->isOpen()) {
259 emit(newMessage((_staID + ": Cannot open serial port " + _serialPort->errorString()).toLatin1(), true));
260 delete _serialPort;
261 _serialPort = 0;
262 }
263
264 connect(_serialPort, SIGNAL(readyRead()), this, SLOT(slotSerialReadyRead()));
265
266 // Automatic NMEA
267 // --------------
268 QString nmeaMode = settings.value("serialAutoNMEA").toString();
269 if (nmeaMode == "Auto") {
270 _serialNMEA = AUTO_NMEA;
271 QString fName = settings.value("serialFileNMEA").toString();
272 if (!fName.isEmpty()) {
273 _serialOutFile = new QFile(fName);
274 if (Qt::CheckState(settings.value("rnxAppend").toInt())
275 == Qt::Checked) {
276 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
277 } else {
278 _serialOutFile->open(QIODevice::WriteOnly);
279 }
280 }
281 }
282 // Manual NMEA
283 // -----------
284 if ((nmeaMode == "Manual GPGGA") ||
285 (nmeaMode == "Manual GNGGA")) {
286 _serialNMEA = MANUAL_NMEA;
287 bncSettings settings;
288 QString hlp = settings.value("serialHeightNMEA").toString();
289 if (hlp.isEmpty()) {
290 hlp = "0.0";
291 }
292 QByteArray _serialHeightNMEA = hlp.toLatin1();
293 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA, nmeaMode);
294 }
295 }
296
297 if (!_staID.isEmpty() && _latencycheck) {
298 _latencyChecker = new latencyChecker(_staID);
299 _rtcmObs = false;
300 _rtcmSsrOrb = false;
301 _rtcmSsrClk = false;
302 _rtcmSsrOrbClk = false;
303 _rtcmSsrCbi = false;
304 _rtcmSsrPbi = false;
305 _rtcmSsrVtec = false;
306 _rtcmSsrUra = false;
307 _rtcmSsrHr = false;
308 _rtcmSsrIgs = false;
309 _ssrEpoch = 0;
310 } else {
311 _latencyChecker = 0;
312 }
313}
314
315// Instantiate the decoder
316//////////////////////////////////////////////////////////////////////////////
317t_irc bncGetThread::initDecoder() {
318
319 _decoder = 0;
320
321 if (_format.indexOf("RTCM_2") != -1 ||
322 _format.indexOf("RTCM2") != -1 ||
323 _format.indexOf("RTCM 2") != -1) {
324 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
325 _decoder = new RTCM2Decoder(_staID.data());
326 } else if (_format.indexOf("RTCM_3") != -1 ||
327 _format.indexOf("RTCM3") != -1 ||
328 _format.indexOf("RTCM 3") != -1) {
329 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
330 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
331 _decoder = newDecoder;
332 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
333 this, SIGNAL(newMessage(QByteArray,bool)));
334 } else if (_format == "ZERO") {
335 emit(newMessage(_staID + ": Forward data in original format", true));
336 _decoder = new bncZeroDecoder(_staID, false);
337 }
338 else if (_format == "ZERO2FILE") {
339 emit(newMessage(_staID + ": Get data in original format and store it", true));
340 _decoder = new bncZeroDecoder(_staID, true);
341 }
342 else if (_format.indexOf("RTNET") != -1) {
343 emit(newMessage(_staID + ": Get data in RTNet format", true));
344 _decoder = new bncRtnetDecoder();
345 } else {
346 emit(newMessage(_staID + ": Unknown data format " + _format, true));
347 _isToBeDeleted = true;
348 return failure;
349 }
350
351 msleep(100); //sleep 0.1 sec
352
353 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
354 _ntripVersion);
355
356 if (_rawFile) {
357 _decodersRaw[_staID] = _decoder;
358 }
359
360 return success;
361}
362
363// Current decoder in use
364////////////////////////////////////////////////////////////////////////////
365GPSDecoder* bncGetThread::decoder() {
366 if (!_rawFile) {
367 return _decoder;
368 } else {
369 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
370 return _decodersRaw[_staID];
371 }
372 }
373 return 0;
374}
375
376// Destructor
377////////////////////////////////////////////////////////////////////////////
378bncGetThread::~bncGetThread() {
379 if (isRunning()) {
380 wait();
381 }
382 if (_query) {
383 _query->stop();
384 _query->deleteLater();
385 }
386 if (_rawFile) {
387 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
388 while (it.hasNext()) {
389 it.next();
390 delete it.value();
391 }
392 _decodersRaw.clear();
393 } else {
394 delete _decoder;
395 }
396 delete _rawFile;
397 delete _serialOutFile;
398 delete _serialPort;
399 delete _latencyChecker;
400 emit getThreadFinished(_staID);
401}
402
403//
404////////////////////////////////////////////////////////////////////////////
405void bncGetThread::terminate() {
406 _isToBeDeleted = true;
407
408 if (_nmeaPortsMap.contains(_staID)) {
409 _nmeaPortsMap.remove(_staID);
410 }
411 if (_nmeaServer) {
412 delete _nmeaServer;
413 }
414 if (_nmeaSockets) {
415 delete _nmeaSockets;
416 }
417
418#ifdef BNC_DEBUG
419 if (BNC_CORE->mode() != t_bncCore::interactive) {
420 while (!isFinished()) {
421 wait();
422 }
423 delete this;
424 } else {
425 if (!isRunning()) {
426 delete this;
427 }
428 }
429#else
430 if (!isRunning()) {delete this;}
431#endif
432
433}
434
435// Run
436////////////////////////////////////////////////////////////////////////////
437void bncGetThread::run() {
438
439 while (true) {
440 try {
441 if (_isToBeDeleted) {
442 emit(newMessage(_staID + ": is to be deleted", true));
443 QThread::exit(4);
444 this->deleteLater();
445 return;
446 }
447
448 if (tryReconnect() != success) {
449 if (_latencyChecker) {
450 _latencyChecker->checkReconnect();
451 }
452 continue;
453 }
454
455 // Delete old observations
456 // -----------------------
457 if (_rawFile) {
458 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
459 while (itDec.hasNext()) {
460 itDec.next();
461 GPSDecoder* decoder = itDec.value();
462 decoder->_obsList.clear();
463 }
464 } else {
465 _decoder->_obsList.clear();
466 }
467
468 // Read Data
469 // ---------
470 QByteArray data;
471 if (_query) {
472 _query->waitForReadyRead(data);
473 } else if (_rawFile) {
474 data = _rawFile->readChunk();
475 _format = _rawFile->format();
476 _staID = _rawFile->staID();
477
478 QCoreApplication::processEvents();
479
480 if (data.isEmpty() || BNC_CORE->sigintReceived) {
481 emit(newMessage("No more data or SIGINT/SIGTERM received", true));
482 BNC_CORE->stopPPP();
483 BNC_CORE->stopCombination();
484 sleep(2);
485 ::exit(5);
486 }
487 }
488
489 qint64 nBytes = data.size();
490
491 // Timeout, reconnect
492 // ------------------
493 if (nBytes == 0) {
494 if (_latencyChecker) {
495 _latencyChecker->checkReconnect();
496 }
497 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
498 msleep(10000); //sleep 10 sec, G. Weber
499 continue;
500 } else {
501 emit newBytes(_staID, nBytes);
502 emit newRawData(_staID, data);
503 }
504
505 // Output Data
506 // -----------
507 if (_rawOutput) {
508 BNC_CORE->writeRawData(data, _staID, _format);
509 }
510
511 if (_serialPort) {
512 slotSerialReadyRead();
513 _serialPort->write(data);
514 }
515
516 // Decode Data
517 // -----------
518 vector<string> errmsg;
519 if (!decoder()) {
520 _isToBeDeleted = true;
521 continue;
522 }
523
524 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
525
526 if (irc != success) {
527 continue;
528 }
529 // Perform various scans and checks
530 // --------------------------------
531 if (_latencyChecker) {
532 _latencyChecker->checkOutage(irc);
533 QListIterator<GPSDecoder::t_typeInfo> it(decoder()->_typeList);
534 _ssrEpoch = static_cast<int>(decoder()->corrGPSEpochTime());
535 if (_ssrEpoch != -1) {
536 if (_rtcmSsrOrb) {
537 _latencyChecker->checkCorrLatency(_ssrEpoch, 1057);
538 _rtcmSsrOrb = false;
539 }
540 if (_rtcmSsrClk) {
541 _latencyChecker->checkCorrLatency(_ssrEpoch, 1058);
542 _rtcmSsrClk = false;
543 }
544 if (_rtcmSsrOrbClk) {
545 _latencyChecker->checkCorrLatency(_ssrEpoch, 1060);
546 _rtcmSsrOrbClk = false;
547 }
548 if (_rtcmSsrCbi) {
549 _latencyChecker->checkCorrLatency(_ssrEpoch, 1059);
550 _rtcmSsrCbi = false;
551 }
552 if (_rtcmSsrPbi) {
553 _latencyChecker->checkCorrLatency(_ssrEpoch, 1265);
554 _rtcmSsrPbi = false;
555 }
556 if (_rtcmSsrVtec) {
557 _latencyChecker->checkCorrLatency(_ssrEpoch, 1264);
558 _rtcmSsrVtec = false;
559 }
560 if (_rtcmSsrUra) {
561 _latencyChecker->checkCorrLatency(_ssrEpoch, 1061);
562 _rtcmSsrUra = false;
563 }
564 if (_rtcmSsrHr) {
565 _latencyChecker->checkCorrLatency(_ssrEpoch, 1062);
566 _rtcmSsrHr = false;
567 }
568 if (_rtcmSsrIgs) {
569 _latencyChecker->checkCorrLatency(_ssrEpoch, 4076);
570 _rtcmSsrIgs = false;
571 }
572 }
573 while (it.hasNext()) {
574 int rtcmType = it.next().type;
575 if ((rtcmType >= 1001 && rtcmType <= 1004) || // legacy RTCM OBS
576 (rtcmType >= 1009 && rtcmType <= 1012) || // legacy RTCM OBS
577 (rtcmType >= 1070 && rtcmType <= 1137)) { // MSM RTCM OBS
578 _rtcmObs = true;
579 } else if ((rtcmType >= 1057 && rtcmType <= 1068) ||
580 (rtcmType >= 1240 && rtcmType <= 1270) ||
581 (rtcmType == 4076)) {
582 switch (rtcmType) {
583 case 1057: case 1063: case 1240: case 1246: case 1252: case 1258:
584 _rtcmSsrOrb = true;
585 break;
586 case 1058: case 1064: case 1241: case 1247: case 1253: case 1259:
587 _rtcmSsrClk = true;
588 break;
589 case 1060: case 1066: case 1243: case 1249: case 1255: case 1261:
590 _rtcmSsrOrbClk = true;
591 break;
592 case 1059: case 1065: case 1242: case 1248: case 1254: case 1260:
593 _rtcmSsrCbi = true;
594 break;
595 case 1265: case 1266: case 1267: case 1268: case 1269: case 1270:
596 _rtcmSsrPbi = true;
597 break;
598 case 1264:
599 _rtcmSsrVtec = true;
600 break;
601 case 1061: case 1067: case 1244: case 1250: case 1256: case 1262:
602 _rtcmSsrUra = true;
603 break;
604 case 1062: case 1068: case 1245: case 1251: case 1257: case 1263:
605 _rtcmSsrHr = true;
606 break;
607 case 4076:
608 _rtcmSsrIgs = true;
609 break;
610 }
611 }
612 }
613 if (_rtcmObs) {
614 _latencyChecker->checkObsLatency(decoder()->_obsList);
615 }
616 emit newLatency(_staID, _latencyChecker->currentLatency());
617 }
618 miscScanRTCM();
619
620 // Loop over all observations (observations output)
621 // ------------------------------------------------
622 QListIterator<t_satObs> it(decoder()->_obsList);
623
624 QList<t_satObs> obsListHlp;
625
626 while (it.hasNext()) {
627 const t_satObs& obs = it.next();
628
629 // Check observation epoch
630 // -----------------------
631 if (!_rawFile) {
632 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
633 if (wrongObservationEpoch) {
634 QString prn(obs._prn.toString().c_str());
635 QString type = QString("%1").arg(obs._type);
636 emit(newMessage(_staID + " (" + prn.toLatin1() + ")" + ": Wrong observation epoch(s)" + "( MT: " + type.toLatin1() + ")", false));
637 continue;
638 }
639 }
640
641 // Check observations coming twice (e.g. KOUR0 Problem)
642 // ----------------------------------------------------
643 if (!_rawFile) {
644 QString prn(obs._prn.toString().c_str());
645 bncTime obsTime = obs._time;
646 QMap<QString, bncTime>::const_iterator it = _prnLastEpo.find(prn);
647 if (it != _prnLastEpo.end()) {
648 bncTime oldTime = it.value();
649 if (obsTime < oldTime) {
650 emit(newMessage(_staID + ": old observation " + prn.toLatin1(), false));
651 continue;
652 } else if (obsTime == oldTime) {
653 emit(newMessage(_staID + ": observation coming more than once " + prn.toLatin1(), false));
654 continue;
655 }
656 }
657 _prnLastEpo[prn] = obsTime;
658 }
659
660 decoder()->dumpRinexEpoch(obs, _format);
661
662 // Save observations
663 // -----------------
664 obsListHlp.append(obs);
665 }
666
667 // Emit signal
668 // -----------
669 if (!_isToBeDeleted && obsListHlp.size() > 0) {
670 emit newObs(_staID, obsListHlp);
671 }
672
673 }
674 catch (Exception& exc) {
675 emit(newMessage(_staID + " " + exc.what(), true));
676 _isToBeDeleted = true;
677 }
678 catch (std::exception& exc) {
679 emit(newMessage(_staID + " " + exc.what(), true));
680 _isToBeDeleted = true;
681 }
682 catch (const string& error) {
683 emit(newMessage(_staID + " ERROR: " + error.c_str(), true));
684 _isToBeDeleted = true;
685 }
686 catch (const char* error) {
687 emit(newMessage(_staID + " ERROR: " + error, true));
688 _isToBeDeleted = true;
689 }
690 catch (QString error) {
691 emit(newMessage(_staID + " ERROR: " + error.toStdString().c_str(), true));
692 _isToBeDeleted = true;
693 }
694 catch (...) {
695 emit(newMessage(_staID + " bncGetThread: unknown exception", true));
696 _isToBeDeleted = true;
697 }
698 }
699}
700
701// Try Re-Connect
702////////////////////////////////////////////////////////////////////////////
703t_irc bncGetThread::tryReconnect() {
704
705 // Easy Return
706 // -----------
707 if (_query && _query->status() == bncNetQuery::running) {
708 _nextSleep = 0;
709 if (_rawFile) {
710 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
711 while (itDec.hasNext()) {
712 itDec.next();
713 GPSDecoder* decoder = itDec.value();
714 decoder->setRinexReconnectFlag(false);
715 }
716 } else {
717 _decoder->setRinexReconnectFlag(false);
718 }
719 return success;
720 }
721
722 // Start a new query
723 // -----------------
724 if (!_rawFile) {
725
726 sleep(_nextSleep);
727 if (_nextSleep == 0) {
728 _nextSleep = 1;
729 } else {
730 _nextSleep = 2 * _nextSleep;
731 if (_nextSleep > 256) {
732 _nextSleep = 256;
733 }
734#ifdef MLS_SOFTWARE
735 if (_nextSleep > 4) {
736 _nextSleep = 4;
737 }
738#endif
739 }
740 delete _query;
741 if (_ntripVersion == "U") {
742 _query = new bncNetQueryUdp();
743 } else if (_ntripVersion == "R") {
744 _query = new bncNetQueryRtp();
745 } else if (_ntripVersion == "S") {
746 _query = new bncNetQueryS();
747 } else if (_ntripVersion == "N") {
748 _query = new bncNetQueryV0();
749 } else if (_ntripVersion == "UN") {
750 _query = new bncNetQueryUdp0();
751 } else if (_ntripVersion == "2") {
752 _query = new bncNetQueryV2(false);
753 } else if (_ntripVersion == "2s") {
754 _query = new bncNetQueryV2(true);
755 } else {
756 _query = new bncNetQueryV1();
757 }
758 if (_nmea == "yes") {
759 if (_serialNMEA == MANUAL_NMEA) {
760 _query->startRequest(_mountPoint, _manualNMEAString);
761 _lastNMEA = QDateTime::currentDateTime();
762 } else if (_serialNMEA == AUTO_NMEA) {
763 if (_serialPort) {
764 int nb = _serialPort->bytesAvailable();
765 if (nb > 0) {
766 QByteArray data = _serialPort->read(nb);
767 int i1 = data.indexOf("$GPGGA");
768 if (i1 == -1) {
769 i1 = data.indexOf("$GNGGA");
770 }
771 if (i1 != -1) {
772 int i2 = data.indexOf("*", i1);
773 if (i2 != -1 && data.size() > i2 + 1) {
774 QByteArray gga = data.mid(i1, i2 - i1 + 3);
775 _query->startRequest(_mountPoint, gga);
776 _lastNMEA = QDateTime::currentDateTime();
777 }
778 }
779 }
780 }
781 }
782 } else {
783 _query->startRequest(_mountPoint, "");
784 }
785
786 if (_query->status() != bncNetQuery::running) {
787 return failure;
788 }
789 }
790
791 if (_rawFile) {
792 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
793 while (itDec.hasNext()) {
794 itDec.next();
795 GPSDecoder* decoder = itDec.value();
796 decoder->setRinexReconnectFlag(false);
797 }
798 } else {
799 _decoder->setRinexReconnectFlag(false);
800 }
801
802 return success;
803}
804
805// RTCM scan output
806//////////////////////////////////////////////////////////////////////////////
807void bncGetThread::miscScanRTCM() {
808
809 if (!decoder()) {
810 return;
811 }
812
813 bncSettings settings;
814 if (Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked) {
815
816 if (_miscMount == _staID || _miscMount == "ALL") {
817 // RTCM message types
818 // ------------------
819 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
820 QString type = QString("%1 ").arg(decoder()->_typeList[ii].type);
821 QString size = (decoder()->_typeList[ii].size) ? QString("(size %1)").arg(decoder()->_typeList[ii].size) : "";
822 emit(newMessage(_staID + ": Received message type " + type.toLatin1() + size.toLatin1(), true));
823 }
824
825 // Check Observation Types
826 // -----------------------
827 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
828 t_satObs& obs = decoder()->_obsList[ii];
829 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
830 bool allFound = true;
831 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
832 if (obs._obs[iFrq]->_codeValid) {
833 QString rnxStr('C');
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 if (obs._obs[iFrq]->_phaseValid) {
846 QString rnxStr('L');
847 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
848 if (_format.indexOf("RTCM_2") != -1
849 || _format.indexOf("RTCM2") != -1
850 || _format.indexOf("RTCM 2") != -1) {
851 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
852 }
853 if (rnxTypes.indexOf(rnxStr) == -1) {
854 rnxTypes.push_back(rnxStr);
855 allFound = false;
856 }
857 }
858 if (obs._obs[iFrq]->_dopplerValid) {
859 QString rnxStr('D');
860 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
861 if (_format.indexOf("RTCM_2") != -1
862 || _format.indexOf("RTCM2") != -1
863 || _format.indexOf("RTCM 2") != -1) {
864 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
865 }
866 if (rnxTypes.indexOf(rnxStr) == -1) {
867 rnxTypes.push_back(rnxStr);
868 allFound = false;
869 }
870 }
871 if (obs._obs[iFrq]->_snrValid) {
872 QString rnxStr('S');
873 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
874 if (_format.indexOf("RTCM_2") != -1
875 || _format.indexOf("RTCM2") != -1
876 || _format.indexOf("RTCM 2") != -1) {
877 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
878 }
879 if (rnxTypes.indexOf(rnxStr) == -1) {
880 rnxTypes.push_back(rnxStr);
881 allFound = false;
882 }
883 }
884 }
885 if (!allFound) {
886 QString msg;
887 QTextStream str(&msg);
888 str << obs._prn.system() << QString(" %1 ").arg(rnxTypes.size());
889 for (int iType = 0; iType < rnxTypes.size(); iType++) {
890 str << " " << rnxTypes[iType];
891 }
892 emit(newMessage(_staID + ": Observation Types: " + msg.toLatin1(), true));
893 }
894 }
895
896 // RTCMv3 antenna descriptor
897 // -------------------------
898 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
899 QString ant1 = QString(": Antenna Descriptor: %1 ").arg(decoder()->_antType[ii].descriptor);
900 emit(newMessage(_staID + ant1.toLatin1(), true));
901 if (strlen(decoder()->_antType[ii].serialnumber)) {
902 QString ant2 = QString(": Antenna Serial Number: %1 ").arg(decoder()->_antType[ii].serialnumber);
903 emit(newMessage(_staID + ant2.toLatin1(), true));
904 }
905 }
906
907 // RTCM Antenna Coordinates
908 // ------------------------
909 for (int ii = 0; ii < decoder()->_antList.size(); ii++) {
910 QByteArray antT;
911 if (decoder()->_antList[ii].type == GPSDecoder::t_antRefPoint::ARP) {
912 antT = "ARP";
913 } else if (decoder()->_antList[ii].type == GPSDecoder::t_antRefPoint::APC) {
914 antT = "APC";
915 }
916 QByteArray ant1, ant2, ant3;
917 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).toLatin1();
918 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).toLatin1();
919 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).toLatin1();
920 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
921 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
922 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
923 double hh = 0.0;
924 if (decoder()->_antList[ii].height_f) {
925 hh = decoder()->_antList[ii].height;
926 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toLatin1();
927 emit(newMessage(
928 _staID + ": Antenna height above marker " + ant4 + "m", true));
929 }
930 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
931 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, hh, antT));
932 }
933
934 // RTCMv3 receiver descriptor
935 // --------------------------
936 for (int ii = 0; ii < decoder()->_recType.size(); ii++) {
937 QString rec1 = QString(": Receiver Descriptor: %1 ").arg(decoder()->_recType[ii].descriptor);
938 QString rec2 = QString(": Receiver Firmware Version: %1 ").arg(decoder()->_recType[ii].firmware);
939 QString rec3 = QString(": Receiver Serial Number: %1 ").arg(decoder()->_recType[ii].serialnumber);
940 emit(newMessage(_staID + rec1.toLatin1(), true));
941 emit(newMessage(_staID + rec2.toLatin1(), true));
942 emit(newMessage(_staID + rec3.toLatin1(), true));
943 }
944
945 // RTCM GLONASS slots
946 // ------------------
947 if (decoder()->_gloFrq.size()) {
948 bool allFound = true;
949 QString slot = decoder()->_gloFrq;
950 slot.replace(" ", " ").replace(" ", ":");
951 if (_gloSlots.indexOf(slot) == -1) {
952 _gloSlots.append(slot);
953 allFound = false;
954 }
955 if (!allFound) {
956 _gloSlots.sort();
957 emit(newMessage(
958 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toLatin1(),
959 true));
960 }
961 }
962
963 // RTCM GLONASS Code-Phase biases (MT 1230)
964 // ----------------------------------------
965 if (decoder()->_gloBiases.changed) {
966 QString gloCodePhaseBiases = decoder()->_gloBiases.toString();
967 emit(newMessage(_staID + gloCodePhaseBiases.toLatin1(), true));
968 }
969
970 // Service CRS / RTCM CRS
971 // ------------------------
972 if (fmod(decoder()->corrGPSEpochTime(), 60.0) == 0.0) {
973 // Service CRS
974 for (int ii = 0; ii < decoder()->_serviceCrs.size(); ii++) {
975 QString servicecrsname = QString(": Service CRS Name: %1 ").arg(decoder()->_serviceCrs[ii]._name);
976 QString coordinateEpoch = QString(": Service CRS Coordinate Epoch: %1 ").arg(decoder()->_serviceCrs[ii]._coordinateEpoch);
977 //QString ce = QString(": CE: %1 ").arg(decoder()->_serviceCrs[ii]._CE);
978 emit(newMessage(_staID + servicecrsname.toLatin1(), true));
979 emit(newMessage(_staID + coordinateEpoch.toLatin1(), true));
980 //emit(newMessage(_staID + ce.toLatin1(), true));
981 }
982 // RTCM CRS
983 for (int ii = 0; ii < decoder()->_rtcmCrs.size(); ii++) {
984 QString rtcmcrsname = QString(": RTCM CRS Name: %1 ").arg(decoder()->_rtcmCrs[ii]._name);
985 QString anchor = QString(": RTCM CRS Anchor: %1 ").arg(decoder()->_rtcmCrs[ii]._anchor);
986 QString platenumber = QString(": RTCM CRS Plate Number: %1 ").arg(decoder()->_rtcmCrs[ii]._plateNumber);
987 emit(newMessage(_staID + rtcmcrsname.toLatin1(), true));
988 emit(newMessage(_staID + anchor.toLatin1(), true));
989 emit(newMessage(_staID + platenumber.toLatin1(), true));
990 for (int i = 0; i<decoder()->_rtcmCrs[ii]._databaseLinks.size(); i++) {
991 QString dblink = QString(": Database Link: %1 ").arg(decoder()->_rtcmCrs[ii]._databaseLinks[i]);
992 emit(newMessage(_staID + dblink.toLatin1(), true));
993 }
994 }
995
996 // Helmert Parameters
997 //-------------------
998 for (int ii = 0; ii < decoder()->_helmertPar.size(); ii++) {
999 t_helmertPar& helmertPar = decoder()->_helmertPar[ii];
1000 bncTime t; t.setmjd(0, helmertPar._mjd); QString dateStr = QString::fromStdString(t.datestr());
1001 QString sourcename = QString(": MT1301 Source Name: %1 ").arg(helmertPar._sourceName);
1002 QString targetname = QString(": MT1301 Target Name: %1 ").arg(helmertPar._targetName);
1003 QString sysidentnum = QString(": MT1301 Sys Ident Num: %1 ").arg(helmertPar._sysIdentNum);
1004 QString trafomessageind = QString(": MT1301 Trafo Ident Num: %1 ").arg(helmertPar.IndtoString());
1005 QString epoch = QString(": MT1301 t0: MJD %1 (%2) ").arg(helmertPar._mjd).arg(dateStr);
1006 QString partrans = QString(": MT1301 Helmert Par Trans: dx = %1, dy = %2, dz = %3, dxr = %4, dyr = %5, dzr = %6")
1007 .arg(helmertPar._dx).arg(helmertPar._dy).arg(helmertPar._dz)
1008 .arg(helmertPar._dxr).arg(helmertPar._dyr).arg(helmertPar._dzr);
1009 QString parrot = QString(": MT1301 Helmert Par Rot: ox = %1, oy = %2, oz = %3, oxr = %4, oyr = %5, ozr = %6")
1010 .arg(helmertPar._ox).arg(helmertPar._oy).arg(helmertPar._oz)
1011 .arg(helmertPar._oxr).arg(helmertPar._oyr).arg(helmertPar._ozr);
1012 QString parscale = QString(": MT1301 Helmert Par Scale: sc = %1, scr = %2").arg(helmertPar._sc).arg(helmertPar._scr);
1013 emit(newMessage(_staID + sourcename.toLatin1(), true));
1014 emit(newMessage(_staID + targetname.toLatin1(), true));
1015 emit(newMessage(_staID + sysidentnum.toLatin1(), true));
1016 emit(newMessage(_staID + trafomessageind.toLatin1(), true));
1017 emit(newMessage(_staID + epoch.toLatin1(), true));
1018 emit(newMessage(_staID + partrans.toLatin1(), true));
1019 emit(newMessage(_staID + parrot.toLatin1(), true));
1020 emit(newMessage(_staID + parscale.toLatin1(), true));
1021 }
1022 }
1023 }
1024 }
1025
1026#ifdef MLS_SOFTWARE
1027 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
1028 QByteArray antT;
1029 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
1030 antT = "ARP";
1031 }
1032 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
1033 antT = "APC";
1034 }
1035 double hh = 0.0;
1036 if (decoder()->_antList[ii].height_f) {
1037 hh = decoder()->_antList[ii].height;
1038 }
1039 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
1040 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
1041 hh, antT));
1042 }
1043
1044 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
1045 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
1046 }
1047#endif
1048
1049 decoder()->_gloFrq.clear();
1050 // decoder()->_gloBiases.clear();
1051 decoder()->_typeList.clear();
1052 decoder()->_antType.clear();
1053 decoder()->_recType.clear();
1054 decoder()->_antList.clear();
1055}
1056
1057// Handle Data from Serial Port
1058////////////////////////////////////////////////////////////////////////////
1059void bncGetThread::slotSerialReadyRead() {
1060
1061 if (_serialPort) {
1062
1063 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
1064 if (_NMEASampl) {
1065 int dt = _lastNMEA.secsTo(QDateTime::currentDateTime());
1066 if (dt && (fmod(double(dt), double(_NMEASampl)) == 0.0)) {
1067 _query->sendNMEA(_manualNMEAString);
1068 _lastNMEA = QDateTime::currentDateTime();
1069 }
1070 }
1071 }
1072
1073 int nb = _serialPort->bytesAvailable();
1074 if (nb > 0) {
1075 QByteArray data = _serialPort->read(nb);
1076
1077 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
1078 int i1 = data.indexOf("$GPGGA");
1079 if (i1 == -1) {
1080 i1 = data.indexOf("$GNGGA");
1081 }
1082 if (i1 != -1) {
1083 int i2 = data.indexOf("*", i1);
1084 if (i2 != -1 && data.size() > i2 + 1) {
1085 QByteArray gga = data.mid(i1, i2 - i1 + 3);
1086 if (_NMEASampl) {
1087 int dt = _lastNMEA.secsTo(QDateTime::currentDateTime());
1088 if (dt && (fmod(double(dt), double(_NMEASampl)) == 0.0)) {
1089 _query->sendNMEA(gga);
1090 _lastNMEA = QDateTime::currentDateTime();
1091 }
1092 }
1093 }
1094 }
1095 }
1096
1097 if (_serialOutFile) {
1098 _serialOutFile->write(data);
1099 _serialOutFile->flush();
1100 }
1101 }
1102 }
1103}
1104
1105void bncGetThread::slotNewNMEAConnection() {
1106 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
1107 emit(newMessage(
1108 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1(),
1109 true));
1110}
1111
1112//
1113////////////////////////////////////////////////////////////////////////////
1114void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
1115 if (_nmeaPortsMap.contains(staID)) {
1116 int nmeaPort = _nmeaPortsMap.value(staID);
1117 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
1118 while (is.hasNext()) {
1119 QTcpSocket* sock = is.next();
1120 if (sock->localPort() == nmeaPort) {
1121 if (sock->state() == QAbstractSocket::ConnectedState) {
1122 sock->write(str);
1123 } else if (sock->state() != QAbstractSocket::ConnectingState) {
1124 delete sock;
1125 is.remove();
1126 }
1127 }
1128 }
1129 }
1130}
Note: See TracBrowser for help on using the repository browser.