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

Last change on this file since 1350 was 1348, checked in by mervart, 16 years ago

* empty log message *

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