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

Last change on this file since 9043 was 9017, checked in by stuerze, 4 years ago

minor changes

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