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

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

* empty log message *

File size: 29.4 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 "bncnetqueryv1.h"
57#include "bncnetqueryv2.h"
58#include "bncnetqueryrtp.h"
59#include "bncsettings.h"
60
61#include "RTCM/RTCM2Decoder.h"
62#include "RTCM3/RTCM3Decoder.h"
63#include "RTIGS/RTIGSDecoder.h"
64#include "GPSS/gpssDecoder.h"
65#include "serial/qextserialport.h"
66
67using namespace std;
68
69// Constructor 1
70////////////////////////////////////////////////////////////////////////////
71bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
72 const QByteArray& format) {
73
74 _format = format;
75
76 int iSep = rawInpFileName.lastIndexOf(QDir::separator());
77 _staID = rawInpFileName.mid(iSep+1,4);
78
79 initialize();
80
81 _inspSegm = 0;
82
83 _rawInpFile = new QFile(rawInpFileName);
84 _rawInpFile->open(QIODevice::ReadOnly);
85
86 if (!_rnx) {
87 cerr << "no RINEX path specified" << endl;
88 ::exit(1);
89 }
90}
91
92// Constructor 2
93////////////////////////////////////////////////////////////////////////////
94bncGetThread::bncGetThread(const QUrl& mountPoint,
95 const QByteArray& format,
96 const QByteArray& latitude,
97 const QByteArray& longitude,
98 const QByteArray& nmea,
99 const QByteArray& ntripVersion, int iMount) {
100
101 setTerminationEnabled(true);
102
103 _mountPoint = mountPoint;
104 _staID = mountPoint.path().mid(1).toAscii();
105 _format = format;
106 _latitude = latitude;
107 _longitude = longitude;
108 _nmea = nmea;
109 _ntripVersion = ntripVersion;
110 _iMount = iMount; // index in mountpoints array
111
112 initialize();
113}
114
115// Initialization
116////////////////////////////////////////////////////////////////////////////
117void bncGetThread::initialize() {
118
119
120 bncApp* app = (bncApp*) qApp;
121 app->connect(this, SIGNAL(newMessage(QByteArray,bool)),
122 app, SLOT(slotMessage(const QByteArray,bool)));
123
124 _isToBeDeleted = false;
125 _decoder = 0;
126 _query = 0;
127 _timeOut = 20*1000; // 20 seconds
128 _nextSleep = 1; // 1 second
129 _rawInpFile = 0;
130 _rawOutFile = 0;
131 _staID_orig = _staID;
132
133 // Check name conflict
134 // -------------------
135 bncSettings settings;
136 QListIterator<QString> it(settings.value("mountPoints").toStringList());
137 int num = 0;
138 int ind = -1;
139 while (it.hasNext()) {
140 ++ind;
141 QStringList hlp = it.next().split(" ");
142 if (hlp.size() <= 1) continue;
143 QUrl url(hlp[0]);
144 if (_mountPoint.path() == url.path()) {
145 if (_iMount > ind || _iMount < 0) {
146 ++num;
147 }
148 }
149 }
150
151 if (num > 0) {
152 _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
153 }
154
155 // Notice threshold
156 // ----------------
157 _inspSegm = 50;
158 if ( settings.value("obsRate").toString().isEmpty() ) { _inspSegm = 0; }
159 if ( settings.value("obsRate").toString().indexOf("5 Hz") != -1 ) { _inspSegm = 2; }
160 if ( settings.value("obsRate").toString().indexOf("1 Hz") != -1 ) { _inspSegm = 10; }
161 if ( settings.value("obsRate").toString().indexOf("0.5 Hz") != -1 ) { _inspSegm = 20; }
162 if ( settings.value("obsRate").toString().indexOf("0.2 Hz") != -1 ) { _inspSegm = 40; }
163 if ( settings.value("obsRate").toString().indexOf("0.1 Hz") != -1 ) { _inspSegm = 50; }
164 _adviseFail = settings.value("adviseFail").toInt();
165 _adviseReco = settings.value("adviseReco").toInt();
166 _makePause = false;
167 if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {_makePause = true; }
168 _adviseScript = settings.value("adviseScript").toString();
169 expandEnvVar(_adviseScript);
170
171 // Latency interval/average
172 // ------------------------
173 _perfIntr = 86400;
174 if ( settings.value("perfIntr").toString().isEmpty() ) { _perfIntr = 0; }
175 if ( settings.value("perfIntr").toString().indexOf("2 sec") != -1 ) { _perfIntr = 2; }
176 if ( settings.value("perfIntr").toString().indexOf("10 sec") != -1 ) { _perfIntr = 10; }
177 if ( settings.value("perfIntr").toString().indexOf("1 min") != -1 ) { _perfIntr = 60; }
178 if ( settings.value("perfIntr").toString().indexOf("5 min") != -1 ) { _perfIntr = 300; }
179 if ( settings.value("perfIntr").toString().indexOf("15 min") != -1 ) { _perfIntr = 900; }
180 if ( settings.value("perfIntr").toString().indexOf("1 hour") != -1 ) { _perfIntr = 3600; }
181 if ( settings.value("perfIntr").toString().indexOf("6 hours") != -1 ) { _perfIntr = 21600; }
182 if ( settings.value("perfIntr").toString().indexOf("1 day") != -1 ) { _perfIntr = 86400; }
183
184 // RTCM message types
185 // ------------------
186 _checkMountPoint = settings.value("miscMount").toString();
187
188 // RINEX writer
189 // ------------
190 _samplingRate = settings.value("rnxSampl").toInt();
191 if ( settings.value("rnxPath").toString().isEmpty() ) {
192 _rnx = 0;
193 }
194 else {
195 _rnx = new bncRinex(_staID, _mountPoint, _format, _latitude,
196 _longitude, _nmea);
197 }
198 _rnx_set_position = false;
199
200 connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
201 this, SLOT(slotNewEphGPS(gpsephemeris)));
202
203 if (settings.value("serialMountPoint").toString() == _staID) {
204 _serialPort = new QextSerialPort(
205 settings.value("serialPortName").toString() );
206 QString hlp = settings.value("serialBaudRate").toString();
207 if (hlp == "110") {
208 _serialPort->setBaudRate(BAUD110);
209 }
210 else if (hlp == "300") {
211 _serialPort->setBaudRate(BAUD300);
212 }
213 else if (hlp == "600") {
214 _serialPort->setBaudRate(BAUD600);
215 }
216 else if (hlp == "1200") {
217 _serialPort->setBaudRate(BAUD1200);
218 }
219 else if (hlp == "2400") {
220 _serialPort->setBaudRate(BAUD2400);
221 }
222 else if (hlp == "4800") {
223 _serialPort->setBaudRate(BAUD4800);
224 }
225 else if (hlp == "9600") {
226 _serialPort->setBaudRate(BAUD9600);
227 }
228 else if (hlp == "19200") {
229 _serialPort->setBaudRate(BAUD19200);
230 }
231 else if (hlp == "38400") {
232 _serialPort->setBaudRate(BAUD38400);
233 }
234 else if (hlp == "57600") {
235 _serialPort->setBaudRate(BAUD57600);
236 }
237 else if (hlp == "115200") {
238 _serialPort->setBaudRate(BAUD115200);
239 }
240 hlp = settings.value("serialParity").toString();
241 if (hlp == "NONE") {
242 _serialPort->setParity(PAR_NONE);
243 }
244 else if (hlp == "ODD") {
245 _serialPort->setParity(PAR_ODD);
246 }
247 else if (hlp == "EVEN") {
248 _serialPort->setParity(PAR_EVEN);
249 }
250 else if (hlp == "SPACE") {
251 _serialPort->setParity(PAR_SPACE);
252 }
253 hlp = settings.value("serialDataBits").toString();
254 if (hlp == "5") {
255 _serialPort->setDataBits(DATA_5);
256 }
257 else if (hlp == "6") {
258 _serialPort->setDataBits(DATA_6);
259 }
260 else if (hlp == "7") {
261 _serialPort->setDataBits(DATA_7);
262 }
263 else if (hlp == "8") {
264 _serialPort->setDataBits(DATA_8);
265 }
266 hlp = settings.value("serialStopBits").toString();
267 if (hlp == "1") {
268 _serialPort->setStopBits(STOP_1);
269 }
270 else if (hlp == "2") {
271 _serialPort->setStopBits(STOP_2);
272 }
273 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
274 if (!_serialPort->isOpen()) {
275 delete _serialPort;
276 _serialPort = 0;
277 emit(newMessage((_staID + ": Cannot open serial port\n"), true));
278 }
279 }
280 else {
281 _serialPort = 0;
282 }
283
284 // Raw Output
285 // ----------
286 // QByteArray rawOutFileName = "./" + _staID + ".raw";
287 // _rawOutFile = new QFile(rawOutFileName);
288 // _rawOutFile->open(QIODevice::WriteOnly);
289
290 msleep(100); //sleep 0.1 sec
291}
292
293// Destructor
294////////////////////////////////////////////////////////////////////////////
295bncGetThread::~bncGetThread() {
296 if (_query) {
297 _query->stop();
298 delete _query;
299 }
300 delete _decoder;
301 delete _rnx;
302 delete _rawInpFile;
303 delete _rawOutFile;
304 delete _serialPort;
305}
306
307//
308////////////////////////////////////////////////////////////////////////////
309void bncGetThread::terminate() {
310 _isToBeDeleted = true;
311}
312
313// Init Run
314////////////////////////////////////////////////////////////////////////////
315t_irc bncGetThread::initRun() {
316
317 if (!_rawInpFile) {
318 delete _query;
319 if (_ntripVersion == "R") {
320 _query = new bncNetQueryRtp();
321 }
322 else if (_ntripVersion == "2") {
323 _query = new bncNetQueryV2();
324 }
325 else {
326 _query = new bncNetQueryV1();
327 }
328 if (_nmea == "yes") {
329 QByteArray gga = ggaString(_latitude, _longitude);
330 _query->startRequest(_mountPoint, gga);
331 }
332 else {
333 _query->startRequest(_mountPoint, "");
334 }
335 }
336
337 // Instantiate the filter
338 // ----------------------
339 if (!_decoder) {
340 if (_format.indexOf("RTCM_2") != -1) {
341 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
342 _decoder = new RTCM2Decoder(_staID.data());
343 }
344 else if (_format.indexOf("RTCM_3") != -1) {
345 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
346 _decoder = new RTCM3Decoder(_staID);
347 connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
348 this, SIGNAL(newMessage(QByteArray,bool)));
349 }
350 else if (_format.indexOf("RTIGS") != -1) {
351 emit(newMessage(_staID + ": Get data in RTIGS format", true));
352 _decoder = new RTIGSDecoder();
353 }
354 else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
355 emit(newMessage(_staID + ": Get Data in GPSS format", true));
356 _decoder = new gpssDecoder();
357 }
358 else if (_format.indexOf("ZERO") != -1) {
359 emit(newMessage(_staID + ": Get data in original format", true));
360 _decoder = new bncZeroDecoder(_staID);
361 }
362 else {
363 emit(newMessage(_staID + ": Unknown data format " + _format, true));
364 if (_rawInpFile) {
365 cerr << "Uknown data format" << endl;
366 delete this;
367 }
368 else {
369 return fatal;
370 }
371 }
372 }
373 return success;
374}
375
376// Run
377////////////////////////////////////////////////////////////////////////////
378void bncGetThread::run() {
379
380 const double maxDt = 600.0; // Check observation epoch
381 bool wrongEpoch = false;
382 bool decode = true;
383 int numSucc = 0;
384 int secSucc = 0;
385 int secFail = 0;
386 int initPause = 30; // Initial pause for corrupted streams
387 int currPause = 0;
388 bool begCorrupt = false;
389 bool endCorrupt = false;
390 bool followSec = false;
391 int oldSecGPS= 0;
392 int newSecGPS = 0;
393 int numGaps = 0;
394 int diffSecGPS = 0;
395 int numLat = 0;
396 double sumLat = 0.;
397 double sumLatQ = 0.;
398 double meanDiff = 0.;
399 double minLat = maxDt;
400 double maxLat = -maxDt;
401 double curLat = 0.;
402
403 _decodeTime = QDateTime::currentDateTime();
404 _decodeSucc = QDateTime::currentDateTime();
405 t_irc irc = initRun();
406
407 if (irc == fatal) {
408 QThread::exit(1);
409 this->deleteLater();
410 return;
411 }
412 else if (irc != success) {
413 emit(newMessage(_staID + ": initRun failed, reconnecting", true));
414 tryReconnect();
415 }
416
417 if (initPause < _inspSegm) {
418 initPause = _inspSegm;
419 }
420 if(!_makePause) {initPause = 0;}
421 currPause = initPause;
422
423 // Read Incoming Data
424 // ------------------
425 while (true) {
426 if (_isToBeDeleted) {
427 QThread::exit(0);
428 this->deleteLater();
429 return;
430 }
431 try {
432 if (_query && _query->status() != bncNetQuery::running) {
433 emit(newMessage(_staID + ": Internet query not running, reconnecting", true));
434 tryReconnect();
435 }
436
437 QListIterator<p_obs> it(_decoder->_obsList);
438 while (it.hasNext()) {
439 delete it.next();
440 }
441 _decoder->_obsList.clear();
442
443 qint64 nBytes = 0;
444
445 QByteArray data;
446
447 if (_query) {
448 _query->waitForReadyRead(data);
449 nBytes = data.size();
450 }
451 else if (_rawInpFile) {
452 const qint64 maxBytes = 1024;
453 nBytes = maxBytes;
454 }
455
456 if (nBytes > 0) {
457 emit newBytes(_staID, nBytes);
458
459 if (_rawInpFile) {
460 data = _rawInpFile->read(nBytes);
461 if (data.isEmpty()) {
462 cout << "no more data" << endl;
463 ::exit(0);
464 }
465 }
466
467 if (_rawOutFile) {
468 _rawOutFile->write(data);
469 _rawOutFile->flush();
470 }
471
472 if (_serialPort) {
473 _serialPort->write(data);
474 }
475
476 if (_inspSegm<1) {
477 vector<string> errmsg;
478 _decoder->Decode(data.data(), data.size(), errmsg);
479#ifdef DEBUG_RTCM2_2021
480 for (unsigned ii = 0; ii < errmsg.size(); ii++) {
481 emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
482 }
483#endif
484 }
485 else {
486
487 // Decode data
488 // -----------
489 if (!_decodePause.isValid() ||
490 _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause ) {
491
492 if (decode) {
493 vector<string> errmsg;
494 if ( _decoder->Decode(data.data(), data.size(), errmsg) == success ) {
495 numSucc += 1;
496 }
497 if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) {
498 decode = false;
499 }
500#ifdef DEBUG_RTCM2_2021
501 for (unsigned ii = 0; ii < errmsg.size(); ii++) {
502 emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
503 }
504#endif
505 }
506
507 // Check - once per inspect segment
508 // --------------------------------
509 if (!decode) {
510 _decodeTime = QDateTime::currentDateTime();
511 if (numSucc>0) {
512 secSucc += _inspSegm;
513 _decodeSucc = QDateTime::currentDateTime();
514 if (secSucc > _adviseReco * 60) {
515 secSucc = _adviseReco * 60 + 1;
516 }
517 numSucc = 0;
518 currPause = initPause;
519 _decodePause.setDate(QDate());
520 _decodePause.setTime(QTime());
521 }
522 else {
523 secFail += _inspSegm;
524 secSucc = 0;
525 if (secFail > _adviseFail * 60) {
526 secFail = _adviseFail * 60 + 1;
527 }
528 if (!_decodePause.isValid() || !_makePause) {
529 _decodePause = QDateTime::currentDateTime();
530 }
531 else {
532 _decodePause.setDate(QDate());
533 _decodePause.setTime(QTime());
534 secFail = secFail + currPause - _inspSegm;
535 currPause = currPause * 2;
536 if (currPause > 960) {
537 currPause = 960;
538 }
539 }
540 }
541
542 // End corrupt threshold
543 // ---------------------
544 if ( begCorrupt && !endCorrupt && secSucc > _adviseReco * 60 ) {
545 _endDateCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
546 _endTimeCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
547 emit(newMessage((_staID + ": Recovery threshold exceeded, corruption ended "
548 + _endDateCor + " " + _endTimeCor).toAscii(), true));
549 callScript(("End_Corrupted " + _endDateCor + " " + _endTimeCor + " Begin was " + _begDateCor + " " + _begTimeCor).toAscii());
550 endCorrupt = true;
551 begCorrupt = false;
552 secFail = 0;
553 }
554 else {
555
556 // Begin corrupt threshold
557 // -----------------------
558 if ( !begCorrupt && secFail > _adviseFail * 60 ) {
559 _begDateCor = _decodeSucc.toUTC().date().toString("yy-MM-dd");
560 _begTimeCor = _decodeSucc.toUTC().time().toString("hh:mm:ss");
561 emit(newMessage((_staID + ": Failure threshold exceeded, corrupted since "
562 + _begDateCor + " " + _begTimeCor).toAscii(), true));
563 callScript(("Begin_Corrupted " + _begDateCor + " " + _begTimeCor).toAscii());
564 begCorrupt = true;
565 endCorrupt = false;
566 secSucc = 0;
567 numSucc = 0;
568 }
569 }
570 decode = true;
571 }
572 }
573 }
574
575 // End outage threshold
576 // --------------------
577 if ( _decodeStart.isValid() && _decodeStart.secsTo(QDateTime::currentDateTime()) > _adviseReco * 60 ) {
578 _decodeStart.setDate(QDate());
579 _decodeStart.setTime(QTime());
580 if (_inspSegm>0) {
581 _endDateOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
582 _endTimeOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
583 emit(newMessage((_staID + ": Recovery threshold exceeded, outage ended "
584 + _endDateOut + " " + _endTimeOut).toAscii(), true));
585 callScript(("End_Outage " + _endDateOut + " " + _endTimeOut + " Begin was " + _begDateOut + " " + _begTimeOut).toAscii());
586 }
587 }
588
589 // RTCM scan output
590 // ----------------
591 if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
592 bncSettings settings;
593 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked) {
594
595 // RTCMv3 message types
596 // --------------------
597 if (0<_decoder->_typeList.size()) {
598 QString type;
599 for (int ii=0;ii<_decoder->_typeList.size();ii++) {
600 type = QString("%1 ").arg(_decoder->_typeList[ii]);
601 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
602 }
603 }
604
605 // RTCMv3 antenna descriptor
606 // -------------------------
607 if (0<_decoder->_antType.size()) {
608 QString ant1;
609 for (int ii=0;ii<_decoder->_antType.size();ii++) {
610 ant1 = QString("%1 ").arg(_decoder->_antType[ii]);
611 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
612 }
613 }
614 }
615 }
616
617 // Antenna Coordinates
618 // -------------------
619 for (int ii=0; ii <_decoder->_antList.size(); ii++) {
620 QByteArray antT;
621 if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
622 antT = "ARP";
623 }
624 else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
625 antT = "APC";
626 }
627 emit(newAntCrd(_staID, _decoder->_antList[ii].xx,
628 _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
629 antT));
630 }
631
632 _decoder->_typeList.clear();
633 _decoder->_antType.clear();
634 _decoder->_antList.clear();
635
636 // Loop over all observations (observations output)
637 // ------------------------------------------------
638 QListIterator<p_obs> it(_decoder->_obsList);
639 while (it.hasNext()) {
640 p_obs obs = it.next();
641
642 // Check observation epoch
643 // -----------------------
644 if (!_rawInpFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
645 int week;
646 double sec;
647 currentGPSWeeks(week, sec);
648 const double secPerWeek = 7.0 * 24.0 * 3600.0;
649
650 if (week < obs->_o.GPSWeek) {
651 week += 1;
652 sec -= secPerWeek;
653 }
654 if (week > obs->_o.GPSWeek) {
655 week -= 1;
656 sec += secPerWeek;
657 }
658 double dt = fabs(sec - obs->_o.GPSWeeks);
659 if (week != obs->_o.GPSWeek || dt > maxDt) {
660 if (!wrongEpoch) {
661 emit( newMessage(_staID + ": Wrong observation epoch(s)", true) );
662 wrongEpoch = true;
663 }
664 delete obs;
665 continue;
666 }
667 else {
668 wrongEpoch = false;
669
670 // Latency and completeness
671 // ------------------------
672 if (_perfIntr>0) {
673 if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
674 newSecGPS = static_cast<int>(obs->_o.GPSWeeks);
675 if (newSecGPS != oldSecGPS) {
676 if (newSecGPS % _perfIntr < oldSecGPS % _perfIntr) {
677 if (numLat>0) {
678 if (meanDiff>0.) {
679 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs, %7 gaps")
680 .arg(_staID.data())
681 .arg(int(sumLat/numLat*100)/100.)
682 .arg(int(minLat*100)/100.)
683 .arg(int(maxLat*100)/100.)
684 .arg(int((sqrt((sumLatQ - sumLat * sumLat / numLat)/numLat))*100)/100.)
685 .arg(numLat)
686 .arg(numGaps)
687 .toAscii(), true) );
688 } else {
689 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs")
690 .arg(_staID.data())
691 .arg(int(sumLat/numLat*100)/100.)
692 .arg(int(minLat*100)/100.)
693 .arg(int(maxLat*100)/100.)
694 .arg(int((sqrt((sumLatQ - sumLat * sumLat / numLat)/numLat))*100)/100.)
695 .arg(numLat)
696 .toAscii(), true) );
697 }
698 }
699 meanDiff = diffSecGPS/numLat;
700 diffSecGPS = 0;
701 numGaps = 0;
702 sumLat = 0.;
703 sumLatQ = 0.;
704 numLat = 0;
705 minLat = maxDt;
706 maxLat = -maxDt;
707 }
708 if (followSec) {
709 diffSecGPS += newSecGPS - oldSecGPS;
710 if (meanDiff>0.) {
711 if (newSecGPS - oldSecGPS > 1.5 * meanDiff) {
712 numGaps += 1;
713 }
714 }
715 }
716 curLat = sec - obs->_o.GPSWeeks;
717 sumLat += curLat;
718 sumLatQ += curLat * curLat;
719 if (curLat < minLat) minLat = curLat;
720 if (curLat >= maxLat) maxLat = curLat;
721 numLat += 1;
722 oldSecGPS = newSecGPS;
723 followSec = true;
724 }
725 }
726 }
727 }
728 }
729
730 // RINEX Output
731 // ------------
732 if (_rnx) {
733 bool dump = true;
734
735 //// // RTCMv2 XYZ
736 //// // ----------
737 //// RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
738 //// if ( decoder2 && !_rnx_set_position ) {
739 //// double stax, stay, staz;
740 //// double dL1[3], dL2[3];
741 //// if ( decoder2->getStaCrd(stax, stay, staz,
742 //// dL1[0], dL1[1], dL1[2],
743 //// dL2[0], dL2[1], dL2[2]) == success ) {
744 ////
745 //// if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
746 //// QString ant1;
747 //// ant1 = QString("%1 ").arg(stax,0,'f',4);
748 //// emit(newMessage(_staID + ": ARP X " + ant1.toAscii() + "m" ));
749 //// ant1 = QString("%1 ").arg(stay,0,'f',4);
750 //// emit(newMessage(_staID + ": ARP Y " + ant1.toAscii() + "m" ));
751 //// ant1 = QString("%1 ").arg(staz,0,'f',4);
752 //// emit(newMessage(_staID + ": ARP Z " + ant1.toAscii() + "m" ));
753 //// ant1 = QString("%1 ").arg(dL1[0],0,'f',4);
754 //// emit(newMessage(_staID + ": L1 APC DX " + ant1.toAscii() + "m" ));
755 //// ant1 = QString("%1 ").arg(dL1[1],0,'f',4);
756 //// emit(newMessage(_staID + ": L1 APC DY " + ant1.toAscii() + "m" ));
757 //// ant1 = QString("%1 ").arg(dL1[2],0,'f',4);
758 //// emit(newMessage(_staID + ": L1 APC DZ " + ant1.toAscii() + "m" ));
759 //// ant1 = QString("%1 ").arg(dL2[0],0,'f',4);
760 //// emit(newMessage(_staID + ": L2 APC DX " + ant1.toAscii() + "m" ));
761 //// ant1 = QString("%1 ").arg(dL2[1],0,'f',4);
762 //// emit(newMessage(_staID + ": L2 APC DY " + ant1.toAscii() + "m" ));
763 //// ant1 = QString("%1 ").arg(dL2[2],0,'f',4);
764 //// emit(newMessage(_staID + ": L2 APC DZ " + ant1.toAscii() + "m" ));
765 //// }
766 //// _rnx_set_position = true;
767 //// }
768 //// }
769
770 if ( dump ) {
771 long iSec = long(floor(obs->_o.GPSWeeks+0.5));
772 long newTime = obs->_o.GPSWeek * 7*24*3600 + iSec;
773 if (_samplingRate == 0 || iSec % _samplingRate == 0) {
774 _rnx->deepCopy(obs);
775 }
776 _rnx->dumpEpoch(newTime);
777 }
778 }
779
780 // Emit new observation signal
781 // ---------------------------
782 bool firstObs = (obs == _decoder->_obsList.first());
783 obs->_status = t_obs::posted;
784 emit newObs(_staID, firstObs, obs);
785 }
786 _decoder->_obsList.clear();
787
788 }
789
790 // Timeout, reconnect
791 // ------------------
792 else {
793 emit(newMessage(_staID + ": Data timeout, reconnecting", true));
794 tryReconnect();
795 }
796 }
797 catch (const char* msg) {
798 emit(newMessage(_staID + msg, true));
799 tryReconnect();
800 }
801 }
802}
803
804// Try Re-Connect
805////////////////////////////////////////////////////////////////////////////
806void bncGetThread::tryReconnect() {
807 if (_rnx) {
808 _rnx->setReconnectFlag(true);
809 }
810 if ( !_decodeStart.isValid()) {
811 _decodeStop = QDateTime::currentDateTime();
812 }
813 while (1) {
814 sleep(_nextSleep);
815 if ( initRun() == success ) {
816 if ( !_decodeStop.isValid()) {
817 _decodeStart = QDateTime::currentDateTime();
818 }
819 break;
820 }
821 else {
822
823 // Begin outage threshold
824 // ----------------------
825 if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _adviseFail * 60 ) {
826 _decodeStop.setDate(QDate());
827 _decodeStop.setTime(QTime());
828 if (_inspSegm>0) {
829 _begDateOut = _decodeTime.toUTC().date().toString("yy-MM-dd");
830 _begTimeOut = _decodeTime.toUTC().time().toString("hh:mm:ss");
831 emit(newMessage((_staID + ": Failure threshold exceeded, outage since "
832 + _begDateOut + " " + _begTimeOut).toAscii(), true));
833 callScript(("Begin_Outage " + _begDateOut + " " + _begTimeOut).toAscii());
834 }
835 }
836 _nextSleep *= 2;
837 if (_nextSleep > 256) {
838 _nextSleep = 256;
839 }
840 _nextSleep += rand() % 6;
841 }
842 }
843 _nextSleep = 1;
844}
845
846// Call advisory notice script
847////////////////////////////////////////////////////////////////////////////
848void bncGetThread::callScript(const char* _comment) {
849 QMutexLocker locker(&_mutex);
850 if (!_adviseScript.isEmpty()) {
851 msleep(1);
852#ifdef WIN32
853 QProcess::startDetached(_adviseScript, QStringList() << _staID << _comment) ;
854#else
855 QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << _comment) ;
856#endif
857 }
858}
859
860//
861//////////////////////////////////////////////////////////////////////////////
862void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
863 RTCM2Decoder* decoder = dynamic_cast<RTCM2Decoder*>(_decoder);
864
865 if ( decoder ) {
866 QMutexLocker locker(&_mutex);
867
868 string storedPRN;
869 vector<int> IODs;
870
871 if ( decoder->storeEph(gpseph, storedPRN, IODs) ) {
872#ifdef DEBUG_RTCM2_2021
873 QString msg = _staID + QString(": Stored eph %1 IODs").arg(storedPRN.c_str());
874
875 for (unsigned ii = 0; ii < IODs.size(); ii++) {
876 msg += QString(" %1").arg(IODs[ii],4);
877 }
878
879 emit(newMessage(msg.toAscii(), false));
880#endif
881 }
882 }
883}
Note: See TracBrowser for help on using the repository browser.