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

Last change on this file since 10681 was 10664, checked in by stuerze, 8 months ago

minor changes regarding serial port

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