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

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

add an docoder-string ZERO2FILE

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