source: ntrip/trunk/BNC/bncgetthread.cpp@ 1367

Last change on this file since 1367 was 1367, checked in by mervart, 15 years ago

* empty log message *

File size: 32.8 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncGetThread
30 *
31 * Purpose: Thread that retrieves data from NTRIP caster
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Dec-2005
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <stdlib.h>
42#include <iomanip>
43#include <sstream>
44
45#include <QFile>
46#include <QTextStream>
47#include <QtNetwork>
48#include <QTime>
49
50#include "bncgetthread.h"
51#include "bnctabledlg.h"
52#include "bncapp.h"
53#include "bncutils.h"
54#include "bncrinex.h"
55#include "bnczerodecoder.h"
56#include "bncsocket.h"
57
58#include "RTCM/RTCM2Decoder.h"
59#include "RTCM3/RTCM3Decoder.h"
60#include "RTIGS/RTIGSDecoder.h"
61#include "GPSS/gpssDecoder.h"
62#include "serial/qextserialport.h"
63
64using namespace std;
65
66// Constructor 1
67////////////////////////////////////////////////////////////////////////////
68bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
69 const QByteArray& format) {
70
71 _format = format;
72
73 int iSep = rawInpFileName.lastIndexOf(QDir::separator());
74 _staID = rawInpFileName.mid(iSep+1,4);
75
76 initialize();
77
78 _inspSegm = 0;
79
80 _rawInpFile = new QFile(rawInpFileName);
81 _rawInpFile->open(QIODevice::ReadOnly);
82
83 if (!_rnx) {
84 cerr << "no RINEX path specified" << endl;
85 ::exit(0);
86 }
87}
88
89// Constructor 2
90////////////////////////////////////////////////////////////////////////////
91bncGetThread::bncGetThread(const QUrl& mountPoint,
92 const QByteArray& format,
93 const QByteArray& latitude,
94 const QByteArray& longitude,
95 const QByteArray& nmea,
96 const QByteArray& ntripVersion, int iMount) {
97
98 setTerminationEnabled(true);
99
100 _mountPoint = mountPoint;
101 _staID = mountPoint.path().mid(1).toAscii();
102 _format = format;
103 _latitude = latitude;
104 _longitude = longitude;
105 _nmea = nmea;
106 _ntripVersion = ntripVersion;
107 _iMount = iMount; // index in mountpoints array
108
109 initialize();
110}
111
112// Initialization
113////////////////////////////////////////////////////////////////////////////
114void bncGetThread::initialize() {
115
116
117 bncApp* app = (bncApp*) qApp;
118 app->connect(this, SIGNAL(newMessage(QByteArray,bool)),
119 app, SLOT(slotMessage(const QByteArray,bool)));
120
121 _decoder = 0;
122 _socket = 0;
123 _timeOut = 20*1000; // 20 seconds
124 _nextSleep = 1; // 1 second
125 _rawInpFile = 0;
126 _rawOutFile = 0;
127 _staID_orig = _staID;
128
129 // Check name conflict
130 // -------------------
131 QSettings settings;
132 QListIterator<QString> it(settings.value("mountPoints").toStringList());
133 int num = 0;
134 int ind = -1;
135 while (it.hasNext()) {
136 ++ind;
137 QStringList hlp = it.next().split(" ");
138 if (hlp.size() <= 1) continue;
139 QUrl url(hlp[0]);
140 if (_mountPoint.path() == url.path()) {
141 if (_iMount > ind || _iMount < 0) {
142 ++num;
143 }
144 }
145 }
146
147 if (num > 0) {
148 _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
149 }
150
151 // Notice threshold
152 // ----------------
153 _inspSegm = 50;
154 if ( settings.value("obsRate").toString().isEmpty() ) { _inspSegm = 0; }
155 if ( settings.value("obsRate").toString().indexOf("5 Hz") != -1 ) { _inspSegm = 2; }
156 if ( settings.value("obsRate").toString().indexOf("1 Hz") != -1 ) { _inspSegm = 10; }
157 if ( settings.value("obsRate").toString().indexOf("0.5 Hz") != -1 ) { _inspSegm = 20; }
158 if ( settings.value("obsRate").toString().indexOf("0.2 Hz") != -1 ) { _inspSegm = 40; }
159 if ( settings.value("obsRate").toString().indexOf("0.1 Hz") != -1 ) { _inspSegm = 50; }
160 _adviseFail = settings.value("adviseFail").toInt();
161 _adviseReco = settings.value("adviseReco").toInt();
162 _makePause = false;
163 if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {_makePause = true; }
164 _adviseScript = settings.value("adviseScript").toString();
165 expandEnvVar(_adviseScript);
166
167 // Latency interval/average
168 // ------------------------
169 _perfIntr = 86400;
170 if ( settings.value("perfIntr").toString().isEmpty() ) { _perfIntr = 0; }
171 if ( settings.value("perfIntr").toString().indexOf("1 min") != -1 ) { _perfIntr = 60; }
172 if ( settings.value("perfIntr").toString().indexOf("5 min") != -1 ) { _perfIntr = 300; }
173 if ( settings.value("perfIntr").toString().indexOf("15 min") != -1 ) { _perfIntr = 900; }
174 if ( settings.value("perfIntr").toString().indexOf("1 hour") != -1 ) { _perfIntr = 3600; }
175 if ( settings.value("perfIntr").toString().indexOf("6 hours") != -1 ) { _perfIntr = 21600; }
176 if ( settings.value("perfIntr").toString().indexOf("1 day") != -1 ) { _perfIntr = 86400; }
177
178 // RTCM message types
179 // ------------------
180 _checkMountPoint = settings.value("miscMount").toString();
181
182 // RINEX writer
183 // ------------
184 _samplingRate = settings.value("rnxSampl").toInt();
185 if ( settings.value("rnxPath").toString().isEmpty() ) {
186 _rnx = 0;
187 }
188 else {
189 _rnx = new bncRinex(_staID, _mountPoint, _format, _latitude,
190 _longitude, _nmea, _ntripVersion);
191 }
192 _rnx_set_position = false;
193
194 connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
195 this, SLOT(slotNewEphGPS(gpsephemeris)));
196
197 if (settings.value("serialMountPoint").toString() == _staID) {
198 _serialPort = new QextSerialPort(
199 settings.value("serialPortName").toString() );
200 QString hlp = settings.value("serialBaudRate").toString();
201 if (hlp == "110") {
202 _serialPort->setBaudRate(BAUD110);
203 }
204 else if (hlp == "300") {
205 _serialPort->setBaudRate(BAUD300);
206 }
207 else if (hlp == "600") {
208 _serialPort->setBaudRate(BAUD600);
209 }
210 else if (hlp == "1200") {
211 _serialPort->setBaudRate(BAUD1200);
212 }
213 else if (hlp == "2400") {
214 _serialPort->setBaudRate(BAUD2400);
215 }
216 else if (hlp == "4800") {
217 _serialPort->setBaudRate(BAUD4800);
218 }
219 else if (hlp == "9600") {
220 _serialPort->setBaudRate(BAUD9600);
221 }
222 else if (hlp == "19200") {
223 _serialPort->setBaudRate(BAUD19200);
224 }
225 else if (hlp == "38400") {
226 _serialPort->setBaudRate(BAUD38400);
227 }
228 else if (hlp == "57600") {
229 _serialPort->setBaudRate(BAUD57600);
230 }
231 else if (hlp == "115200") {
232 _serialPort->setBaudRate(BAUD115200);
233 }
234 hlp = settings.value("serialParity").toString();
235 if (hlp == "NONE") {
236 _serialPort->setParity(PAR_NONE);
237 }
238 else if (hlp == "ODD") {
239 _serialPort->setParity(PAR_ODD);
240 }
241 else if (hlp == "EVEN") {
242 _serialPort->setParity(PAR_EVEN);
243 }
244 else if (hlp == "SPACE") {
245 _serialPort->setParity(PAR_SPACE);
246 }
247 hlp = settings.value("serialDataBits").toString();
248 if (hlp == "5") {
249 _serialPort->setDataBits(DATA_5);
250 }
251 else if (hlp == "6") {
252 _serialPort->setDataBits(DATA_6);
253 }
254 else if (hlp == "7") {
255 _serialPort->setDataBits(DATA_7);
256 }
257 else if (hlp == "8") {
258 _serialPort->setDataBits(DATA_8);
259 }
260 hlp = settings.value("serialStopBits").toString();
261 if (hlp == "1") {
262 _serialPort->setStopBits(STOP_1);
263 }
264 else if (hlp == "2") {
265 _serialPort->setStopBits(STOP_2);
266 }
267 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
268 if (!_serialPort->isOpen()) {
269 delete _serialPort;
270 _serialPort = 0;
271 emit(newMessage((_staID + ": Cannot Open Serial Port\n"), true));
272 }
273 }
274 else {
275 _serialPort = 0;
276 }
277
278 // Raw Output
279 // ----------
280 // QByteArray rawOutFileName = "./" + _staID + ".raw";
281 // _rawOutFile = new QFile(rawOutFileName);
282 // _rawOutFile->open(QIODevice::WriteOnly);
283
284 msleep(100); //sleep 0.1 sec
285}
286
287// Destructor
288////////////////////////////////////////////////////////////////////////////
289bncGetThread::~bncGetThread() {
290 if (_socket) {
291 _socket->close();
292#if QT_VERSION == 0x040203
293 delete _socket;
294#else
295 _socket->deleteLater();
296#endif
297 }
298 delete _decoder;
299 delete _rnx;
300 delete _rawInpFile;
301 delete _rawOutFile;
302 delete _serialPort;
303}
304
305// Init Run
306////////////////////////////////////////////////////////////////////////////
307t_irc bncGetThread::initRun() {
308
309 if (!_rawInpFile) {
310
311 // Initialize Socket
312 // -----------------
313 QString msg;
314 delete _socket;
315 _socket = new bncSocket;
316 if (_socket->request(_mountPoint, _latitude, _longitude,
317 _nmea, _ntripVersion, _timeOut, msg) != success) {
318 delete _socket;
319 _socket = 0;
320 return failure;
321 }
322
323 // Read Caster Response
324 // --------------------
325 if (_ntripVersion == "1") {
326 _socket->waitForReadyRead(_timeOut);
327 if (_socket->canReadLine()) {
328 QString line = _socket->readLine();
329
330 // Skip messages from proxy server
331 // -------------------------------
332 if (line.indexOf("ICY 200 OK") == -1 &&
333 line.indexOf("200 OK") != -1 ) {
334 bool proxyRespond = true;
335 while (true) {
336 if (_socket->canReadLine()) {
337 line = _socket->readLine();
338 if (!proxyRespond) {
339 break;
340 }
341 if (line.trimmed().isEmpty()) {
342 proxyRespond = false;
343 }
344 }
345 else {
346 _socket->waitForReadyRead(_timeOut);
347 if (_socket->bytesAvailable() <= 0) {
348 break;
349 }
350 }
351 }
352 }
353
354 if (line.indexOf("Unauthorized") != -1) {
355 QStringList table;
356 bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
357 _ntripVersion, table);
358 QString net;
359 QStringListIterator it(table);
360 while (it.hasNext()) {
361 QString line = it.next();
362 if (line.indexOf("STR") == 0) {
363 QStringList tags = line.split(";");
364 if (tags.at(1) == _staID_orig) {
365 net = tags.at(7);
366 break;
367 }
368 }
369 }
370
371 QString reg;
372 it.toFront();
373 while (it.hasNext()) {
374 QString line = it.next();
375 if (line.indexOf("NET") == 0) {
376 QStringList tags = line.split(";");
377 if (tags.at(1) == net) {
378 reg = tags.at(7);
379 break;
380 }
381 }
382 }
383 emit(newMessage((_staID + ": Caster Response: " + line +
384 " Adjust User-ID and Password Register, see"
385 "\n " + reg).toAscii(), true));
386 return fatal;
387 }
388 if (line.indexOf("ICY 200 OK") != 0) {
389 emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii(), true));
390 return failure;
391 }
392 }
393 else {
394 emit(newMessage(_staID + ": Response Timeout", true));
395 return failure;
396 }
397 }
398 }
399
400 // Instantiate the filter
401 // ----------------------
402 if (!_decoder) {
403 if (_format.indexOf("RTCM_2") != -1) {
404 emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format", true));
405 _decoder = new RTCM2Decoder(_staID.data());
406 }
407 else if (_format.indexOf("RTCM_3") != -1) {
408 emit(newMessage("Get Data: " + _staID + " in RTCM 3.x format", true));
409 _decoder = new RTCM3Decoder(_staID);
410 connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
411 this, SIGNAL(newMessage(QByteArray,bool)));
412 }
413 else if (_format.indexOf("RTIGS") != -1) {
414 emit(newMessage("Get Data: " + _staID + " in RTIGS format", true));
415 _decoder = new RTIGSDecoder();
416 }
417 else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
418 emit(newMessage("Get Data: " + _staID + " in GPSS format", true));
419 _decoder = new gpssDecoder();
420 }
421 else if (_format.indexOf("ZERO") != -1) {
422 emit(newMessage("Get Data: " + _staID + " in original format", true));
423 _decoder = new bncZeroDecoder(_staID);
424 }
425 else {
426 emit(newMessage(_staID + ": Unknown data format " + _format, true));
427 if (_rawInpFile) {
428 cerr << "Uknown data format" << endl;
429 ::exit(0);
430 }
431 else {
432 return fatal;
433 }
434 }
435 }
436 return success;
437}
438
439// Run
440////////////////////////////////////////////////////////////////////////////
441void bncGetThread::run() {
442
443 const double maxDt = 600.0; // Check observation epoch
444 bool wrongEpoch = false;
445 bool decode = true;
446 int numSucc = 0;
447 int secSucc = 0;
448 int secFail = 0;
449 int initPause = 30; // Initial pause for corrupted streams
450 int currPause = 0;
451 bool begCorrupt = false;
452 bool endCorrupt = false;
453 bool followSec = false;
454 int oldSecGPS= 0;
455 int newSecGPS = 0;
456 int numGaps = 0;
457 int diffSecGPS = 0;
458 int numLat = 0;
459 double sumLat = 0.;
460 double sumLatQ = 0.;
461 double meanDiff = 0.;
462 double minLat = maxDt;
463 double maxLat = -maxDt;
464 double curLat = 0.;
465
466 _decodeTime = QDateTime::currentDateTime();
467 _decodeSucc = QDateTime::currentDateTime();
468 t_irc irc = initRun();
469
470 if (irc == fatal) {
471 QThread::exit(1);
472 return;
473 }
474 else if (irc != success) {
475 emit(newMessage(_staID + ": initRun failed, reconnecting", true));
476 tryReconnect();
477 }
478
479 if (initPause < _inspSegm) {
480 initPause = _inspSegm;
481 }
482 if(!_makePause) {initPause = 0;}
483 currPause = initPause;
484
485 // Read Incoming Data
486 // ------------------
487 while (true) {
488 try {
489 if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
490 emit(newMessage(_staID + ": Socket not connected, reconnecting", true));
491 tryReconnect();
492 }
493
494 QListIterator<p_obs> it(_decoder->_obsList);
495 while (it.hasNext()) {
496 delete it.next();
497 }
498 _decoder->_obsList.clear();
499
500 qint64 nBytes = 0;
501
502 if (_socket) {
503 _socket->waitForReadyRead(_timeOut);
504 nBytes = _socket->bytesAvailable();
505 }
506 else if (_rawInpFile) {
507 const qint64 maxBytes = 1024;
508 nBytes = maxBytes;
509 }
510
511 if (nBytes > 0) {
512 emit newBytes(_staID, nBytes);
513
514 char* data = new char[nBytes];
515
516 if (_socket) {
517 _socket->read(data, nBytes);
518 }
519 else if (_rawInpFile) {
520 nBytes = _rawInpFile->read(data, nBytes);
521 if (nBytes <= 0) {
522 cout << "no more data" << endl;
523 ::exit(0);
524 }
525 }
526
527 if (_rawOutFile) {
528 _rawOutFile->write(data, nBytes);
529 _rawOutFile->flush();
530 }
531
532 if (_serialPort) {
533 _serialPort->write(data, nBytes);
534 //// _serialPort->flush();
535 }
536
537 if (_inspSegm<1) {
538 vector<string> errmsg;
539 _decoder->Decode(data, nBytes, errmsg);
540#ifdef DEBUG_RTCM2_2021
541 for (unsigned ii = 0; ii < errmsg.size(); ii++) {
542 emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
543 }
544#endif
545 }
546 else {
547
548 // Decode data
549 // -----------
550 if (!_decodePause.isValid() ||
551 _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause ) {
552
553 if (decode) {
554 vector<string> errmsg;
555 if ( _decoder->Decode(data, nBytes, errmsg) == success ) {
556 numSucc += 1;
557 }
558 if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) {
559 decode = false;
560 }
561#ifdef DEBUG_RTCM2_2021
562 for (unsigned ii = 0; ii < errmsg.size(); ii++) {
563 emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
564 }
565#endif
566 }
567
568 // Check - once per inspect segment
569 // --------------------------------
570 if (!decode) {
571 _decodeTime = QDateTime::currentDateTime();
572 if (numSucc>0) {
573 secSucc += _inspSegm;
574 _decodeSucc = QDateTime::currentDateTime();
575 if (secSucc > _adviseReco * 60) {
576 secSucc = _adviseReco * 60 + 1;
577 }
578 numSucc = 0;
579 currPause = initPause;
580 _decodePause.setDate(QDate());
581 _decodePause.setTime(QTime());
582 }
583 else {
584 secFail += _inspSegm;
585 secSucc = 0;
586 if (secFail > _adviseFail * 60) {
587 secFail = _adviseFail * 60 + 1;
588 }
589 if (!_decodePause.isValid() || !_makePause) {
590 _decodePause = QDateTime::currentDateTime();
591 }
592 else {
593 _decodePause.setDate(QDate());
594 _decodePause.setTime(QTime());
595 secFail = secFail + currPause - _inspSegm;
596 currPause = currPause * 2;
597 if (currPause > 960) {
598 currPause = 960;
599 }
600 }
601 }
602
603 // End corrupt threshold
604 // ---------------------
605 if ( begCorrupt && !endCorrupt && secSucc > _adviseReco * 60 ) {
606 _endDateCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
607 _endTimeCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
608 emit(newMessage((_staID + ": Recovery threshold exceeded, corruption ended "
609 + _endDateCor + " " + _endTimeCor).toAscii(), true));
610 callScript(("End_Corrupted " + _endDateCor + " " + _endTimeCor + " Begin was " + _begDateCor + " " + _begTimeCor).toAscii());
611 endCorrupt = true;
612 begCorrupt = false;
613 secFail = 0;
614 }
615 else {
616
617 // Begin corrupt threshold
618 // -----------------------
619 if ( !begCorrupt && secFail > _adviseFail * 60 ) {
620 _begDateCor = _decodeSucc.toUTC().date().toString("yy-MM-dd");
621 _begTimeCor = _decodeSucc.toUTC().time().toString("hh:mm:ss");
622 emit(newMessage((_staID + ": Failure threshold exceeded, corrupted since "
623 + _begDateCor + " " + _begTimeCor).toAscii(), true));
624 callScript(("Begin_Corrupted " + _begDateCor + " " + _begTimeCor).toAscii());
625 begCorrupt = true;
626 endCorrupt = false;
627 secSucc = 0;
628 numSucc = 0;
629 }
630 }
631 decode = true;
632 }
633 }
634 }
635
636 // End outage threshold
637 // --------------------
638 if ( _decodeStart.isValid() && _decodeStart.secsTo(QDateTime::currentDateTime()) > _adviseReco * 60 ) {
639 _decodeStart.setDate(QDate());
640 _decodeStart.setTime(QTime());
641 if (_inspSegm>0) {
642 _endDateOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
643 _endTimeOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
644 emit(newMessage((_staID + ": Recovery threshold exceeded, outage ended "
645 + _endDateOut + " " + _endTimeOut).toAscii(), true));
646 callScript(("End_Outage " + _endDateOut + " " + _endTimeOut + " Begin was " + _begDateOut + " " + _begTimeOut).toAscii());
647 }
648 }
649
650 delete [] data;
651
652
653 // RTCM scan output
654 // ----------------
655 if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
656 QSettings settings;
657 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked) {
658
659 // RTCMv3 message types
660 // --------------------
661 if (0<_decoder->_typeList.size()) {
662 QString type;
663 for (int ii=0;ii<_decoder->_typeList.size();ii++) {
664 type = QString("%1 ").arg(_decoder->_typeList[ii]);
665 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
666 }
667 }
668
669 // RTCMv3 antenna descriptor
670 // -------------------------
671 if (0<_decoder->_antType.size()) {
672 QString ant1;
673 for (int ii=0;ii<_decoder->_antType.size();ii++) {
674 ant1 = QString("%1 ").arg(_decoder->_antType[ii]);
675 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
676 }
677 }
678
679 // Antenna XYZ
680 // ------------------
681 if (0<_decoder->_antList.size()) {
682 for (int ii=0;ii<_decoder->_antList.size();++ii) {
683 QByteArray ant1,ant2,ant3, antT;
684 ant1 = QString("%1 ").arg(_decoder->_antList[ii].xx,0,'f',4).toAscii();
685 ant2 = QString("%1 ").arg(_decoder->_antList[ii].yy,0,'f',4).toAscii();
686 ant3 = QString("%1 ").arg(_decoder->_antList[ii].zz,0,'f',4).toAscii();
687 switch (_decoder->_antList[ii].type) {
688 case GPSDecoder::t_antInfo::ARP: antT = "ARP"; break;
689 case GPSDecoder::t_antInfo::APC: antT = "APC"; break;
690 }
691 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
692 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
693 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
694 if (_decoder->_antList[ii].height_f) {
695 QByteArray ant4 = QString("%1 ").arg(_decoder->_antList[ii].height,0,'f',4).toAscii();
696 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
697 }
698 emit(newAntCrd(_staID,
699 _decoder->_antList[ii].xx, _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
700 antT));
701 }
702 }
703 }
704 if ( _checkMountPoint == "ANTCRD_ONLY" && _decoder->_antList.size() ) {
705 for (int ii=0;ii<_decoder->_antList.size();++ii) {
706 QByteArray antT;
707 switch (_decoder->_antList[ii].type) {
708 case GPSDecoder::t_antInfo::ARP: antT = "ARP"; break;
709 case GPSDecoder::t_antInfo::APC: antT = "APC"; break;
710 }
711 emit(newAntCrd(_staID,
712 _decoder->_antList[ii].xx, _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
713 antT));
714 }
715 }
716 }
717
718 _decoder->_typeList.clear();
719 _decoder->_antType.clear();
720 _decoder->_antList.clear();
721
722 // Loop over all observations (observations output)
723 // ------------------------------------------------
724 QListIterator<p_obs> it(_decoder->_obsList);
725 while (it.hasNext()) {
726 p_obs obs = it.next();
727
728 // Check observation epoch
729 // -----------------------
730 if (!_rawInpFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
731 int week;
732 double sec;
733 currentGPSWeeks(week, sec);
734 const double secPerWeek = 7.0 * 24.0 * 3600.0;
735
736 if (week < obs->_o.GPSWeek) {
737 week += 1;
738 sec -= secPerWeek;
739 }
740 if (week > obs->_o.GPSWeek) {
741 week -= 1;
742 sec += secPerWeek;
743 }
744 double dt = fabs(sec - obs->_o.GPSWeeks);
745 if (week != obs->_o.GPSWeek || dt > maxDt) {
746 if (!wrongEpoch) {
747 emit( newMessage(_staID + ": Wrong observation epoch(s)", true) );
748 wrongEpoch = true;
749 }
750 delete obs;
751 continue;
752 }
753 else {
754 wrongEpoch = false;
755
756 // Latency and completeness
757 // ------------------------
758 if (_perfIntr>0) {
759 if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
760 newSecGPS = static_cast<int>(obs->_o.GPSWeeks);
761 if (newSecGPS != oldSecGPS) {
762 if (newSecGPS % _perfIntr < oldSecGPS % _perfIntr) {
763 if (numLat>0) {
764 if (meanDiff>0.) {
765 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs, %7 gaps")
766 .arg(_staID.data())
767 .arg(int(sumLat/numLat*100)/100.)
768 .arg(int(minLat*100)/100.)
769 .arg(int(maxLat*100)/100.)
770 .arg(int((sqrt((sumLatQ - sumLat * sumLat / numLat)/numLat))*100)/100.)
771 .arg(numLat)
772 .arg(numGaps)
773 .toAscii(), true) );
774 } else {
775 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs")
776 .arg(_staID.data())
777 .arg(int(sumLat/numLat*100)/100.)
778 .arg(int(minLat*100)/100.)
779 .arg(int(maxLat*100)/100.)
780 .arg(int((sqrt((sumLatQ - sumLat * sumLat / numLat)/numLat))*100)/100.)
781 .arg(numLat)
782 .toAscii(), true) );
783 }
784 }
785 meanDiff = diffSecGPS/numLat;
786 diffSecGPS = 0;
787 numGaps = 0;
788 sumLat = 0.;
789 sumLatQ = 0.;
790 numLat = 0;
791 minLat = maxDt;
792 maxLat = -maxDt;
793 }
794 if (followSec) {
795 diffSecGPS += newSecGPS - oldSecGPS;
796 if (meanDiff>0.) {
797 if (newSecGPS - oldSecGPS > 1.5 * meanDiff) {
798 numGaps += 1;
799 }
800 }
801 }
802 curLat = sec - obs->_o.GPSWeeks;
803 sumLat += curLat;
804 sumLatQ += curLat * curLat;
805 if (curLat < minLat) minLat = curLat;
806 if (curLat >= maxLat) maxLat = curLat;
807 numLat += 1;
808 oldSecGPS = newSecGPS;
809 followSec = true;
810 }
811 }
812 }
813 }
814 }
815
816 // RINEX Output
817 // ------------
818 if (_rnx) {
819 bool dump = true;
820
821 //// // RTCMv2 XYZ
822 //// // ----------
823 //// RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
824 //// if ( decoder2 && !_rnx_set_position ) {
825 //// double stax, stay, staz;
826 //// double dL1[3], dL2[3];
827 //// if ( decoder2->getStaCrd(stax, stay, staz,
828 //// dL1[0], dL1[1], dL1[2],
829 //// dL2[0], dL2[1], dL2[2]) == success ) {
830 ////
831 //// if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
832 //// QString ant1;
833 //// ant1 = QString("%1 ").arg(stax,0,'f',4);
834 //// emit(newMessage(_staID + ": ARP X " + ant1.toAscii() + "m" ));
835 //// ant1 = QString("%1 ").arg(stay,0,'f',4);
836 //// emit(newMessage(_staID + ": ARP Y " + ant1.toAscii() + "m" ));
837 //// ant1 = QString("%1 ").arg(staz,0,'f',4);
838 //// emit(newMessage(_staID + ": ARP Z " + ant1.toAscii() + "m" ));
839 //// ant1 = QString("%1 ").arg(dL1[0],0,'f',4);
840 //// emit(newMessage(_staID + ": L1 APC DX " + ant1.toAscii() + "m" ));
841 //// ant1 = QString("%1 ").arg(dL1[1],0,'f',4);
842 //// emit(newMessage(_staID + ": L1 APC DY " + ant1.toAscii() + "m" ));
843 //// ant1 = QString("%1 ").arg(dL1[2],0,'f',4);
844 //// emit(newMessage(_staID + ": L1 APC DZ " + ant1.toAscii() + "m" ));
845 //// ant1 = QString("%1 ").arg(dL2[0],0,'f',4);
846 //// emit(newMessage(_staID + ": L2 APC DX " + ant1.toAscii() + "m" ));
847 //// ant1 = QString("%1 ").arg(dL2[1],0,'f',4);
848 //// emit(newMessage(_staID + ": L2 APC DY " + ant1.toAscii() + "m" ));
849 //// ant1 = QString("%1 ").arg(dL2[2],0,'f',4);
850 //// emit(newMessage(_staID + ": L2 APC DZ " + ant1.toAscii() + "m" ));
851 //// }
852 //// _rnx_set_position = true;
853 //// }
854 //// }
855
856 if ( dump ) {
857 long iSec = long(floor(obs->_o.GPSWeeks+0.5));
858 long newTime = obs->_o.GPSWeek * 7*24*3600 + iSec;
859 if (_samplingRate == 0 || iSec % _samplingRate == 0) {
860 _rnx->deepCopy(obs);
861 }
862 _rnx->dumpEpoch(newTime);
863 }
864 }
865
866 // Emit new observation signal
867 // ---------------------------
868 bool firstObs = (obs == _decoder->_obsList.first());
869 obs->_status = t_obs::posted;
870 emit newObs(_staID, firstObs, obs);
871 }
872 _decoder->_obsList.clear();
873
874 }
875
876 // Timeout, reconnect
877 // ------------------
878 else {
879 emit(newMessage(_staID + ": Data Timeout, reconnecting", true));
880 tryReconnect();
881 }
882 }
883 catch (const char* msg) {
884 emit(newMessage(_staID + msg, true));
885 tryReconnect();
886 }
887 }
888}
889
890// Exit
891////////////////////////////////////////////////////////////////////////////
892void bncGetThread::exit(int exitCode) {
893 if (exitCode!= 0) {
894 emit error(_staID);
895 }
896 QThread::exit(exitCode);
897 terminate();
898}
899
900// Try Re-Connect
901////////////////////////////////////////////////////////////////////////////
902void bncGetThread::tryReconnect() {
903 if (_rnx) {
904 _rnx->setReconnectFlag(true);
905 }
906 if ( !_decodeStart.isValid()) {
907 _decodeStop = QDateTime::currentDateTime();
908 }
909 while (1) {
910 sleep(_nextSleep);
911 if ( initRun() == success ) {
912 if ( !_decodeStop.isValid()) {
913 _decodeStart = QDateTime::currentDateTime();
914 }
915 break;
916 }
917 else {
918
919 // Begin outage threshold
920 // ----------------------
921 if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _adviseFail * 60 ) {
922 _decodeStop.setDate(QDate());
923 _decodeStop.setTime(QTime());
924 if (_inspSegm>0) {
925 _begDateOut = _decodeTime.toUTC().date().toString("yy-MM-dd");
926 _begTimeOut = _decodeTime.toUTC().time().toString("hh:mm:ss");
927 emit(newMessage((_staID + ": Failure threshold exceeded, outage since "
928 + _begDateOut + " " + _begTimeOut).toAscii(), true));
929 callScript(("Begin_Outage " + _begDateOut + " " + _begTimeOut).toAscii());
930 }
931 }
932 _nextSleep *= 2;
933 if (_nextSleep > 256) {
934 _nextSleep = 256;
935 }
936 _nextSleep += rand() % 6;
937 }
938 }
939 _nextSleep = 1;
940}
941
942// Call advisory notice script
943////////////////////////////////////////////////////////////////////////////
944void bncGetThread::callScript(const char* _comment) {
945 QMutexLocker locker(&_mutex);
946 if (!_adviseScript.isEmpty()) {
947 msleep(1);
948#ifdef WIN32
949 QProcess::startDetached(_adviseScript, QStringList() << _staID << _comment) ;
950#else
951 QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << _comment) ;
952#endif
953 }
954}
955
956//
957//////////////////////////////////////////////////////////////////////////////
958void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
959 RTCM2Decoder* decoder = dynamic_cast<RTCM2Decoder*>(_decoder);
960
961 if ( decoder ) {
962 QMutexLocker locker(&_mutex);
963
964 string storedPRN;
965 vector<int> IODs;
966
967 if ( decoder->storeEph(gpseph, storedPRN, IODs) ) {
968#ifdef DEBUG_RTCM2_2021
969 QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
970
971 for (unsigned ii = 0; ii < IODs.size(); ii++) {
972 msg += QString(" %1").arg(IODs[ii],4);
973 }
974
975 emit(newMessage(msg.toAscii(), false));
976#endif
977 }
978 }
979}
980
Note: See TracBrowser for help on using the repository browser.