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

Last change on this file since 1359 was 1353, checked in by mervart, 17 years ago

* empty log message *

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