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

Last change on this file since 8818 was 8781, checked in by stuerze, 5 years ago

minor changes

File size: 30.9 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 _ssrEpoch = 0;
305 } else {
306 _latencyChecker = 0;
307 }
308}
309
310// Instantiate the decoder
311//////////////////////////////////////////////////////////////////////////////
312t_irc bncGetThread::initDecoder() {
313
314 _decoder = 0;
315
316 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1
317 || _format.indexOf("RTCM 2") != -1) {
318 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
319 _decoder = new RTCM2Decoder(_staID.data());
320 } else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1
321 || _format.indexOf("RTCM 3") != -1) {
322 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
323 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
324 _decoder = newDecoder;
325 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
326 this, SIGNAL(newMessage(QByteArray,bool)));
327 } else if (_format.indexOf("ZERO") != -1) {
328 emit(newMessage(_staID + ": Get data in original format", true));
329 _decoder = new bncZeroDecoder(_staID);
330 } else if (_format.indexOf("RTNET") != -1) {
331 emit(newMessage(_staID + ": Get data in RTNet format", true));
332 _decoder = new bncRtnetDecoder();
333 } else {
334 emit(newMessage(_staID + ": Unknown data format " + _format, true));
335 _isToBeDeleted = true;
336 return failure;
337 }
338
339 msleep(100); //sleep 0.1 sec
340
341 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
342 _ntripVersion);
343
344 if (_rawFile) {
345 _decodersRaw[_staID] = _decoder;
346 }
347
348 return success;
349}
350
351// Current decoder in use
352////////////////////////////////////////////////////////////////////////////
353GPSDecoder* bncGetThread::decoder() {
354 if (!_rawFile) {
355 return _decoder;
356 } else {
357 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
358 return _decodersRaw[_staID];
359 }
360 }
361 return 0;
362}
363
364// Destructor
365////////////////////////////////////////////////////////////////////////////
366bncGetThread::~bncGetThread() {
367 if (isRunning()) {
368 wait();
369 }
370 if (_query) {
371 _query->stop();
372 _query->deleteLater();
373 }
374 if (_rawFile) {
375 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
376 while (it.hasNext()) {
377 it.next();
378 delete it.value();
379 }
380 } else {
381 delete _decoder;
382 }
383 delete _rawFile;
384 delete _serialOutFile;
385 delete _serialPort;
386 delete _latencyChecker;
387 emit getThreadFinished(_staID);
388}
389
390//
391////////////////////////////////////////////////////////////////////////////
392void bncGetThread::terminate() {
393 _isToBeDeleted = true;
394
395 if (_nmeaPortsMap.contains(_staID)) {
396 _nmeaPortsMap.remove(_staID);
397 }
398 if (_nmeaServer) {
399 delete _nmeaServer;
400 }
401 if (_nmeaSockets) {
402 delete _nmeaSockets;
403 }
404
405#ifdef BNC_DEBUG
406 if (BNC_CORE->mode() != t_bncCore::interactive) {
407 while (!isFinished()) {
408 wait();
409 }
410 delete this;
411 } else {
412 if (!isRunning()) {
413 delete this;
414 }
415 }
416#else
417 if (!isRunning()) {delete this;}
418#endif
419
420}
421
422// Run
423////////////////////////////////////////////////////////////////////////////
424void bncGetThread::run() {
425
426 while (true) {
427 try {
428 if (_isToBeDeleted) {
429 QThread::exit(0);
430 this->deleteLater();
431 return;
432 }
433
434 if (tryReconnect() != success) {
435 if (_latencyChecker) {
436 _latencyChecker->checkReconnect();
437 }
438 continue;
439 }
440
441 // Delete old observations
442 // -----------------------
443 if (_rawFile) {
444 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
445 while (itDec.hasNext()) {
446 itDec.next();
447 GPSDecoder* decoder = itDec.value();
448 decoder->_obsList.clear();
449 }
450 } else {
451 _decoder->_obsList.clear();
452 }
453
454 // Read Data
455 // ---------
456 QByteArray data;
457 if (_query) {
458 _query->waitForReadyRead(data);
459 } else if (_rawFile) {
460 data = _rawFile->readChunk();
461 _format = _rawFile->format();
462 _staID = _rawFile->staID();
463
464 QCoreApplication::processEvents();
465
466 if (data.isEmpty() || BNC_CORE->sigintReceived) {
467 cout << "no more data or Ctrl-C received" << endl;
468 BNC_CORE->stopCombination();
469 BNC_CORE->stopPPP();
470 sleep(1);
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 (_ssrEpoch != -1) {
522 if (ssrOrb) {
523 _latencyChecker->checkCorrLatency(_ssrEpoch, 1057);
524 ssrOrb = false;
525 }
526 if (ssrClk) {
527 _latencyChecker->checkCorrLatency(_ssrEpoch, 1058);
528 ssrClk = false;
529 }
530 if (ssrOrbClk) {
531 _latencyChecker->checkCorrLatency(_ssrEpoch, 1060);
532 ssrOrbClk = false;
533 }
534 if (ssrCbi) {
535 _latencyChecker->checkCorrLatency(_ssrEpoch, 1059);
536 ssrCbi = false;
537 }
538 if (ssrPbi) {
539 _latencyChecker->checkCorrLatency(_ssrEpoch, 1265);
540 ssrPbi = false;
541 }
542 if (ssrVtec) {
543 _latencyChecker->checkCorrLatency(_ssrEpoch, 1264);
544 ssrVtec = false;
545 }
546 if (ssrUra) {
547 _latencyChecker->checkCorrLatency(_ssrEpoch, 1061);
548 ssrUra = false;
549 }
550 if (ssrHr) {
551 _latencyChecker->checkCorrLatency(_ssrEpoch, 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 emit newLatency(_staID, _latencyChecker->currentLatency());
595 }
596 miscScanRTCM();
597
598 // Loop over all observations (observations output)
599 // ------------------------------------------------
600 QListIterator<t_satObs> it(decoder()->_obsList);
601
602 QList<t_satObs> obsListHlp;
603
604 while (it.hasNext()) {
605 const t_satObs& obs = it.next();
606
607 // Check observation epoch
608 // -----------------------
609 if (!_rawFile) {
610 bool wrongObservationEpoch = checkForWrongObsEpoch(obs._time);
611 if (wrongObservationEpoch) {
612 QString prn(obs._prn.toString().c_str());
613 emit(newMessage(
614 _staID + " (" + prn.toLatin1() + ")"
615 + ": Wrong observation epoch(s)", false));
616 continue;
617 }
618 }
619
620 // Check observations coming twice (e.g. KOUR0 Problem)
621 // ----------------------------------------------------
622 if (!_rawFile) {
623 QString prn(obs._prn.toString().c_str());
624 bncTime obsTime = obs._time;
625 QMap<QString, bncTime>::const_iterator it = _prnLastEpo.find(prn);
626 if (it != _prnLastEpo.end()) {
627 bncTime oldTime = it.value();
628 if (obsTime < oldTime) {
629 emit(newMessage(_staID + ": old observation " + prn.toLatin1(), false));
630 continue;
631 } else if (obsTime == oldTime) {
632 emit(newMessage(_staID + ": observation coming more than once "
633 + prn.toLatin1(), false));
634 continue;
635 }
636 }
637 _prnLastEpo[prn] = obsTime;
638 }
639
640 decoder()->dumpRinexEpoch(obs, _format);
641
642 // Save observations
643 // -----------------
644 obsListHlp.append(obs);
645 }
646
647 // Emit signal
648 // -----------
649 if (!_isToBeDeleted && obsListHlp.size() > 0) {
650 emit newObs(_staID, obsListHlp);
651 }
652
653 } catch (Exception& exc) {
654 emit(newMessage(_staID + " " + exc.what(), true));
655 _isToBeDeleted = true;
656 } catch (...) {
657 emit(newMessage(_staID + " bncGetThread exception", true));
658 _isToBeDeleted = true;
659 }
660 }
661}
662
663// Try Re-Connect
664////////////////////////////////////////////////////////////////////////////
665t_irc bncGetThread::tryReconnect() {
666
667 // Easy Return
668 // -----------
669 if (_query && _query->status() == bncNetQuery::running) {
670 _nextSleep = 0;
671 if (_rawFile) {
672 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
673 while (itDec.hasNext()) {
674 itDec.next();
675 GPSDecoder* decoder = itDec.value();
676 decoder->setRinexReconnectFlag(false);
677 }
678 } else {
679 _decoder->setRinexReconnectFlag(false);
680 }
681 return success;
682 }
683
684 // Start a new query
685 // -----------------
686 if (!_rawFile) {
687
688 sleep(_nextSleep);
689 if (_nextSleep == 0) {
690 _nextSleep = 1;
691 } else {
692 _nextSleep = 2 * _nextSleep;
693 if (_nextSleep > 256) {
694 _nextSleep = 256;
695 }
696#ifdef MLS_SOFTWARE
697 if (_nextSleep > 4) {
698 _nextSleep = 4;
699 }
700#endif
701 }
702 delete _query;
703 if (_ntripVersion == "U") {
704 _query = new bncNetQueryUdp();
705 } else if (_ntripVersion == "R") {
706 _query = new bncNetQueryRtp();
707 } else if (_ntripVersion == "S") {
708 _query = new bncNetQueryS();
709 } else if (_ntripVersion == "N") {
710 _query = new bncNetQueryV0();
711 } else if (_ntripVersion == "UN") {
712 _query = new bncNetQueryUdp0();
713 } else if (_ntripVersion == "2") {
714 _query = new bncNetQueryV2(false);
715 } else if (_ntripVersion == "2s") {
716 _query = new bncNetQueryV2(true);
717 } else {
718 _query = new bncNetQueryV1();
719 }
720 if (_nmea == "yes") {
721 if (_serialNMEA == MANUAL_NMEA) {
722 _query->startRequest(_mountPoint, _manualNMEAString);
723 _lastManualNMEA = QDateTime::currentDateTime();
724 } else if (_serialNMEA == AUTO_NMEA) {
725 if (_serialPort) {
726 int nb = _serialPort->bytesAvailable();
727 if (nb > 0) {
728 QByteArray data = _serialPort->read(nb);
729 int i1 = data.indexOf("$GPGGA");
730 if (i1 == -1) {
731 i1 = data.indexOf("$GNGGA");
732 }
733 if (i1 != -1) {
734 int i2 = data.indexOf("*", i1);
735 if (i2 != -1 && data.size() > i2 + 1) {
736 QByteArray gga = data.mid(i1, i2 - i1 + 3);
737 _query->startRequest(_mountPoint, gga);
738 }
739 }
740 }
741 }
742 }
743 } else {
744 _query->startRequest(_mountPoint, "");
745 }
746
747 if (_query->status() != bncNetQuery::running) {
748 return failure;
749 }
750 }
751
752 if (_rawFile) {
753 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
754 while (itDec.hasNext()) {
755 itDec.next();
756 GPSDecoder* decoder = itDec.value();
757 decoder->setRinexReconnectFlag(false);
758 }
759 } else {
760 _decoder->setRinexReconnectFlag(false);
761 }
762
763 return success;
764}
765
766// RTCM scan output
767//////////////////////////////////////////////////////////////////////////////
768void bncGetThread::miscScanRTCM() {
769
770 if (!decoder()) {
771 return;
772 }
773
774 bncSettings settings;
775 if (Qt::CheckState(settings.value("miscScanRTCM").toInt()) == Qt::Checked) {
776
777 if (_miscMount == _staID || _miscMount == "ALL") {
778 // RTCM message types
779 // ------------------
780 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
781 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
782 emit(newMessage(_staID + ": Received message type " + type.toLatin1(),
783 true));
784 }
785
786 // Check Observation Types
787 // -----------------------
788 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
789 t_satObs& obs = decoder()->_obsList[ii];
790 QVector<QString>& rnxTypes = _rnxTypes[obs._prn.system()];
791 bool allFound = true;
792 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
793 if (obs._obs[iFrq]->_codeValid) {
794 QString rnxStr('C');
795 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
796 if (_format.indexOf("RTCM_2") != -1
797 || _format.indexOf("RTCM2") != -1
798 || _format.indexOf("RTCM 2") != -1) {
799 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
800 }
801 if (rnxTypes.indexOf(rnxStr) == -1) {
802 rnxTypes.push_back(rnxStr);
803 allFound = false;
804 }
805 }
806 if (obs._obs[iFrq]->_phaseValid) {
807 QString rnxStr('L');
808 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
809 if (_format.indexOf("RTCM_2") != -1
810 || _format.indexOf("RTCM2") != -1
811 || _format.indexOf("RTCM 2") != -1) {
812 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
813 }
814 if (rnxTypes.indexOf(rnxStr) == -1) {
815 rnxTypes.push_back(rnxStr);
816 allFound = false;
817 }
818 }
819 if (obs._obs[iFrq]->_dopplerValid) {
820 QString rnxStr('D');
821 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
822 if (_format.indexOf("RTCM_2") != -1
823 || _format.indexOf("RTCM2") != -1
824 || _format.indexOf("RTCM 2") != -1) {
825 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
826 }
827 if (rnxTypes.indexOf(rnxStr) == -1) {
828 rnxTypes.push_back(rnxStr);
829 allFound = false;
830 }
831 }
832 if (obs._obs[iFrq]->_snrValid) {
833 QString rnxStr('S');
834 rnxStr.append(obs._obs[iFrq]->_rnxType2ch.c_str());
835 if (_format.indexOf("RTCM_2") != -1
836 || _format.indexOf("RTCM2") != -1
837 || _format.indexOf("RTCM 2") != -1) {
838 rnxStr = t_rnxObsFile::type3to2(obs._prn.system(), rnxStr);
839 }
840 if (rnxTypes.indexOf(rnxStr) == -1) {
841 rnxTypes.push_back(rnxStr);
842 allFound = false;
843 }
844 }
845 }
846 if (!allFound) {
847 QString msg;
848 QTextStream str(&msg);
849 QString s;
850 str << obs._prn.system() << " "
851 << s.sprintf("%2d", rnxTypes.size()) << " ";
852 for (int iType = 0; iType < rnxTypes.size(); iType++) {
853 str << " " << rnxTypes[iType];
854 }
855 emit(newMessage(_staID + ": Observation Types: " + msg.toLatin1(),
856 true));
857 }
858 }
859
860 // RTCMv3 antenna descriptor
861 // -------------------------
862 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
863 QString ant1 = QString(": Antenna Descriptor: %1 ").arg(decoder()->_antType[ii].descriptor);
864 emit(newMessage(_staID + ant1.toLatin1(), true));
865 if (strlen(decoder()->_antType[ii].serialnumber)) {
866 QString ant2 = QString(": Antenna Serial Number: %1 ").arg(decoder()->_antType[ii].serialnumber);
867 emit(newMessage(_staID + ant2.toLatin1(), true));
868 }
869 }
870
871 // RTCM Antenna Coordinates
872 // ------------------------
873 for (int ii = 0; ii < decoder()->_antList.size(); ii++) {
874 QByteArray antT;
875 if (decoder()->_antList[ii].type == GPSDecoder::t_antRefPoint::ARP) {
876 antT = "ARP";
877 } else if (decoder()->_antList[ii].type == GPSDecoder::t_antRefPoint::APC) {
878 antT = "APC";
879 }
880 QByteArray ant1, ant2, ant3;
881 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).toLatin1();
882 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).toLatin1();
883 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).toLatin1();
884 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
885 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
886 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
887 double hh = 0.0;
888 if (decoder()->_antList[ii].height_f) {
889 hh = decoder()->_antList[ii].height;
890 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toLatin1();
891 emit(newMessage(
892 _staID + ": Antenna height above marker " + ant4 + "m", true));
893 }
894 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
895 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, hh, antT));
896 }
897
898 // RTCMv3 receiver descriptor
899 // --------------------------
900 for (int ii = 0; ii < decoder()->_recType.size(); ii++) {
901 QString rec1 = QString(": Receiver Descriptor: %1 ").arg(decoder()->_recType[ii].descriptor);
902 QString rec2 = QString(": Receiver Firmware Version: %1 ").arg(decoder()->_recType[ii].firmware);
903 QString rec3 = QString(": Receiver Serial Number: %1 ").arg(decoder()->_recType[ii].serialnumber);
904 emit(newMessage(_staID + rec1.toLatin1(), true));
905 emit(newMessage(_staID + rec2.toLatin1(), true));
906 emit(newMessage(_staID + rec3.toLatin1(), true));
907 }
908
909 // RTCM GLONASS slots
910 // ------------------
911 if (decoder()->_gloFrq.size()) {
912 bool allFound = true;
913 QString slot = decoder()->_gloFrq;
914 slot.replace(" ", " ").replace(" ", ":");
915 if (_gloSlots.indexOf(slot) == -1) {
916 _gloSlots.append(slot);
917 allFound = false;
918 }
919 if (!allFound) {
920 _gloSlots.sort();
921 emit(newMessage(
922 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toLatin1(),
923 true));
924 }
925 }
926 }
927 }
928
929#ifdef MLS_SOFTWARE
930 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
931 QByteArray antT;
932 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
933 antT = "ARP";
934 }
935 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
936 antT = "APC";
937 }
938 double hh = 0.0;
939 if (decoder()->_antList[ii].height_f) {
940 hh = decoder()->_antList[ii].height;
941 }
942 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
943 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
944 hh, antT));
945 }
946
947 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
948 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
949 }
950#endif
951
952 decoder()->_gloFrq.clear();
953 decoder()->_typeList.clear();
954 decoder()->_antType.clear();
955 decoder()->_recType.clear();
956 decoder()->_antList.clear();
957}
958
959// Handle Data from Serial Port
960////////////////////////////////////////////////////////////////////////////
961void bncGetThread::slotSerialReadyRead() {
962
963 if (_serialPort) {
964
965 if (_nmea == "yes" && _serialNMEA == MANUAL_NMEA) {
966 if (_manualNMEASampl) {
967 int dt = _lastManualNMEA.secsTo(QDateTime::currentDateTime());
968 if (dt && (fmod(double(dt), double(_manualNMEASampl)) == 0.0)) {
969 _query->sendNMEA(_manualNMEAString);
970 _lastManualNMEA = QDateTime::currentDateTime();
971 }
972 }
973 }
974
975 int nb = _serialPort->bytesAvailable();
976 if (nb > 0) {
977 QByteArray data = _serialPort->read(nb);
978
979 if (_nmea == "yes" && _serialNMEA == AUTO_NMEA) {
980 int i1 = data.indexOf("$GPGGA");
981 if (i1 == -1) {
982 i1 = data.indexOf("$GNGGA");
983 }
984 if (i1 != -1) {
985 int i2 = data.indexOf("*", i1);
986 if (i2 != -1 && data.size() > i2 + 1) {
987 QByteArray gga = data.mid(i1, i2 - i1 + 3);
988 _query->sendNMEA(gga);
989 }
990 }
991 }
992
993 if (_serialOutFile) {
994 _serialOutFile->write(data);
995 _serialOutFile->flush();
996 }
997 }
998 }
999}
1000
1001void bncGetThread::slotNewNMEAConnection() {
1002 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
1003 emit(newMessage(
1004 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1(),
1005 true));
1006}
1007
1008//
1009////////////////////////////////////////////////////////////////////////////
1010void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
1011 if (_nmeaPortsMap.contains(staID)) {
1012 int nmeaPort = _nmeaPortsMap.value(staID);
1013 QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
1014 while (is.hasNext()) {
1015 QTcpSocket* sock = is.next();
1016 if (sock->localPort() == nmeaPort) {
1017 if (sock->state() == QAbstractSocket::ConnectedState) {
1018 sock->write(str);
1019 } else if (sock->state() != QAbstractSocket::ConnectingState) {
1020 delete sock;
1021 is.remove();
1022 }
1023 }
1024 }
1025 }
1026}
Note: See TracBrowser for help on using the repository browser.