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