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

Last change on this file since 1471 was 1471, checked in by weber, 15 years ago

* empty log message *

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