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

Last change on this file since 8252 was 8252, checked in by stoecker, 6 years ago

see #105 - reenable Qt4 build options, drop generic version dependend includes, replace by direct requirements, remaining QtCore lines should also be replaced

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