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

Last change on this file since 1512 was 1472, checked in by weber, 16 years ago

* empty log message *

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