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 <QFile>
|
---|
46 | #include <QTextStream>
|
---|
47 | #include <QMutex>
|
---|
48 | #include <QtNetwork>
|
---|
49 | #include <QTime>
|
---|
50 |
|
---|
51 | #include "bncgetthread.h"
|
---|
52 | #include "bnctabledlg.h"
|
---|
53 | #include "bnccore.h"
|
---|
54 | #include "bncutils.h"
|
---|
55 | #include "bnczerodecoder.h"
|
---|
56 | #include "bncnetqueryv0.h"
|
---|
57 | #include "bncnetqueryv1.h"
|
---|
58 | #include "bncnetqueryv2.h"
|
---|
59 | #include "bncnetqueryrtp.h"
|
---|
60 | #include "bncnetqueryudp.h"
|
---|
61 | #include "bncnetqueryudp0.h"
|
---|
62 | #include "bncnetquerys.h"
|
---|
63 | #include "bncsettings.h"
|
---|
64 | #include "latencychecker.h"
|
---|
65 | #include "bncpppclient.h"
|
---|
66 | #include "upload/bncrtnetdecoder.h"
|
---|
67 | #include "RTCM/RTCM2Decoder.h"
|
---|
68 | #include "RTCM3/RTCM3Decoder.h"
|
---|
69 | #include "GPSS/gpssDecoder.h"
|
---|
70 | #include "GPSS/hassDecoder.h"
|
---|
71 | #include "serial/qextserialport.h"
|
---|
72 |
|
---|
73 | using namespace std;
|
---|
74 |
|
---|
75 | // Constructor 1
|
---|
76 | ////////////////////////////////////////////////////////////////////////////
|
---|
77 | bncGetThread::bncGetThread(bncRawFile* rawFile) {
|
---|
78 |
|
---|
79 | _rawFile = rawFile;
|
---|
80 | _format = rawFile->format();
|
---|
81 | _staID = rawFile->staID();
|
---|
82 | _rawOutput = false;
|
---|
83 | _ntripVersion = "N";
|
---|
84 |
|
---|
85 | initialize();
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Constructor 2
|
---|
89 | ////////////////////////////////////////////////////////////////////////////
|
---|
90 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
---|
91 | const QByteArray& format,
|
---|
92 | const QByteArray& latitude,
|
---|
93 | const QByteArray& longitude,
|
---|
94 | const QByteArray& nmea,
|
---|
95 | const QByteArray& ntripVersion) {
|
---|
96 | _rawFile = 0;
|
---|
97 | _mountPoint = mountPoint;
|
---|
98 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
99 | _format = format;
|
---|
100 | _latitude = latitude;
|
---|
101 | _longitude = longitude;
|
---|
102 | _nmea = nmea;
|
---|
103 | _ntripVersion = ntripVersion;
|
---|
104 |
|
---|
105 | bncSettings settings;
|
---|
106 |
|
---|
107 | if (!settings.value("rawOutFile").toString().isEmpty()) {
|
---|
108 | _rawOutput = true;
|
---|
109 | } else {
|
---|
110 | _rawOutput = false;
|
---|
111 | }
|
---|
112 |
|
---|
113 | initialize();
|
---|
114 | initDecoder();
|
---|
115 | }
|
---|
116 |
|
---|
117 | // Initialization (common part of the constructor)
|
---|
118 | ////////////////////////////////////////////////////////////////////////////
|
---|
119 | void bncGetThread::initialize() {
|
---|
120 |
|
---|
121 | bncSettings settings;
|
---|
122 |
|
---|
123 | setTerminationEnabled(true);
|
---|
124 |
|
---|
125 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
126 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
127 |
|
---|
128 | _isToBeDeleted = false;
|
---|
129 | _query = 0;
|
---|
130 | _nextSleep = 0;
|
---|
131 | _PPPclient = 0;
|
---|
132 | _miscMount = settings.value("miscMount").toString();
|
---|
133 | _decoder = 0;
|
---|
134 |
|
---|
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 |
|
---|
151 | // Serial Port
|
---|
152 | // -----------
|
---|
153 | _serialNMEA = NO_NMEA;
|
---|
154 | _serialOutFile = 0;
|
---|
155 | _serialPort = 0;
|
---|
156 |
|
---|
157 | if (!_staID.isEmpty() &&
|
---|
158 | settings.value("serialMountPoint").toString() == _staID) {
|
---|
159 | _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
|
---|
160 | _serialPort->setTimeout(0,100);
|
---|
161 |
|
---|
162 | // Baud Rate
|
---|
163 | // ---------
|
---|
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 | }
|
---|
198 |
|
---|
199 | // Parity
|
---|
200 | // ------
|
---|
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 | }
|
---|
214 |
|
---|
215 | // Data Bits
|
---|
216 | // ---------
|
---|
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 | }
|
---|
237 |
|
---|
238 | // Flow Control
|
---|
239 | // ------------
|
---|
240 | hlp = settings.value("serialFlowControl").toString();
|
---|
241 | if (hlp == "XONXOFF") {
|
---|
242 | _serialPort->setFlowControl(FLOW_XONXOFF);
|
---|
243 | }
|
---|
244 | else if (hlp == "HARDWARE") {
|
---|
245 | _serialPort->setFlowControl(FLOW_HARDWARE);
|
---|
246 | }
|
---|
247 | else {
|
---|
248 | _serialPort->setFlowControl(FLOW_OFF);
|
---|
249 | }
|
---|
250 |
|
---|
251 | // Open Serial Port
|
---|
252 | // ----------------
|
---|
253 | _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
|
---|
254 | if (!_serialPort->isOpen()) {
|
---|
255 | delete _serialPort;
|
---|
256 | _serialPort = 0;
|
---|
257 | emit(newMessage((_staID + ": Cannot open serial port\n"), true));
|
---|
258 | }
|
---|
259 | connect(_serialPort, SIGNAL(readyRead()),
|
---|
260 | this, SLOT(slotSerialReadyRead()));
|
---|
261 |
|
---|
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 | }
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | // Manual NMEA
|
---|
280 | // -----------
|
---|
281 | else {
|
---|
282 | _serialNMEA = MANUAL_NMEA;
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | if (!_staID.isEmpty()) {
|
---|
287 | _latencyChecker = new latencyChecker(_staID);
|
---|
288 | }
|
---|
289 | else {
|
---|
290 | _latencyChecker = 0;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | // Instantiate the decoder
|
---|
295 | //////////////////////////////////////////////////////////////////////////////
|
---|
296 | t_irc bncGetThread::initDecoder() {
|
---|
297 |
|
---|
298 | _decoder = 0;
|
---|
299 |
|
---|
300 | if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
|
---|
301 | _format.indexOf("RTCM 2") != -1 ) {
|
---|
302 | emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
|
---|
303 | _decoder = new RTCM2Decoder(_staID.data());
|
---|
304 | }
|
---|
305 | else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
|
---|
306 | _format.indexOf("RTCM 3") != -1 ) {
|
---|
307 | emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
|
---|
308 | RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
|
---|
309 | _decoder = newDecoder;
|
---|
310 | connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
|
---|
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));
|
---|
315 | _decoder = new gpssDecoder();
|
---|
316 | }
|
---|
317 | else if (_format.indexOf("ZERO") != -1) {
|
---|
318 | emit(newMessage(_staID + ": Get data in original format", true));
|
---|
319 | _decoder = new bncZeroDecoder(_staID);
|
---|
320 | }
|
---|
321 | else if (_format.indexOf("RTNET") != -1) {
|
---|
322 | emit(newMessage(_staID + ": Get data in RTNet format", true));
|
---|
323 | _decoder = new bncRtnetDecoder();
|
---|
324 | }
|
---|
325 | else if (_format.indexOf("HASS2ASCII") != -1) {
|
---|
326 | emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
|
---|
327 | _decoder = new hassDecoder(_staID);
|
---|
328 | }
|
---|
329 | else {
|
---|
330 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
---|
331 | _isToBeDeleted = true;
|
---|
332 | return failure;
|
---|
333 | }
|
---|
334 |
|
---|
335 | msleep(100); //sleep 0.1 sec
|
---|
336 |
|
---|
337 | _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude,
|
---|
338 | _nmea, _ntripVersion);
|
---|
339 |
|
---|
340 | if (_rawFile) {
|
---|
341 | _decodersRaw[_staID] = _decoder;
|
---|
342 | }
|
---|
343 |
|
---|
344 | // Initialize PPP Client?
|
---|
345 | // ----------------------
|
---|
346 | #ifndef MLS_SOFTWARE
|
---|
347 | bncSettings settings;
|
---|
348 | if (!settings.value("pppSPP").toString().isEmpty() &&
|
---|
349 | settings.value("pppMount").toString() == _staID) {
|
---|
350 | _PPPclient = new bncPPPclient(_staID);
|
---|
351 | BNC_CORE->_bncPPPclient = _PPPclient;
|
---|
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 |
|
---|
360 | return success;
|
---|
361 | }
|
---|
362 |
|
---|
363 | // Current decoder in use
|
---|
364 | ////////////////////////////////////////////////////////////////////////////
|
---|
365 | GPSDecoder* bncGetThread::decoder() {
|
---|
366 | if (!_rawFile) {
|
---|
367 | return _decoder;
|
---|
368 | }
|
---|
369 | else {
|
---|
370 | if (_decodersRaw.contains(_staID) || initDecoder() == success) {
|
---|
371 | return _decodersRaw[_staID];
|
---|
372 | }
|
---|
373 | }
|
---|
374 | return 0;
|
---|
375 | }
|
---|
376 |
|
---|
377 | // Destructor
|
---|
378 | ////////////////////////////////////////////////////////////////////////////
|
---|
379 | bncGetThread::~bncGetThread() {
|
---|
380 | if (isRunning()) {
|
---|
381 | wait();
|
---|
382 | }
|
---|
383 | if (_query) {
|
---|
384 | _query->stop();
|
---|
385 | _query->deleteLater();
|
---|
386 | }
|
---|
387 | delete _PPPclient;
|
---|
388 | if (_rawFile) {
|
---|
389 | QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
|
---|
390 | while (it.hasNext()) {
|
---|
391 | it.next();
|
---|
392 | delete it.value();
|
---|
393 | }
|
---|
394 | }
|
---|
395 | else {
|
---|
396 | delete _decoder;
|
---|
397 | }
|
---|
398 | delete _rawFile;
|
---|
399 | delete _serialOutFile;
|
---|
400 | delete _serialPort;
|
---|
401 | delete _latencyChecker;
|
---|
402 | delete _miscServer;
|
---|
403 | delete _miscSockets;
|
---|
404 | emit getThreadFinished(_staID);
|
---|
405 | }
|
---|
406 |
|
---|
407 | //
|
---|
408 | ////////////////////////////////////////////////////////////////////////////
|
---|
409 | void bncGetThread::terminate() {
|
---|
410 | _isToBeDeleted = true;
|
---|
411 | if (!isRunning()) {
|
---|
412 | delete this;
|
---|
413 | }
|
---|
414 | }
|
---|
415 |
|
---|
416 | // Run
|
---|
417 | ////////////////////////////////////////////////////////////////////////////
|
---|
418 | void bncGetThread::run() {
|
---|
419 |
|
---|
420 | while (true) {
|
---|
421 | try {
|
---|
422 | if (_isToBeDeleted) {
|
---|
423 | QThread::exit(0);
|
---|
424 | this->deleteLater();
|
---|
425 | return;
|
---|
426 | }
|
---|
427 |
|
---|
428 | if (tryReconnect() != success) {
|
---|
429 | if (_latencyChecker) {
|
---|
430 | _latencyChecker->checkReconnect();
|
---|
431 | }
|
---|
432 | continue;
|
---|
433 | }
|
---|
434 |
|
---|
435 | // Delete old observations
|
---|
436 | // -----------------------
|
---|
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 | }
|
---|
444 | }
|
---|
445 | else {
|
---|
446 | _decoder->_obsList.clear();
|
---|
447 | }
|
---|
448 |
|
---|
449 | // Read Data
|
---|
450 | // ---------
|
---|
451 | QByteArray data;
|
---|
452 | if (_query) {
|
---|
453 | _query->waitForReadyRead(data);
|
---|
454 | }
|
---|
455 | else if (_rawFile) {
|
---|
456 | data = _rawFile->readChunk();
|
---|
457 | _format = _rawFile->format();
|
---|
458 | _staID = _rawFile->staID();
|
---|
459 |
|
---|
460 | if (data.isEmpty()) {
|
---|
461 | cout << "no more data" << endl;
|
---|
462 | BNC_CORE->stopCombination();
|
---|
463 | QThread::exit(0);
|
---|
464 | delete this;
|
---|
465 | ::exit(0);
|
---|
466 | }
|
---|
467 | }
|
---|
468 | qint64 nBytes = data.size();
|
---|
469 |
|
---|
470 | // Timeout, reconnect
|
---|
471 | // ------------------
|
---|
472 | if (nBytes == 0) {
|
---|
473 | if (_latencyChecker) {
|
---|
474 | _latencyChecker->checkReconnect();
|
---|
475 | }
|
---|
476 | emit(newMessage(_staID + ": Data timeout, reconnecting", true));
|
---|
477 | msleep(10000); //sleep 10 sec, G. Weber
|
---|
478 | continue;
|
---|
479 | }
|
---|
480 | else {
|
---|
481 | emit newBytes(_staID, nBytes);
|
---|
482 | }
|
---|
483 |
|
---|
484 | // Output Data
|
---|
485 | // -----------
|
---|
486 | if (_rawOutput) {
|
---|
487 | BNC_CORE->writeRawData(data, _staID, _format);
|
---|
488 | }
|
---|
489 |
|
---|
490 | if (_serialPort) {
|
---|
491 | slotSerialReadyRead();
|
---|
492 | _serialPort->write(data);
|
---|
493 | }
|
---|
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 |
|
---|
514 | // Decode Data
|
---|
515 | // -----------
|
---|
516 | vector<string> errmsg;
|
---|
517 | if (!decoder()) {
|
---|
518 | _isToBeDeleted = true;
|
---|
519 | continue;
|
---|
520 | }
|
---|
521 | decoder()->_obsList.clear();
|
---|
522 | t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
|
---|
523 |
|
---|
524 | // Perform various scans and checks
|
---|
525 | // --------------------------------
|
---|
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 | }
|
---|
533 |
|
---|
534 | scanRTCM();
|
---|
535 |
|
---|
536 | // Loop over all observations (observations output)
|
---|
537 | // ------------------------------------------------
|
---|
538 | QListIterator<t_obs> it(decoder()->_obsList);
|
---|
539 |
|
---|
540 | QList<t_obs> obsListHlp;
|
---|
541 |
|
---|
542 | while (it.hasNext()) {
|
---|
543 | const t_obs& obs = it.next();
|
---|
544 |
|
---|
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 |
|
---|
550 | // Check observation epoch
|
---|
551 | // -----------------------
|
---|
552 | if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) {
|
---|
553 | int week;
|
---|
554 | double sec;
|
---|
555 | currentGPSWeeks(week, sec);
|
---|
556 | long currTime = week * 7*24*3600 + long(sec);
|
---|
557 | const double maxDt = 600.0;
|
---|
558 | if (fabs(currTime - obsTime) > maxDt) {
|
---|
559 | emit( newMessage(_staID + ": Wrong observation epoch(s)", false) );
|
---|
560 | continue;
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | // Check observations coming twice (e.g. KOUR0 Problem)
|
---|
565 | // ----------------------------------------------------
|
---|
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 | }
|
---|
580 | }
|
---|
581 | _prnLastEpo[prn] = obsTime;
|
---|
582 | }
|
---|
583 |
|
---|
584 | decoder()->dumpRinexEpoch(obs, _format);
|
---|
585 |
|
---|
586 | // PPP Client
|
---|
587 | // ----------
|
---|
588 | #ifndef MLS_SOFTWARE
|
---|
589 | if (_PPPclient && _staID == _PPPclient->staID()) {
|
---|
590 | _PPPclient->putNewObs(obs);
|
---|
591 | }
|
---|
592 | #endif
|
---|
593 | // Save observations
|
---|
594 | // -----------------
|
---|
595 | obsListHlp.append(obs);
|
---|
596 | }
|
---|
597 |
|
---|
598 | // Emit signal
|
---|
599 | // -----------
|
---|
600 | if (!_isToBeDeleted && obsListHlp.size() > 0) {
|
---|
601 | emit newObs(_staID, obsListHlp);
|
---|
602 | }
|
---|
603 |
|
---|
604 | decoder()->_obsList.clear();
|
---|
605 | }
|
---|
606 | catch (Exception& exc) {
|
---|
607 | emit(newMessage(_staID + " " + exc.what(), true));
|
---|
608 | _isToBeDeleted = true;
|
---|
609 | }
|
---|
610 | catch (...) {
|
---|
611 | emit(newMessage(_staID + " bncGetThread exception", true));
|
---|
612 | _isToBeDeleted = true;
|
---|
613 | }
|
---|
614 | }
|
---|
615 | }
|
---|
616 |
|
---|
617 | // Try Re-Connect
|
---|
618 | ////////////////////////////////////////////////////////////////////////////
|
---|
619 | t_irc bncGetThread::tryReconnect() {
|
---|
620 |
|
---|
621 | // Easy Return
|
---|
622 | // -----------
|
---|
623 | if (_query && _query->status() == bncNetQuery::running) {
|
---|
624 | _nextSleep = 0;
|
---|
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 | }
|
---|
632 | }
|
---|
633 | else {
|
---|
634 | _decoder->setRinexReconnectFlag(false);
|
---|
635 | }
|
---|
636 | return success;
|
---|
637 | }
|
---|
638 |
|
---|
639 | // Start a new query
|
---|
640 | // -----------------
|
---|
641 | if (!_rawFile) {
|
---|
642 |
|
---|
643 | sleep(_nextSleep);
|
---|
644 | if (_nextSleep == 0) {
|
---|
645 | _nextSleep = 1;
|
---|
646 | }
|
---|
647 | else {
|
---|
648 | _nextSleep = 2 * _nextSleep;
|
---|
649 | if (_nextSleep > 256) {
|
---|
650 | _nextSleep = 256;
|
---|
651 | }
|
---|
652 | #ifdef MLS_SOFTWARE
|
---|
653 | if (_nextSleep > 4) {
|
---|
654 | _nextSleep = 4;
|
---|
655 | }
|
---|
656 | #endif
|
---|
657 | }
|
---|
658 |
|
---|
659 | delete _query;
|
---|
660 | if (_ntripVersion == "U") {
|
---|
661 | _query = new bncNetQueryUdp();
|
---|
662 | }
|
---|
663 | else if (_ntripVersion == "R") {
|
---|
664 | _query = new bncNetQueryRtp();
|
---|
665 | }
|
---|
666 | else if (_ntripVersion == "S") {
|
---|
667 | _query = new bncNetQueryS();
|
---|
668 | }
|
---|
669 | else if (_ntripVersion == "N") {
|
---|
670 | _query = new bncNetQueryV0();
|
---|
671 | }
|
---|
672 | else if (_ntripVersion == "UN") {
|
---|
673 | _query = new bncNetQueryUdp0();
|
---|
674 | }
|
---|
675 | else if (_ntripVersion == "2") {
|
---|
676 | _query = new bncNetQueryV2(false);
|
---|
677 | }
|
---|
678 | else if (_ntripVersion == "2s") {
|
---|
679 | _query = new bncNetQueryV2(true);
|
---|
680 | }
|
---|
681 | else {
|
---|
682 | _query = new bncNetQueryV1();
|
---|
683 | }
|
---|
684 | if (_nmea == "yes" && _serialNMEA != AUTO_NMEA) {
|
---|
685 | QByteArray gga = ggaString(_latitude, _longitude, "100.0");
|
---|
686 | _query->startRequest(_mountPoint, gga);
|
---|
687 | }
|
---|
688 | else {
|
---|
689 | _query->startRequest(_mountPoint, "");
|
---|
690 | }
|
---|
691 | if (_query->status() != bncNetQuery::running) {
|
---|
692 | return failure;
|
---|
693 | }
|
---|
694 | }
|
---|
695 |
|
---|
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 | }
|
---|
703 | }
|
---|
704 | else {
|
---|
705 | _decoder->setRinexReconnectFlag(false);
|
---|
706 | }
|
---|
707 |
|
---|
708 | return success;
|
---|
709 | }
|
---|
710 |
|
---|
711 | // New Connection // Georg
|
---|
712 | ////////////////////////////////////////////////////////////////////////////
|
---|
713 | void 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 | ////////////////////////////////////////////////////////////////////////////
|
---|
721 | int 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 |
|
---|
731 | // RTCM scan output
|
---|
732 | //////////////////////////////////////////////////////////////////////////////
|
---|
733 | void bncGetThread::scanRTCM() {
|
---|
734 |
|
---|
735 | if ( !decoder() ) {
|
---|
736 | return;
|
---|
737 | }
|
---|
738 |
|
---|
739 | bncSettings settings;
|
---|
740 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
|
---|
741 |
|
---|
742 | if ( _miscMount == _staID || _miscMount == "ALL" ) {
|
---|
743 |
|
---|
744 | // RTCM message types
|
---|
745 | // ------------------
|
---|
746 | for (int ii = 0; ii < decoder()->_typeList.size(); ii++) {
|
---|
747 | QString type = QString("%1 ").arg(decoder()->_typeList[ii]);
|
---|
748 | emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
|
---|
749 | }
|
---|
750 |
|
---|
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) {
|
---|
766 | QString msg;
|
---|
767 | QTextStream str(&msg);
|
---|
768 | str << obs.satSys << " " << rnxTypes.size() << " ";
|
---|
769 | for (int iType = 0; iType < rnxTypes.size(); iType++) {
|
---|
770 | str << " " << rnxTypes[iType];
|
---|
771 | }
|
---|
772 | emit(newMessage(_staID + ": Observation Types: " + msg.toAscii(), true));
|
---|
773 | }
|
---|
774 | }
|
---|
775 |
|
---|
776 | // RTCMv3 antenna descriptor
|
---|
777 | // -------------------------
|
---|
778 | for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
|
---|
779 | QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]);
|
---|
780 | emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
|
---|
781 | }
|
---|
782 |
|
---|
783 | // RTCM Antenna Coordinates
|
---|
784 | // ------------------------
|
---|
785 | for (int ii=0; ii < decoder()->_antList.size(); ii++) {
|
---|
786 | QByteArray antT;
|
---|
787 | if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
788 | antT = "ARP";
|
---|
789 | }
|
---|
790 | else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
791 | antT = "APC";
|
---|
792 | }
|
---|
793 | QByteArray ant1, ant2, ant3;
|
---|
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();
|
---|
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));
|
---|
800 | double hh = 0.0;
|
---|
801 | if (decoder()->_antList[ii].height_f) {
|
---|
802 | hh = decoder()->_antList[ii].height;
|
---|
803 | QByteArray ant4 = QString("%1 ").arg(hh,0,'f',4).toAscii();
|
---|
804 | emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
|
---|
805 | }
|
---|
806 | emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
|
---|
807 | decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
|
---|
808 | hh, antT));
|
---|
809 | }
|
---|
810 | }
|
---|
811 | }
|
---|
812 |
|
---|
813 | #ifdef MLS_SOFTWARE
|
---|
814 | for (int ii=0; ii <decoder()->_antList.size(); ii++) {
|
---|
815 | QByteArray antT;
|
---|
816 | if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
|
---|
817 | antT = "ARP";
|
---|
818 | }
|
---|
819 | else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
|
---|
820 | antT = "APC";
|
---|
821 | }
|
---|
822 | double hh = 0.0;
|
---|
823 | if (decoder()->_antList[ii].height_f) {
|
---|
824 | hh = decoder()->_antList[ii].height;
|
---|
825 | }
|
---|
826 | emit(newAntCrd(_staID, decoder()->_antList[ii].xx,
|
---|
827 | decoder()->_antList[ii].yy, decoder()->_antList[ii].zz,
|
---|
828 | hh, antT));
|
---|
829 | }
|
---|
830 |
|
---|
831 | for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
|
---|
832 | emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
|
---|
833 | }
|
---|
834 | #endif
|
---|
835 |
|
---|
836 | decoder()->_typeList.clear();
|
---|
837 | decoder()->_antType.clear();
|
---|
838 | decoder()->_antList.clear();
|
---|
839 | }
|
---|
840 |
|
---|
841 | // Handle Data from Serial Port
|
---|
842 | ////////////////////////////////////////////////////////////////////////////
|
---|
843 | void bncGetThread::slotSerialReadyRead() {
|
---|
844 | if (_serialPort) {
|
---|
845 | int nb = _serialPort->bytesAvailable();
|
---|
846 | if (nb > 0) {
|
---|
847 | QByteArray data = _serialPort->read(nb);
|
---|
848 |
|
---|
849 | if (_serialNMEA == AUTO_NMEA) {
|
---|
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 | }
|
---|
858 | }
|
---|
859 |
|
---|
860 | if (_serialOutFile) {
|
---|
861 | _serialOutFile->write(data);
|
---|
862 | _serialOutFile->flush();
|
---|
863 | }
|
---|
864 | }
|
---|
865 | }
|
---|
866 | }
|
---|
867 |
|
---|