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

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

port error messages extended

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 QString message = "bncCaster: Cannot listen on port "
155 + QByteArray::number(nmeaPort) + ": "
156 + _nmeaServer->errorString();
157 emit newMessage(message.toLatin1(), true);
158 } else {
159 connect(_nmeaServer, SIGNAL(newConnection()), this,
160 SLOT(slotNewNMEAConnection()));
161 connect(BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)), this,
162 SLOT(slotNewNMEAstr(QByteArray, QByteArray)));
163 _nmeaSockets = new QList<QTcpSocket*>;
164 _nmeaPortsMap[_staID] = nmeaPort;
165 }
166 } else {
167 _nmeaServer = 0;
168 _nmeaSockets = 0;
169 }
170
171 // Serial Port
172 // -----------
173 _serialNMEA = NO_NMEA;
174 _serialOutFile = 0;
175 _serialPort = 0;
176
177 if (!_staID.isEmpty()
178 && settings.value("serialMountPoint").toString() == _staID) {
179 _serialPort = new QextSerialPort(
180 settings.value("serialPortName").toString());
181 _serialPort->setTimeout(0, 100);
182
183 // Baud Rate
184 // ---------
185 QString hlp = settings.value("serialBaudRate").toString();
186 if (hlp == "110") {
187 _serialPort->setBaudRate(BAUD110);
188 } else if (hlp == "300") {
189 _serialPort->setBaudRate(BAUD300);
190 } else if (hlp == "600") {
191 _serialPort->setBaudRate(BAUD600);
192 } else if (hlp == "1200") {
193 _serialPort->setBaudRate(BAUD1200);
194 } else if (hlp == "2400") {
195 _serialPort->setBaudRate(BAUD2400);
196 } else if (hlp == "4800") {
197 _serialPort->setBaudRate(BAUD4800);
198 } else if (hlp == "9600") {
199 _serialPort->setBaudRate(BAUD9600);
200 } else if (hlp == "19200") {
201 _serialPort->setBaudRate(BAUD19200);
202 } else if (hlp == "38400") {
203 _serialPort->setBaudRate(BAUD38400);
204 } else if (hlp == "57600") {
205 _serialPort->setBaudRate(BAUD57600);
206 } else if (hlp == "115200") {
207 _serialPort->setBaudRate(BAUD115200);
208 }
209
210 // Parity
211 // ------
212 hlp = settings.value("serialParity").toString();
213 if (hlp == "NONE") {
214 _serialPort->setParity(PAR_NONE);
215 } else if (hlp == "ODD") {
216 _serialPort->setParity(PAR_ODD);
217 } else if (hlp == "EVEN") {
218 _serialPort->setParity(PAR_EVEN);
219 } else if (hlp == "SPACE") {
220 _serialPort->setParity(PAR_SPACE);
221 }
222
223 // Data Bits
224 // ---------
225 hlp = settings.value("serialDataBits").toString();
226 if (hlp == "5") {
227 _serialPort->setDataBits(DATA_5);
228 } else if (hlp == "6") {
229 _serialPort->setDataBits(DATA_6);
230 } else if (hlp == "7") {
231 _serialPort->setDataBits(DATA_7);
232 } else if (hlp == "8") {
233 _serialPort->setDataBits(DATA_8);
234 }
235 hlp = settings.value("serialStopBits").toString();
236 if (hlp == "1") {
237 _serialPort->setStopBits(STOP_1);
238 } else if (hlp == "2") {
239 _serialPort->setStopBits(STOP_2);
240 }
241
242 // Flow Control
243 // ------------
244 hlp = settings.value("serialFlowControl").toString();
245 if (hlp == "XONXOFF") {
246 _serialPort->setFlowControl(FLOW_XONXOFF);
247 } else if (hlp == "HARDWARE") {
248 _serialPort->setFlowControl(FLOW_HARDWARE);
249 } else {
250 _serialPort->setFlowControl(FLOW_OFF);
251 }
252
253 // Open Serial Port
254 // ----------------
255 _serialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
256 if (!_serialPort->isOpen()) {
257 delete _serialPort;
258 _serialPort = 0;
259 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
260 }
261 connect(_serialPort, SIGNAL(readyRead()), this,
262 SLOT(slotSerialReadyRead()));
263
264 // Automatic NMEA
265 // --------------
266 QString nmeaMode = settings.value("serialAutoNMEA").toString();
267 if (nmeaMode == "Auto") {
268 _serialNMEA = AUTO_NMEA;
269 QString fName = settings.value("serialFileNMEA").toString();
270 if (!fName.isEmpty()) {
271 _serialOutFile = new QFile(fName);
272 if (Qt::CheckState(settings.value("rnxAppend").toInt())
273 == Qt::Checked) {
274 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
275 } else {
276 _serialOutFile->open(QIODevice::WriteOnly);
277 }
278 }
279 }
280 // Manual NMEA
281 // -----------
282 if ((nmeaMode == "Manual GPGGA") || (nmeaMode == "Manual GNGGA")) {
283 _serialNMEA = MANUAL_NMEA;
284 bncSettings settings;
285 _manualNMEASampl = settings.value("serialManualNMEASampling").toInt();
286 QString hlp = settings.value("serialHeightNMEA").toString();
287 if (hlp.isEmpty()) {
288 hlp = "0.0";
289 }
290 QByteArray _serialHeightNMEA = hlp.toLatin1();
291 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA,
292 nmeaMode);
293 }
294 }
295
296 if (!_staID.isEmpty() && _latencycheck) {
297 _latencyChecker = new latencyChecker(_staID);
298 obs = false;
299 ssrOrb = false;
300 ssrClk = false;
301 ssrOrbClk = false;
302 ssrCbi = false;
303 ssrPbi = false;
304 ssrVtec = false;
305 ssrUra = false;
306 ssrHr = false;
307 _ssrEpoch = 0;
308 } else {
309 _latencyChecker = 0;
310 }
311}
312
313// Instantiate the decoder
314//////////////////////////////////////////////////////////////////////////////
315t_irc bncGetThread::initDecoder() {
316
317 _decoder = 0;
318
319 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1
320 || _format.indexOf("RTCM 2") != -1) {
321 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
322 _decoder = new RTCM2Decoder(_staID.data());
323 } else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1
324 || _format.indexOf("RTCM 3") != -1) {
325 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
326 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
327 _decoder = newDecoder;
328 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
329 this, SIGNAL(newMessage(QByteArray,bool)));
330 } else if (_format.indexOf("ZERO") != -1) {
331 emit(newMessage(_staID + ": Get data in original format", true));
332 _decoder = new bncZeroDecoder(_staID);
333 } else if (_format.indexOf("RTNET") != -1) {
334 emit(newMessage(_staID + ": Get data in RTNet format", true));
335 _decoder = new bncRtnetDecoder();
336 } else {
337 emit(newMessage(_staID + ": Unknown data format " + _format, true));
338 _isToBeDeleted = true;
339 return failure;
340 }
341
342 msleep(100); //sleep 0.1 sec
343
344 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
345 _ntripVersion);
346
347 if (_rawFile) {
348 _decodersRaw[_staID] = _decoder;
349 }
350
351 return success;
352}
353
354// Current decoder in use
355////////////////////////////////////////////////////////////////////////////
356GPSDecoder* bncGetThread::decoder() {
357 if (!_rawFile) {
358 return _decoder;
359 } else {
360 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
361 return _decodersRaw[_staID];
362 }
363 }
364 return 0;
365}
366
367// Destructor
368////////////////////////////////////////////////////////////////////////////
369bncGetThread::~bncGetThread() {
370 if (isRunning()) {
371 wait();
372 }
373 if (_query) {
374 _query->stop();
375 _query->deleteLater();
376 }
377 if (_rawFile) {
378 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
379 while (it.hasNext()) {
380 it.next();
381 delete it.value();
382 }
383 } else {
384 delete _decoder;
385 }
386 delete _rawFile;
387 delete _serialOutFile;
388 delete _serialPort;
389 delete _latencyChecker;
390 emit getThreadFinished(_staID);
391}
392
393//
394////////////////////////////////////////////////////////////////////////////
395void bncGetThread::terminate() {
396 _isToBeDeleted = true;
397
398 if (_nmeaPortsMap.contains(_staID)) {
399 _nmeaPortsMap.remove(_staID);
400 }
401 if (_nmeaServer) {
402 delete _nmeaServer;
403 }
404 if (_nmeaSockets) {
405 delete _nmeaSockets;
406 }
407
408#ifdef BNC_DEBUG
409 if (BNC_CORE->mode() != t_bncCore::interactive) {
410 while (!isFinished()) {
411 wait();
412 }
413 delete this;
414 } else {
415 if (!isRunning()) {
416 delete this;
417 }
418 }
419#else
420 if (!isRunning()) {delete this;}
421#endif
422
423}
424
425// Run
426////////////////////////////////////////////////////////////////////////////
427void bncGetThread::run() {
428
429 while (true) {
430 try {
431 if (_isToBeDeleted) {
432 QThread::exit(0);
433 this->deleteLater();
434 return;
435 }
436
437 if (tryReconnect() != success) {
438 if (_latencyChecker) {
439 _latencyChecker->checkReconnect();
440 }
441 continue;
442 }
443
444 // Delete old observations
445 // -----------------------
446 if (_rawFile) {
447 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
448 while (itDec.hasNext()) {
449 itDec.next();
450 GPSDecoder* decoder = itDec.value();
451 decoder->_obsList.clear();
452 }
453 } else {
454 _decoder->_obsList.clear();
455 }
456
457 // Read Data
458 // ---------
459 QByteArray data;
460 if (_query) {
461 _query->waitForReadyRead(data);
462 } else if (_rawFile) {
463 data = _rawFile->readChunk();
464 _format = _rawFile->format();
465 _staID = _rawFile->staID();
466
467 QCoreApplication::processEvents();
468
469 if (data.isEmpty() || BNC_CORE->sigintReceived) {
470 cout << "no more data or Ctrl-C received" << endl;
471 BNC_CORE->stopCombination();
472 BNC_CORE->stopPPP();
473 sleep(1);
474 ::exit(0);
475 }
476 }
477
478 qint64 nBytes = data.size();
479
480 // Timeout, reconnect
481 // ------------------
482 if (nBytes == 0) {
483 if (_latencyChecker) {
484 _latencyChecker->checkReconnect();
485 }
486 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
487 msleep(10000); //sleep 10 sec, G. Weber
488 continue;
489 } else {
490 emit newBytes(_staID, nBytes);
491 emit newRawData(_staID, data);
492 }
493
494 // Output Data
495 // -----------
496 if (_rawOutput) {
497 BNC_CORE->writeRawData(data, _staID, _format);
498 }
499
500 if (_serialPort) {
501 slotSerialReadyRead();
502 _serialPort->write(data);
503 }
504
505 // Decode Data
506 // -----------
507 vector<string> errmsg;
508 if (!decoder()) {
509 _isToBeDeleted = true;
510 continue;
511 }
512
513 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
514
515 if (irc != success) {
516 continue;
517 }
518 // Perform various scans and checks
519 // --------------------------------
520 if (_latencyChecker) {
521 _latencyChecker->checkOutage(irc);
522 QListIterator<int> it(decoder()->_typeList);
523 _ssrEpoch = static_cast<int>(decoder()->corrGPSEpochTime());
524 if (_ssrEpoch != -1) {
525 if (ssrOrb) {
526 _latencyChecker->checkCorrLatency(_ssrEpoch, 1057);
527 ssrOrb = false;
528 }
529 if (ssrClk) {
530 _latencyChecker->checkCorrLatency(_ssrEpoch, 1058);
531 ssrClk = false;
532 }
533 if (ssrOrbClk) {
534 _latencyChecker->checkCorrLatency(_ssrEpoch, 1060);
535 ssrOrbClk = false;
536 }
537 if (ssrCbi) {
538 _latencyChecker->checkCorrLatency(_ssrEpoch, 1059);
539 ssrCbi = false;
540 }
541 if (ssrPbi) {
542 _latencyChecker->checkCorrLatency(_ssrEpoch, 1265);
543 ssrPbi = false;
544 }
545 if (ssrVtec) {
546 _latencyChecker->checkCorrLatency(_ssrEpoch, 1264);
547 ssrVtec = false;
548 }
549 if (ssrUra) {
550 _latencyChecker->checkCorrLatency(_ssrEpoch, 1061);
551 ssrUra = false;
552 }
553 if (ssrHr) {
554 _latencyChecker->checkCorrLatency(_ssrEpoch, 1062);
555 ssrHr = false;
556 }
557 }
558 while (it.hasNext()) {
559 int rtcmType = it.next();
560 if ((rtcmType >= 1001 && rtcmType <= 1004) || // legacy RTCM OBS
561 (rtcmType >= 1009 && rtcmType <= 1012) || // legacy RTCM OBS
562 (rtcmType >= 1071 && rtcmType <= 1127)) { // MSM RTCM OBS
563 obs = true;
564 } else if ((rtcmType >= 1057 && rtcmType <= 1068) ||
565 (rtcmType >= 1240 && rtcmType <= 1270)) {
566 switch (rtcmType) {
567 case 1057: case 1063: case 1240: case 1246: case 1252: case 1258:
568 ssrOrb = true;
569 break;
570 case 1058: case 1064: case 1241: case 1247: case 1253: case 1259:
571 ssrClk = true;
572 break;
573 case 1060: case 1066: case 1243: case 1249: case 1255: case 1261:
574 ssrOrbClk = true;
575 break;
576 case 1059: case 1065: case 1242: case 1248: case 1254: case 1260:
577 ssrCbi = true;
578 break;
579 case 1265: case 1266: case 1267: case 1268: case 1269: case 1270:
580 ssrPbi = true;
581 break;
582 case 1264:
583 ssrVtec = true;
584 break;
585 case 1061: case 1067: case 1244: case 1250: case 1256: case 1262:
586 ssrUra = true;
587 break;
588 case 1062: case 1068: case 1245: case 1251: case 1257: case 1263:
589 ssrHr = true;
590 break;
591 }
592 }
593 }
594 if (obs) {
595 _latencyChecker->checkObsLatency(decoder()->_obsList);
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.