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

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