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