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

Last change on this file since 8653 was 8417, checked in by stuerze, 6 years ago

some changes to allow 10 Hz observation data real-time processing

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