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

Last change on this file since 5646 was 5646, checked in by weber, 10 years ago

Ras stream output through TCP/IP port enabled

File size: 24.7 KB
RevLine 
[280]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[280]3//
[464]4// Copyright (C) 2007
[280]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[280]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.
[35]24
25/* -------------------------------------------------------------------------
[93]26 * BKG NTRIP Client
[35]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
[277]41#include <stdlib.h>
[1044]42#include <iomanip>
[1218]43#include <sstream>
[277]44
[35]45#include <QFile>
46#include <QTextStream>
[5524]47#include <QMutex>
[35]48#include <QtNetwork>
[356]49#include <QTime>
[35]50
51#include "bncgetthread.h"
[192]52#include "bnctabledlg.h"
[5070]53#include "bnccore.h"
[352]54#include "bncutils.h"
[423]55#include "bnczerodecoder.h"
[1621]56#include "bncnetqueryv0.h"
[1387]57#include "bncnetqueryv1.h"
58#include "bncnetqueryv2.h"
[1410]59#include "bncnetqueryrtp.h"
[1721]60#include "bncnetqueryudp.h"
[1779]61#include "bncnetqueryudp0.h"
[1753]62#include "bncnetquerys.h"
[1535]63#include "bncsettings.h"
[1558]64#include "latencychecker.h"
[2035]65#include "bncpppclient.h"
[3168]66#include "upload/bncrtnetdecoder.h"
[243]67#include "RTCM/RTCM2Decoder.h"
[297]68#include "RTCM3/RTCM3Decoder.h"
[1310]69#include "GPSS/gpssDecoder.h"
[3504]70#include "GPSS/hassDecoder.h"
[1318]71#include "serial/qextserialport.h"
[35]72
73using namespace std;
74
[1143]75// Constructor 1
[35]76////////////////////////////////////////////////////////////////////////////
[2519]77bncGetThread::bncGetThread(bncRawFile* rawFile) {
[1138]78
[2519]79 _rawFile = rawFile;
80 _format = rawFile->format();
[3548]81 _staID = rawFile->staID();
[2519]82 _rawOutput = false;
[2390]83 _ntripVersion = "N";
84
[1555]85 initialize();
[1138]86}
87
[1143]88// Constructor 2
89////////////////////////////////////////////////////////////////////////////
[278]90bncGetThread::bncGetThread(const QUrl& mountPoint,
[366]91 const QByteArray& format,
92 const QByteArray& latitude,
93 const QByteArray& longitude,
[1353]94 const QByteArray& nmea,
[3527]95 const QByteArray& ntripVersion) {
[2519]96 _rawFile = 0;
[1555]97 _mountPoint = mountPoint;
[3003]98 _staID = mountPoint.path().mid(1).toAscii();
[1555]99 _format = format;
100 _latitude = latitude;
101 _longitude = longitude;
102 _nmea = nmea;
[1353]103 _ntripVersion = ntripVersion;
[1139]104
[2386]105 bncSettings settings;
[5646]106
[2386]107 if (!settings.value("rawOutFile").toString().isEmpty()) {
108 _rawOutput = true;
[3734]109 } else {
110 _rawOutput = false;
[2386]111 }
112
[1139]113 initialize();
[3523]114 initDecoder();
[1139]115}
116
[1555]117// Initialization (common part of the constructor)
[1143]118////////////////////////////////////////////////////////////////////////////
[1139]119void bncGetThread::initialize() {
120
[3528]121 bncSettings settings;
122
[1555]123 setTerminationEnabled(true);
124
125 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[5068]126 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[1555]127
[1525]128 _isToBeDeleted = false;
[1555]129 _query = 0;
130 _nextSleep = 0;
[2035]131 _PPPclient = 0;
[3528]132 _miscMount = settings.value("miscMount").toString();
[3560]133 _decoder = 0;
[255]134
[5646]135 // Miscellaneous output port // Georg
136 // -------------------------
137 _miscPort = settings.value("miscPort").toInt();
138 if (_miscPort != 0) {
139 _miscServer = new QTcpServer;
140 if ( !_miscServer->listen(QHostAddress::Any, _miscPort) ) {
141 emit newMessage("bncgetthread: Cannot listen on Miscellaneous Output Port", true);
142 }
143 connect(_miscServer, SIGNAL(newConnection()), this, SLOT(slotNewMiscConnection()));
144 _miscSockets = new QList<QTcpSocket*>;
145 }
146 else {
147 _miscServer = 0;
148 _miscSockets = 0;
149 }
150
[1555]151 // Serial Port
152 // -----------
[1710]153 _serialNMEA = NO_NMEA;
154 _serialOutFile = 0;
155 _serialPort = 0;
156
[3532]157 if (!_staID.isEmpty() &&
158 settings.value("serialMountPoint").toString() == _staID) {
[1710]159 _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
160 _serialPort->setTimeout(0,100);
161
162 // Baud Rate
163 // ---------
[1330]164 QString hlp = settings.value("serialBaudRate").toString();
165 if (hlp == "110") {
166 _serialPort->setBaudRate(BAUD110);
167 }
168 else if (hlp == "300") {
169 _serialPort->setBaudRate(BAUD300);
170 }
171 else if (hlp == "600") {
172 _serialPort->setBaudRate(BAUD600);
173 }
174 else if (hlp == "1200") {
175 _serialPort->setBaudRate(BAUD1200);
176 }
177 else if (hlp == "2400") {
178 _serialPort->setBaudRate(BAUD2400);
179 }
180 else if (hlp == "4800") {
181 _serialPort->setBaudRate(BAUD4800);
182 }
183 else if (hlp == "9600") {
184 _serialPort->setBaudRate(BAUD9600);
185 }
186 else if (hlp == "19200") {
187 _serialPort->setBaudRate(BAUD19200);
188 }
189 else if (hlp == "38400") {
190 _serialPort->setBaudRate(BAUD38400);
191 }
192 else if (hlp == "57600") {
193 _serialPort->setBaudRate(BAUD57600);
194 }
195 else if (hlp == "115200") {
196 _serialPort->setBaudRate(BAUD115200);
197 }
[1710]198
199 // Parity
200 // ------
[1330]201 hlp = settings.value("serialParity").toString();
202 if (hlp == "NONE") {
203 _serialPort->setParity(PAR_NONE);
204 }
205 else if (hlp == "ODD") {
206 _serialPort->setParity(PAR_ODD);
207 }
208 else if (hlp == "EVEN") {
209 _serialPort->setParity(PAR_EVEN);
210 }
211 else if (hlp == "SPACE") {
212 _serialPort->setParity(PAR_SPACE);
213 }
[1710]214
215 // Data Bits
216 // ---------
[1330]217 hlp = settings.value("serialDataBits").toString();
218 if (hlp == "5") {
219 _serialPort->setDataBits(DATA_5);
220 }
221 else if (hlp == "6") {
222 _serialPort->setDataBits(DATA_6);
223 }
224 else if (hlp == "7") {
225 _serialPort->setDataBits(DATA_7);
226 }
227 else if (hlp == "8") {
228 _serialPort->setDataBits(DATA_8);
229 }
230 hlp = settings.value("serialStopBits").toString();
231 if (hlp == "1") {
232 _serialPort->setStopBits(STOP_1);
233 }
234 else if (hlp == "2") {
235 _serialPort->setStopBits(STOP_2);
236 }
[1710]237
238 // Flow Control
239 // ------------
240 hlp = settings.value("serialFlowControl").toString();
[1711]241 if (hlp == "XONXOFF") {
[1710]242 _serialPort->setFlowControl(FLOW_XONXOFF);
243 }
244 else if (hlp == "HARDWARE") {
245 _serialPort->setFlowControl(FLOW_HARDWARE);
246 }
[1711]247 else {
248 _serialPort->setFlowControl(FLOW_OFF);
249 }
[1710]250
251 // Open Serial Port
252 // ----------------
[1326]253 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
[1331]254 if (!_serialPort->isOpen()) {
255 delete _serialPort;
256 _serialPort = 0;
[1451]257 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
[1331]258 }
[1606]259 connect(_serialPort, SIGNAL(readyRead()),
260 this, SLOT(slotSerialReadyRead()));
261
[1710]262 // Automatic NMEA
263 // --------------
264 if (settings.value("serialAutoNMEA").toString() == "Auto") {
265 _serialNMEA = AUTO_NMEA;
266
267 QString fName = settings.value("serialFileNMEA").toString();
268 if (!fName.isEmpty()) {
269 _serialOutFile = new QFile(fName);
270 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
271 _serialOutFile->open(QIODevice::WriteOnly | QIODevice::Append);
272 }
273 else {
274 _serialOutFile->open(QIODevice::WriteOnly);
275 }
[1634]276 }
[1606]277 }
[1710]278
279 // Manual NMEA
280 // -----------
281 else {
282 _serialNMEA = MANUAL_NMEA;
[1636]283 }
[1318]284 }
285
[3532]286 if (!_staID.isEmpty()) {
287 _latencyChecker = new latencyChecker(_staID);
[2004]288 }
[3532]289 else {
290 _latencyChecker = 0;
291 }
[3523]292}
293
294// Instantiate the decoder
295//////////////////////////////////////////////////////////////////////////////
296t_irc bncGetThread::initDecoder() {
297
[3560]298 _decoder = 0;
299
[1744]300 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
301 _format.indexOf("RTCM 2") != -1 ) {
[1555]302 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
[3560]303 _decoder = new RTCM2Decoder(_staID.data());
[1555]304 }
[1744]305 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
306 _format.indexOf("RTCM 3") != -1 ) {
[1555]307 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
[3558]308 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
[3560]309 _decoder = newDecoder;
[3558]310 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
[1555]311 this, SIGNAL(newMessage(QByteArray,bool)));
312 }
313 else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
314 emit(newMessage(_staID + ": Get Data in GPSS format", true));
[3560]315 _decoder = new gpssDecoder();
[1555]316 }
317 else if (_format.indexOf("ZERO") != -1) {
318 emit(newMessage(_staID + ": Get data in original format", true));
[3560]319 _decoder = new bncZeroDecoder(_staID);
[1555]320 }
[3168]321 else if (_format.indexOf("RTNET") != -1) {
322 emit(newMessage(_staID + ": Get data in RTNet format", true));
[3560]323 _decoder = new bncRtnetDecoder();
[3168]324 }
[3509]325 else if (_format.indexOf("HASS2ASCII") != -1) {
[3517]326 emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
[3560]327 _decoder = new hassDecoder(_staID);
[3504]328 }
[1555]329 else {
330 emit(newMessage(_staID + ": Unknown data format " + _format, true));
331 _isToBeDeleted = true;
[3523]332 return failure;
[1555]333 }
334
[319]335 msleep(100); //sleep 0.1 sec
[3523]336
[3560]337 _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
338 _nmea, _ntripVersion);
339
340 if (_rawFile) {
341 _decodersRaw[_staID] = _decoder;
[3530]342 }
343
[3532]344 // Initialize PPP Client?
345 // ----------------------
346#ifndef MLS_SOFTWARE
347 bncSettings settings;
[4792]348 if (!settings.value("pppSPP").toString().isEmpty() &&
349 settings.value("pppMount").toString() == _staID) {
[3532]350 _PPPclient = new bncPPPclient(_staID);
[5068]351 BNC_CORE->_bncPPPclient = _PPPclient;
[3532]352 qRegisterMetaType<bncTime>("bncTime");
353 connect(_PPPclient, SIGNAL(newPosition(bncTime, double, double, double)),
354 this, SIGNAL(newPosition(bncTime, double, double, double)));
355 connect(_PPPclient, SIGNAL(newNMEAstr(QByteArray)),
356 this, SIGNAL(newNMEAstr(QByteArray)));
357 }
358#endif
359
[3523]360 return success;
[35]361}
362
[3523]363// Current decoder in use
364////////////////////////////////////////////////////////////////////////////
365GPSDecoder* bncGetThread::decoder() {
[3560]366 if (!_rawFile) {
367 return _decoder;
[3523]368 }
369 else {
[3560]370 if (_decodersRaw.contains(_staID) || initDecoder() == success) {
371 return _decodersRaw[_staID];
372 }
[3523]373 }
[3560]374 return 0;
[3523]375}
376
[35]377// Destructor
378////////////////////////////////////////////////////////////////////////////
379bncGetThread::~bncGetThread() {
[1928]380 if (isRunning()) {
381 wait();
382 }
[1527]383 if (_query) {
384 _query->stop();
[1708]385 _query->deleteLater();
[1527]386 }
[2035]387 delete _PPPclient;
[3560]388 if (_rawFile) {
389 QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
390 while (it.hasNext()) {
391 it.next();
392 delete it.value();
393 }
[3523]394 }
[3560]395 else {
396 delete _decoder;
397 }
[2519]398 delete _rawFile;
[1607]399 delete _serialOutFile;
[1328]400 delete _serialPort;
[1557]401 delete _latencyChecker;
[5646]402 delete _miscServer;
403 delete _miscSockets;
[1556]404 emit getThreadFinished(_staID);
[35]405}
406
[1390]407//
408////////////////////////////////////////////////////////////////////////////
409void bncGetThread::terminate() {
[1525]410 _isToBeDeleted = true;
[1559]411 if (!isRunning()) {
412 delete this;
413 }
[1390]414}
415
[136]416// Run
417////////////////////////////////////////////////////////////////////////////
418void bncGetThread::run() {
419
[35]420 while (true) {
[629]421 try {
[1555]422 if (_isToBeDeleted) {
423 QThread::exit(0);
424 this->deleteLater();
425 return;
[629]426 }
[621]427
[1555]428 if (tryReconnect() != success) {
[3532]429 if (_latencyChecker) {
430 _latencyChecker->checkReconnect();
431 }
[1555]432 continue;
[621]433 }
[1555]434
435 // Delete old observations
436 // -----------------------
[3560]437 if (_rawFile) {
438 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
439 while (itDec.hasNext()) {
440 itDec.next();
441 GPSDecoder* decoder = itDec.value();
442 decoder->_obsList.clear();
443 }
[3515]444 }
[3560]445 else {
446 _decoder->_obsList.clear();
447 }
[621]448
[1555]449 // Read Data
450 // ---------
[1377]451 QByteArray data;
452 if (_query) {
453 _query->waitForReadyRead(data);
[1138]454 }
[2519]455 else if (_rawFile) {
[2527]456 data = _rawFile->readChunk();
[3523]457 _format = _rawFile->format();
458 _staID = _rawFile->staID();
[2388]459
[1555]460 if (data.isEmpty()) {
461 cout << "no more data" << endl;
[5068]462 BNC_CORE->stopCombination();
[3541]463 QThread::exit(0);
464 delete this;
[3534]465 ::exit(0);
[1555]466 }
[1138]467 }
[1555]468 qint64 nBytes = data.size();
[1138]469
[1555]470 // Timeout, reconnect
471 // ------------------
472 if (nBytes == 0) {
[3532]473 if (_latencyChecker) {
474 _latencyChecker->checkReconnect();
475 }
[1555]476 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
[2355]477 msleep(10000); //sleep 10 sec, G. Weber
[1555]478 continue;
479 }
480 else {
[567]481 emit newBytes(_staID, nBytes);
[1555]482 }
[567]483
[1555]484 // Output Data
485 // -----------
[2386]486 if (_rawOutput) {
[5068]487 BNC_CORE->writeRawData(data, _staID, _format);
[2386]488 }
[2385]489
[1555]490 if (_serialPort) {
[1633]491 slotSerialReadyRead();
[1555]492 _serialPort->write(data);
493 }
[5646]494
495 // Output into the Miscellaneous socket // Georg
496 // ------------------------------------
497 if (_miscSockets && _miscMount != "ALL") {
498 QMutableListIterator<QTcpSocket*> is(*_miscSockets);
499 while (is.hasNext()) {
500 QTcpSocket* sock = is.next();
501 if (sock->state() == QAbstractSocket::ConnectedState) {
502 if (myMiscWrite(sock, data, nBytes) != nBytes) {
503 delete sock;
504 is.remove();
505 }
506 }
507 else if (sock->state() != QAbstractSocket::ConnectingState) {
508 delete sock;
509 is.remove();
510 }
511 }
512 }
513
[1555]514 // Decode Data
515 // -----------
516 vector<string> errmsg;
[3526]517 if (!decoder()) {
518 _isToBeDeleted = true;
519 continue;
520 }
[3523]521 decoder()->_obsList.clear();
522 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
[1137]523
[1555]524 // Perform various scans and checks
525 // --------------------------------
[3532]526 if (_latencyChecker) {
527 _latencyChecker->checkOutage(irc == success);
528 _latencyChecker->checkObsLatency(decoder()->_obsList);
529 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
530
531 emit newLatency(_staID, _latencyChecker->currentLatency());
532 }
[1567]533
[1555]534 scanRTCM();
[1138]535
[1555]536 // Loop over all observations (observations output)
537 // ------------------------------------------------
[3523]538 QListIterator<t_obs> it(decoder()->_obsList);
[5524]539
540 QList<t_obs> obsListHlp;
541
[1555]542 while (it.hasNext()) {
[2711]543 const t_obs& obs = it.next();
544
[3303]545 QString prn = QString("%1%2").arg(obs.satSys)
546 .arg(obs.satNum, 2, 10, QChar('0'));
547 long iSec = long(floor(obs.GPSWeeks+0.5));
548 long obsTime = obs.GPSWeek * 7*24*3600 + iSec;
549
[1555]550 // Check observation epoch
551 // -----------------------
[3523]552 if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) {
[3303]553 int week;
[1555]554 double sec;
555 currentGPSWeeks(week, sec);
[3304]556 long currTime = week * 7*24*3600 + long(sec);
[1555]557 const double maxDt = 600.0;
[3303]558 if (fabs(currTime - obsTime) > maxDt) {
[2308]559 emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
[1555]560 continue;
[940]561 }
[686]562 }
[1555]563
[3305]564 // Check observations coming twice (e.g. KOUR0 Problem)
565 // ----------------------------------------------------
[3535]566 if (!_rawFile) {
567 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
568 if (it != _prnLastEpo.end()) {
569 long oldTime = it.value();
570 if (obsTime < oldTime) {
571 emit( newMessage(_staID +
572 ": old observation " + prn.toAscii(), false));
573 continue;
574 }
575 else if (obsTime == oldTime) {
576 emit( newMessage(_staID +
577 ": observation coming more than once " + prn.toAscii(), false));
578 continue;
579 }
[3302]580 }
[3535]581 _prnLastEpo[prn] = obsTime;
[3301]582 }
583
[3528]584 decoder()->dumpRinexEpoch(obs, _format);
585
[2030]586 // PPP Client
587 // ----------
[2290]588#ifndef MLS_SOFTWARE
[3535]589 if (_PPPclient && _staID == _PPPclient->staID()) {
[2035]590 _PPPclient->putNewObs(obs);
[2030]591 }
[2290]592#endif
[5524]593 // Save observations
594 // -----------------
595 obsListHlp.append(obs);
596 }
[2030]597
[5524]598 // Emit signal
599 // -----------
600 if (!_isToBeDeleted && obsListHlp.size() > 0) {
601 emit newObs(_staID, obsListHlp);
[249]602 }
[5524]603
[3523]604 decoder()->_obsList.clear();
[35]605 }
[3311]606 catch (Exception& exc) {
607 emit(newMessage(_staID + " " + exc.what(), true));
608 _isToBeDeleted = true;
609 }
[1555]610 catch (...) {
[3311]611 emit(newMessage(_staID + " bncGetThread exception", true));
[1559]612 _isToBeDeleted = true;
[1555]613 }
[35]614 }
615}
616
[136]617// Try Re-Connect
618////////////////////////////////////////////////////////////////////////////
[1555]619t_irc bncGetThread::tryReconnect() {
620
621 // Easy Return
622 // -----------
623 if (_query && _query->status() == bncNetQuery::running) {
624 _nextSleep = 0;
[3560]625 if (_rawFile) {
626 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
627 while (itDec.hasNext()) {
628 itDec.next();
629 GPSDecoder* decoder = itDec.value();
630 decoder->setRinexReconnectFlag(false);
631 }
[1709]632 }
[3560]633 else {
634 _decoder->setRinexReconnectFlag(false);
635 }
[1555]636 return success;
[408]637 }
[1555]638
639 // Start a new query
640 // -----------------
[2519]641 if (!_rawFile) {
[1555]642
[138]643 sleep(_nextSleep);
[1555]644 if (_nextSleep == 0) {
645 _nextSleep = 1;
[138]646 }
647 else {
[1555]648 _nextSleep = 2 * _nextSleep;
[442]649 if (_nextSleep > 256) {
650 _nextSleep = 256;
[152]651 }
[1816]652#ifdef MLS_SOFTWARE
[1817]653 if (_nextSleep > 4) {
654 _nextSleep = 4;
[1816]655 }
656#endif
[138]657 }
[1555]658
659 delete _query;
[1722]660 if (_ntripVersion == "U") {
[1721]661 _query = new bncNetQueryUdp();
662 }
[1722]663 else if (_ntripVersion == "R") {
[1555]664 _query = new bncNetQueryRtp();
665 }
[1744]666 else if (_ntripVersion == "S") {
[1753]667 _query = new bncNetQueryS();
[1744]668 }
[1621]669 else if (_ntripVersion == "N") {
670 _query = new bncNetQueryV0();
671 }
[1779]672 else if (_ntripVersion == "UN") {
673 _query = new bncNetQueryUdp0();
674 }
[1555]675 else if (_ntripVersion == "2") {
[3337]676 _query = new bncNetQueryV2(false);
[1555]677 }
[3334]678 else if (_ntripVersion == "2s") {
[3337]679 _query = new bncNetQueryV2(true);
[3334]680 }
[1555]681 else {
682 _query = new bncNetQueryV1();
683 }
[1710]684 if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
685 QByteArray gga = ggaString(_latitude, _longitude, "100.0");
[1555]686 _query->startRequest(_mountPoint, gga);
687 }
688 else {
689 _query->startRequest(_mountPoint, "");
690 }
691 if (_query->status() != bncNetQuery::running) {
692 return failure;
693 }
[138]694 }
[658]695
[3560]696 if (_rawFile) {
697 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
698 while (itDec.hasNext()) {
699 itDec.next();
700 GPSDecoder* decoder = itDec.value();
701 decoder->setRinexReconnectFlag(false);
702 }
[658]703 }
[3560]704 else {
705 _decoder->setRinexReconnectFlag(false);
706 }
[1555]707
708 return success;
[658]709}
[1044]710
[5646]711// New Connection // Georg
712////////////////////////////////////////////////////////////////////////////
713void bncGetThread::slotNewMiscConnection() {
714 _miscSockets->push_back( _miscServer->nextPendingConnection() );
715 emit( newMessage(QString("New client connection on Miscellaneous Output Port: # %1")
716 .arg(_miscSockets->size()).toAscii(), true) );
717}
718
719// Write buffer // Georg
720////////////////////////////////////////////////////////////////////////////
721int bncGetThread::myMiscWrite(QTcpSocket* sock, const char* buf, int bufLen) {
722 sock->write(buf, bufLen);
723 for (int ii = 1; ii <= 10; ii++) {
724 if (sock->waitForBytesWritten(10)) { // wait 10 ms
725 return bufLen;
726 }
727 }
728 return -1;
729}
730
[1555]731// RTCM scan output
[1044]732//////////////////////////////////////////////////////////////////////////////
[1555]733void bncGetThread::scanRTCM() {
[1044]734
[4476]735 if ( !decoder() ) {
[3558]736 return;
737 }
738
[1555]739 bncSettings settings;
[1574]740 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
741
742 if ( _miscMount == _staID || _miscMount == "ALL" ) {
743
[1575]744 // RTCM message types
745 // ------------------
[4476]746 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
[3523]747 QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
[1574]748 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
749 }
[1044]750
[4476]751 // Check Observation Types
752 // -----------------------
753 for (int ii = 0; ii < decoder()->_obsList.size(); ii++) {
754 t_obs& obs = decoder()->_obsList[ii];
755 QVector<QString>& rnxTypes = _rnxTypes[obs.satSys];
756 bool allFound = true;
757 for (int iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
758 if (obs._measdata[iEntry] != 0.0) {
759 if (rnxTypes.indexOf(obs.rnxStr(iEntry)) == -1) {
760 allFound = false;
761 rnxTypes << obs.rnxStr(iEntry);
762 }
763 }
764 }
765 if (!allFound) {
[4477]766 QString msg;
767 QTextStream str(&msg);
768 str << obs.satSys << " " << rnxTypes.size() << " ";
[4476]769 for (int iType = 0; iType < rnxTypes.size(); iType++) {
[4478]770 str << " " << rnxTypes[iType];
[4476]771 }
[4477]772 emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
[4476]773 }
774 }
775
[1574]776 // RTCMv3 antenna descriptor
777 // -------------------------
[4476]778 for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
[3523]779 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
[1574]780 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
781 }
[1555]782
[1575]783 // RTCM Antenna Coordinates
784 // ------------------------
[4476]785 for (int ii=0; ii < decoder()->_antList.size(); ii++) {
[1574]786 QByteArray antT;
[3523]787 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1574]788 antT = "ARP";
789 }
[3523]790 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1574]791 antT = "APC";
792 }
[1575]793 QByteArray ant1, ant2, ant3;
[3523]794 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
795 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
796 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
[1575]797 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
798 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
799 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
[3595]800 double hh = 0.0;
[3523]801 if (decoder()->_antList[ii].height_f) {
[3595]802 hh = decoder()->_antList[ii].height;
803 QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
[1575]804 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
805 }
[3523]806 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
807 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]808 hh, antT));
[1218]809 }
810 }
[1044]811 }
[1575]812
[1770]813#ifdef MLS_SOFTWARE
[3523]814 for (int ii=0; ii <decoder()->_antList.size(); ii++) {
[1770]815 QByteArray antT;
[3523]816 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
[1770]817 antT = "ARP";
818 }
[3523]819 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
[1770]820 antT = "APC";
821 }
[3595]822 double hh = 0.0;
823 if (decoder()->_antList[ii].height_f) {
824 hh = decoder()->_antList[ii].height;
825 }
[3523]826 emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
827 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
[3595]828 hh, antT));
[1770]829 }
[2356]830
[3523]831 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
832 emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
[2356]833 }
[1770]834#endif
835
[3523]836 decoder()->_typeList.clear();
837 decoder()->_antType.clear();
838 decoder()->_antList.clear();
[1044]839}
[1555]840
[1606]841// Handle Data from Serial Port
842////////////////////////////////////////////////////////////////////////////
843void bncGetThread::slotSerialReadyRead() {
[1607]844 if (_serialPort) {
[1633]845 int nb = _serialPort->bytesAvailable();
846 if (nb > 0) {
847 QByteArray data = _serialPort->read(nb);
[1711]848
849 if (_serialNMEA == AUTO_NMEA) {
[1725]850 int i1 = data.indexOf("$GPGGA");
851 if (i1 != -1) {
852 int i2 = data.indexOf("*", i1);
853 if (i2 != -1 && data.size() > i2 + 1) {
854 QByteArray gga = data.mid(i1,i2-i1+3);
855 _query->sendNMEA(gga);
856 }
857 }
[1711]858 }
859
[1633]860 if (_serialOutFile) {
861 _serialOutFile->write(data);
862 _serialOutFile->flush();
863 }
[1607]864 }
865 }
[1606]866}
[5646]867
Note: See TracBrowser for help on using the repository browser.