| 1 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2007
|
|---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 6 | // http://www.bkg.bund.de
|
|---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 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.
|
|---|
| 24 |
|
|---|
| 25 | /* -------------------------------------------------------------------------
|
|---|
| 26 | * BKG NTRIP Client
|
|---|
| 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 |
|
|---|
| 41 | #include <stdlib.h>
|
|---|
| 42 | #include <iomanip>
|
|---|
| 43 | #include <sstream>
|
|---|
| 44 |
|
|---|
| 45 | #include <QFile>
|
|---|
| 46 | #include <QTextStream>
|
|---|
| 47 | #include <QtNetwork>
|
|---|
| 48 | #include <QTime>
|
|---|
| 49 |
|
|---|
| 50 | #include "bncgetthread.h"
|
|---|
| 51 | #include "bnctabledlg.h"
|
|---|
| 52 | #include "bncapp.h"
|
|---|
| 53 | #include "bncutils.h"
|
|---|
| 54 | #include "bncrinex.h"
|
|---|
| 55 | #include "bnczerodecoder.h"
|
|---|
| 56 | #include "bncsocket.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "RTCM/RTCM2Decoder.h"
|
|---|
| 59 | #include "RTCM3/RTCM3Decoder.h"
|
|---|
| 60 | #include "RTIGS/RTIGSDecoder.h"
|
|---|
| 61 | #include "GPSS/gpssDecoder.h"
|
|---|
| 62 | #include "serial/qextserialport.h"
|
|---|
| 63 |
|
|---|
| 64 | using namespace std;
|
|---|
| 65 |
|
|---|
| 66 | // Constructor 1
|
|---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 68 | bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
|
|---|
| 69 | const QByteArray& format) {
|
|---|
| 70 |
|
|---|
| 71 | _format = format;
|
|---|
| 72 |
|
|---|
| 73 | int iSep = rawInpFileName.lastIndexOf(QDir::separator());
|
|---|
| 74 | _staID = rawInpFileName.mid(iSep+1,4);
|
|---|
| 75 |
|
|---|
| 76 | initialize();
|
|---|
| 77 |
|
|---|
| 78 | _inspSegm = 0;
|
|---|
| 79 |
|
|---|
| 80 | _rawInpFile = new QFile(rawInpFileName);
|
|---|
| 81 | _rawInpFile->open(QIODevice::ReadOnly);
|
|---|
| 82 |
|
|---|
| 83 | if (!_rnx) {
|
|---|
| 84 | cerr << "no RINEX path specified" << endl;
|
|---|
| 85 | ::exit(0);
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | // Constructor 2
|
|---|
| 90 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 91 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
|---|
| 92 | const QByteArray& format,
|
|---|
| 93 | const QByteArray& latitude,
|
|---|
| 94 | const QByteArray& longitude,
|
|---|
| 95 | const QByteArray& nmea,
|
|---|
| 96 | const QByteArray& ntripVersion, int iMount) {
|
|---|
| 97 |
|
|---|
| 98 | setTerminationEnabled(true);
|
|---|
| 99 |
|
|---|
| 100 | _mountPoint = mountPoint;
|
|---|
| 101 | _staID = mountPoint.path().mid(1).toAscii();
|
|---|
| 102 | _format = format;
|
|---|
| 103 | _latitude = latitude;
|
|---|
| 104 | _longitude = longitude;
|
|---|
| 105 | _nmea = nmea;
|
|---|
| 106 | _ntripVersion = ntripVersion;
|
|---|
| 107 | _iMount = iMount; // index in mountpoints array
|
|---|
| 108 |
|
|---|
| 109 | initialize();
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // Initialization
|
|---|
| 113 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 114 | void bncGetThread::initialize() {
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | bncApp* app = (bncApp*) qApp;
|
|---|
| 118 | app->connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 119 | app, SLOT(slotMessage(const QByteArray,bool)));
|
|---|
| 120 |
|
|---|
| 121 | _decoder = 0;
|
|---|
| 122 | _socket = 0;
|
|---|
| 123 | _timeOut = 20*1000; // 20 seconds
|
|---|
| 124 | _nextSleep = 1; // 1 second
|
|---|
| 125 | _rawInpFile = 0;
|
|---|
| 126 | _rawOutFile = 0;
|
|---|
| 127 | _staID_orig = _staID;
|
|---|
| 128 |
|
|---|
| 129 | // Check name conflict
|
|---|
| 130 | // -------------------
|
|---|
| 131 | QSettings settings;
|
|---|
| 132 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
|---|
| 133 | int num = 0;
|
|---|
| 134 | int ind = -1;
|
|---|
| 135 | while (it.hasNext()) {
|
|---|
| 136 | ++ind;
|
|---|
| 137 | QStringList hlp = it.next().split(" ");
|
|---|
| 138 | if (hlp.size() <= 1) continue;
|
|---|
| 139 | QUrl url(hlp[0]);
|
|---|
| 140 | if (_mountPoint.path() == url.path()) {
|
|---|
| 141 | if (_iMount > ind || _iMount < 0) {
|
|---|
| 142 | ++num;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | if (num > 0) {
|
|---|
| 148 | _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | // Notice threshold
|
|---|
| 152 | // ----------------
|
|---|
| 153 | _inspSegm = 50;
|
|---|
| 154 | if ( settings.value("obsRate").toString().isEmpty() ) { _inspSegm = 0; }
|
|---|
| 155 | if ( settings.value("obsRate").toString().indexOf("5 Hz") != -1 ) { _inspSegm = 2; }
|
|---|
| 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; }
|
|---|
| 160 | _adviseFail = settings.value("adviseFail").toInt();
|
|---|
| 161 | _adviseReco = settings.value("adviseReco").toInt();
|
|---|
| 162 | _makePause = false;
|
|---|
| 163 | if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {_makePause = true; }
|
|---|
| 164 | _adviseScript = settings.value("adviseScript").toString();
|
|---|
| 165 | expandEnvVar(_adviseScript);
|
|---|
| 166 |
|
|---|
| 167 | // Latency interval/average
|
|---|
| 168 | // ------------------------
|
|---|
| 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; }
|
|---|
| 177 |
|
|---|
| 178 | // RTCM message types
|
|---|
| 179 | // ------------------
|
|---|
| 180 | _checkMountPoint = settings.value("miscMount").toString();
|
|---|
| 181 |
|
|---|
| 182 | // RINEX writer
|
|---|
| 183 | // ------------
|
|---|
| 184 | _samplingRate = settings.value("rnxSampl").toInt();
|
|---|
| 185 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
|---|
| 186 | _rnx = 0;
|
|---|
| 187 | }
|
|---|
| 188 | else {
|
|---|
| 189 | _rnx = new bncRinex(_staID, _mountPoint, _format, _latitude,
|
|---|
| 190 | _longitude, _nmea, _ntripVersion);
|
|---|
| 191 | }
|
|---|
| 192 | _rnx_set_position = false;
|
|---|
| 193 |
|
|---|
| 194 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
|---|
| 195 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
|---|
| 196 |
|
|---|
| 197 | if (settings.value("serialMountPoint").toString() == _staID) {
|
|---|
| 198 | _serialPort = new QextSerialPort(
|
|---|
| 199 | settings.value("serialPortName").toString() );
|
|---|
| 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 | }
|
|---|
| 267 | _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
|
|---|
| 268 | if (!_serialPort->isOpen()) {
|
|---|
| 269 | delete _serialPort;
|
|---|
| 270 | _serialPort = 0;
|
|---|
| 271 | emit(newMessage((_staID + ": Cannot Open Serial Port\n"), true));
|
|---|
| 272 | }
|
|---|
| 273 | }
|
|---|
| 274 | else {
|
|---|
| 275 | _serialPort = 0;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | // Raw Output
|
|---|
| 279 | // ----------
|
|---|
| 280 | // QByteArray rawOutFileName = "./" + _staID + ".raw";
|
|---|
| 281 | // _rawOutFile = new QFile(rawOutFileName);
|
|---|
| 282 | // _rawOutFile->open(QIODevice::WriteOnly);
|
|---|
| 283 |
|
|---|
| 284 | msleep(100); //sleep 0.1 sec
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | // Destructor
|
|---|
| 288 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 289 | bncGetThread::~bncGetThread() {
|
|---|
| 290 | if (_socket) {
|
|---|
| 291 | _socket->close();
|
|---|
| 292 | #if QT_VERSION == 0x040203
|
|---|
| 293 | delete _socket;
|
|---|
| 294 | #else
|
|---|
| 295 | _socket->deleteLater();
|
|---|
| 296 | #endif
|
|---|
| 297 | }
|
|---|
| 298 | delete _decoder;
|
|---|
| 299 | delete _rnx;
|
|---|
| 300 | delete _rawInpFile;
|
|---|
| 301 | delete _rawOutFile;
|
|---|
| 302 | delete _serialPort;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | // Init Run
|
|---|
| 306 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 307 | t_irc bncGetThread::initRun() {
|
|---|
| 308 |
|
|---|
| 309 | if (!_rawInpFile) {
|
|---|
| 310 |
|
|---|
| 311 | // Initialize Socket
|
|---|
| 312 | // -----------------
|
|---|
| 313 | QString msg;
|
|---|
| 314 | delete _socket;
|
|---|
| 315 | _socket = new bncSocket;
|
|---|
| 316 | if (_socket->request(_mountPoint, _latitude, _longitude,
|
|---|
| 317 | _nmea, _ntripVersion, _timeOut, msg) != success) {
|
|---|
| 318 | delete _socket;
|
|---|
| 319 | _socket = 0;
|
|---|
| 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 | }
|
|---|
| 343 | }
|
|---|
| 344 | else {
|
|---|
| 345 | _socket->waitForReadyRead(_timeOut);
|
|---|
| 346 | if (_socket->bytesAvailable() <= 0) {
|
|---|
| 347 | break;
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | if (line.indexOf("Unauthorized") != -1) {
|
|---|
| 354 | QStringList table;
|
|---|
| 355 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
|
|---|
| 356 | _ntripVersion, table);
|
|---|
| 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 | }
|
|---|
| 367 | }
|
|---|
| 368 | }
|
|---|
| 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 | }
|
|---|
| 380 | }
|
|---|
| 381 | }
|
|---|
| 382 | emit(newMessage((_staID + ": Caster Response: " + line +
|
|---|
| 383 | " Adjust User-ID and Password Register, see"
|
|---|
| 384 | "\n " + reg).toAscii(), true));
|
|---|
| 385 | return fatal;
|
|---|
| 386 | }
|
|---|
| 387 | if (line.indexOf("ICY 200 OK") != 0) {
|
|---|
| 388 | emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii(), true));
|
|---|
| 389 | return failure;
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 | else {
|
|---|
| 393 | emit(newMessage(_staID + ": Response Timeout", true));
|
|---|
| 394 | return failure;
|
|---|
| 395 | }
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | // Instantiate the filter
|
|---|
| 399 | // ----------------------
|
|---|
| 400 | if (!_decoder) {
|
|---|
| 401 | if (_format.indexOf("RTCM_2") != -1) {
|
|---|
| 402 | emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format", true));
|
|---|
| 403 | _decoder = new RTCM2Decoder(_staID.data());
|
|---|
| 404 | }
|
|---|
| 405 | else if (_format.indexOf("RTCM_3") != -1) {
|
|---|
| 406 | emit(newMessage("Get Data: " + _staID + " in RTCM 3.x format", true));
|
|---|
| 407 | _decoder = new RTCM3Decoder(_staID);
|
|---|
| 408 | connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 409 | this, SIGNAL(newMessage(QByteArray,bool)));
|
|---|
| 410 | }
|
|---|
| 411 | else if (_format.indexOf("RTIGS") != -1) {
|
|---|
| 412 | emit(newMessage("Get Data: " + _staID + " in RTIGS format", true));
|
|---|
| 413 | _decoder = new RTIGSDecoder();
|
|---|
| 414 | }
|
|---|
| 415 | else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
|
|---|
| 416 | emit(newMessage("Get Data: " + _staID + " in GPSS format", true));
|
|---|
| 417 | _decoder = new gpssDecoder();
|
|---|
| 418 | }
|
|---|
| 419 | else if (_format.indexOf("ZERO") != -1) {
|
|---|
| 420 | emit(newMessage("Get Data: " + _staID + " in original format", true));
|
|---|
| 421 | _decoder = new bncZeroDecoder(_staID);
|
|---|
| 422 | }
|
|---|
| 423 | else {
|
|---|
| 424 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
|---|
| 425 | if (_rawInpFile) {
|
|---|
| 426 | cerr << "Uknown data format" << endl;
|
|---|
| 427 | ::exit(0);
|
|---|
| 428 | }
|
|---|
| 429 | else {
|
|---|
| 430 | return fatal;
|
|---|
| 431 | }
|
|---|
| 432 | }
|
|---|
| 433 | }
|
|---|
| 434 | return success;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | // Run
|
|---|
| 438 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 439 | void bncGetThread::run() {
|
|---|
| 440 |
|
|---|
| 441 | const double maxDt = 600.0; // Check observation epoch
|
|---|
| 442 | bool wrongEpoch = false;
|
|---|
| 443 | bool decode = true;
|
|---|
| 444 | int numSucc = 0;
|
|---|
| 445 | int secSucc = 0;
|
|---|
| 446 | int secFail = 0;
|
|---|
| 447 | int initPause = 30; // Initial pause for corrupted streams
|
|---|
| 448 | int currPause = 0;
|
|---|
| 449 | bool begCorrupt = false;
|
|---|
| 450 | bool endCorrupt = false;
|
|---|
| 451 | bool followSec = false;
|
|---|
| 452 | int oldSecGPS= 0;
|
|---|
| 453 | int newSecGPS = 0;
|
|---|
| 454 | int numGaps = 0;
|
|---|
| 455 | int diffSecGPS = 0;
|
|---|
| 456 | int numLat = 0;
|
|---|
| 457 | double sumLat = 0.;
|
|---|
| 458 | double sumLatQ = 0.;
|
|---|
| 459 | double meanDiff = 0.;
|
|---|
| 460 | double minLat = maxDt;
|
|---|
| 461 | double maxLat = -maxDt;
|
|---|
| 462 | double curLat = 0.;
|
|---|
| 463 |
|
|---|
| 464 | _decodeTime = QDateTime::currentDateTime();
|
|---|
| 465 | _decodeSucc = QDateTime::currentDateTime();
|
|---|
| 466 | t_irc irc = initRun();
|
|---|
| 467 |
|
|---|
| 468 | if (irc == fatal) {
|
|---|
| 469 | QThread::exit(1);
|
|---|
| 470 | return;
|
|---|
| 471 | }
|
|---|
| 472 | else if (irc != success) {
|
|---|
| 473 | emit(newMessage(_staID + ": initRun failed, reconnecting", true));
|
|---|
| 474 | tryReconnect();
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | if (initPause < _inspSegm) {
|
|---|
| 478 | initPause = _inspSegm;
|
|---|
| 479 | }
|
|---|
| 480 | if(!_makePause) {initPause = 0;}
|
|---|
| 481 | currPause = initPause;
|
|---|
| 482 |
|
|---|
| 483 | // Read Incoming Data
|
|---|
| 484 | // ------------------
|
|---|
| 485 | while (true) {
|
|---|
| 486 | try {
|
|---|
| 487 | if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
|
|---|
| 488 | emit(newMessage(_staID + ": Socket not connected, reconnecting", true));
|
|---|
| 489 | tryReconnect();
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | QListIterator<p_obs> it(_decoder->_obsList);
|
|---|
| 493 | while (it.hasNext()) {
|
|---|
| 494 | delete it.next();
|
|---|
| 495 | }
|
|---|
| 496 | _decoder->_obsList.clear();
|
|---|
| 497 |
|
|---|
| 498 | qint64 nBytes = 0;
|
|---|
| 499 |
|
|---|
| 500 | if (_socket) {
|
|---|
| 501 | _socket->waitForReadyRead(_timeOut);
|
|---|
| 502 | nBytes = _socket->bytesAvailable();
|
|---|
| 503 | }
|
|---|
| 504 | else if (_rawInpFile) {
|
|---|
| 505 | const qint64 maxBytes = 1024;
|
|---|
| 506 | nBytes = maxBytes;
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | if (nBytes > 0) {
|
|---|
| 510 | emit newBytes(_staID, nBytes);
|
|---|
| 511 |
|
|---|
| 512 | char* data = new char[nBytes];
|
|---|
| 513 |
|
|---|
| 514 | if (_socket) {
|
|---|
| 515 | _socket->read(data, nBytes);
|
|---|
| 516 | }
|
|---|
| 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 | }
|
|---|
| 524 |
|
|---|
| 525 | if (_rawOutFile) {
|
|---|
| 526 | _rawOutFile->write(data, nBytes);
|
|---|
| 527 | _rawOutFile->flush();
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | if (_serialPort) {
|
|---|
| 531 | _serialPort->write(data, nBytes);
|
|---|
| 532 | //// _serialPort->flush();
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | if (_inspSegm<1) {
|
|---|
| 536 | vector<string> errmsg;
|
|---|
| 537 | _decoder->Decode(data, nBytes, errmsg);
|
|---|
| 538 | #ifdef DEBUG_RTCM2_2021
|
|---|
| 539 | for (unsigned ii = 0; ii < errmsg.size(); ii++) {
|
|---|
| 540 | emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
|
|---|
| 541 | }
|
|---|
| 542 | #endif
|
|---|
| 543 | }
|
|---|
| 544 | else {
|
|---|
| 545 |
|
|---|
| 546 | // Decode data
|
|---|
| 547 | // -----------
|
|---|
| 548 | if (!_decodePause.isValid() ||
|
|---|
| 549 | _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause ) {
|
|---|
| 550 |
|
|---|
| 551 | if (decode) {
|
|---|
| 552 | vector<string> errmsg;
|
|---|
| 553 | if ( _decoder->Decode(data, nBytes, errmsg) == success ) {
|
|---|
| 554 | numSucc += 1;
|
|---|
| 555 | }
|
|---|
| 556 | if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) {
|
|---|
| 557 | decode = false;
|
|---|
| 558 | }
|
|---|
| 559 | #ifdef DEBUG_RTCM2_2021
|
|---|
| 560 | for (unsigned ii = 0; ii < errmsg.size(); ii++) {
|
|---|
| 561 | emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
|
|---|
| 562 | }
|
|---|
| 563 | #endif
|
|---|
| 564 | }
|
|---|
| 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());
|
|---|
| 580 | }
|
|---|
| 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 | }
|
|---|
| 599 | }
|
|---|
| 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");
|
|---|
| 606 | emit(newMessage((_staID + ": Recovery threshold exceeded, corruption ended "
|
|---|
| 607 | + _endDateCor + " " + _endTimeCor).toAscii(), true));
|
|---|
| 608 | callScript(("End_Corrupted " + _endDateCor + " " + _endTimeCor + " Begin was " + _begDateCor + " " + _begTimeCor).toAscii());
|
|---|
| 609 | endCorrupt = true;
|
|---|
| 610 | begCorrupt = false;
|
|---|
| 611 | secFail = 0;
|
|---|
| 612 | }
|
|---|
| 613 | else {
|
|---|
| 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");
|
|---|
| 620 | emit(newMessage((_staID + ": Failure threshold exceeded, corrupted since "
|
|---|
| 621 | + _begDateCor + " " + _begTimeCor).toAscii(), true));
|
|---|
| 622 | callScript(("Begin_Corrupted " + _begDateCor + " " + _begTimeCor).toAscii());
|
|---|
| 623 | begCorrupt = true;
|
|---|
| 624 | endCorrupt = false;
|
|---|
| 625 | secSucc = 0;
|
|---|
| 626 | numSucc = 0;
|
|---|
| 627 | }
|
|---|
| 628 | }
|
|---|
| 629 | decode = true;
|
|---|
| 630 | }
|
|---|
| 631 | }
|
|---|
| 632 | }
|
|---|
| 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");
|
|---|
| 642 | emit(newMessage((_staID + ": Recovery threshold exceeded, outage ended "
|
|---|
| 643 | + _endDateOut + " " + _endTimeOut).toAscii(), true));
|
|---|
| 644 | callScript(("End_Outage " + _endDateOut + " " + _endTimeOut + " Begin was " + _begDateOut + " " + _begTimeOut).toAscii());
|
|---|
| 645 | }
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | delete [] data;
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 | // RTCM scan output
|
|---|
| 652 | // ----------------
|
|---|
| 653 | if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
|
|---|
| 654 | QSettings settings;
|
|---|
| 655 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked) {
|
|---|
| 656 |
|
|---|
| 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 | }
|
|---|
| 665 | }
|
|---|
| 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 | }
|
|---|
| 675 | }
|
|---|
| 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 | }
|
|---|
| 701 | }
|
|---|
| 702 | if ( _checkMountPoint == "ANTCRD_ONLY" && _decoder->_antList.size() ) {
|
|---|
| 703 | for (int ii=0;ii<_decoder->_antList.size();++ii) {
|
|---|
| 704 | QByteArray antT;
|
|---|
| 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,
|
|---|
| 710 | _decoder->_antList[ii].xx, _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
|---|
| 711 | antT));
|
|---|
| 712 | }
|
|---|
| 713 | }
|
|---|
| 714 | }
|
|---|
| 715 |
|
|---|
| 716 | _decoder->_typeList.clear();
|
|---|
| 717 | _decoder->_antType.clear();
|
|---|
| 718 | _decoder->_antList.clear();
|
|---|
| 719 |
|
|---|
| 720 | // Loop over all observations (observations output)
|
|---|
| 721 | // ------------------------------------------------
|
|---|
| 722 | QListIterator<p_obs> it(_decoder->_obsList);
|
|---|
| 723 | while (it.hasNext()) {
|
|---|
| 724 | p_obs obs = it.next();
|
|---|
| 725 |
|
|---|
| 726 | // Check observation epoch
|
|---|
| 727 | // -----------------------
|
|---|
| 728 | if (!_rawInpFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
|
|---|
| 729 | int week;
|
|---|
| 730 | double sec;
|
|---|
| 731 | currentGPSWeeks(week, sec);
|
|---|
| 732 | const double secPerWeek = 7.0 * 24.0 * 3600.0;
|
|---|
| 733 |
|
|---|
| 734 | if (week < obs->_o.GPSWeek) {
|
|---|
| 735 | week += 1;
|
|---|
| 736 | sec -= secPerWeek;
|
|---|
| 737 | }
|
|---|
| 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) {
|
|---|
| 745 | emit( newMessage(_staID + ": Wrong observation epoch(s)", true) );
|
|---|
| 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) {
|
|---|
| 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 | }
|
|---|
| 782 | }
|
|---|
| 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;
|
|---|
| 791 | }
|
|---|
| 792 | if (followSec) {
|
|---|
| 793 | diffSecGPS += newSecGPS - oldSecGPS;
|
|---|
| 794 | if (meanDiff>0.) {
|
|---|
| 795 | if (newSecGPS - oldSecGPS > 1.5 * meanDiff) {
|
|---|
| 796 | numGaps += 1;
|
|---|
| 797 | }
|
|---|
| 798 | }
|
|---|
| 799 | }
|
|---|
| 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;
|
|---|
| 808 | }
|
|---|
| 809 | }
|
|---|
| 810 | }
|
|---|
| 811 | }
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | // RINEX Output
|
|---|
| 815 | // ------------
|
|---|
| 816 | if (_rnx) {
|
|---|
| 817 | bool dump = true;
|
|---|
| 818 |
|
|---|
| 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 | //// }
|
|---|
| 853 |
|
|---|
| 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);
|
|---|
| 861 | }
|
|---|
| 862 | }
|
|---|
| 863 |
|
|---|
| 864 | // Emit new observation signal
|
|---|
| 865 | // ---------------------------
|
|---|
| 866 | bool firstObs = (obs == _decoder->_obsList.first());
|
|---|
| 867 | obs->_status = t_obs::posted;
|
|---|
| 868 | emit newObs(_staID, firstObs, obs);
|
|---|
| 869 | }
|
|---|
| 870 | _decoder->_obsList.clear();
|
|---|
| 871 |
|
|---|
| 872 | }
|
|---|
| 873 |
|
|---|
| 874 | // Timeout, reconnect
|
|---|
| 875 | // ------------------
|
|---|
| 876 | else {
|
|---|
| 877 | emit(newMessage(_staID + ": Data Timeout, reconnecting", true));
|
|---|
| 878 | tryReconnect();
|
|---|
| 879 | }
|
|---|
| 880 | }
|
|---|
| 881 | catch (const char* msg) {
|
|---|
| 882 | emit(newMessage(_staID + msg, true));
|
|---|
| 883 | tryReconnect();
|
|---|
| 884 | }
|
|---|
| 885 | }
|
|---|
| 886 | }
|
|---|
| 887 |
|
|---|
| 888 | // Exit
|
|---|
| 889 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 890 | void bncGetThread::exit(int exitCode) {
|
|---|
| 891 | if (exitCode!= 0) {
|
|---|
| 892 | emit error(_staID);
|
|---|
| 893 | }
|
|---|
| 894 | QThread::exit(exitCode);
|
|---|
| 895 | terminate();
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | // Try Re-Connect
|
|---|
| 899 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 900 | void bncGetThread::tryReconnect() {
|
|---|
| 901 | if (_rnx) {
|
|---|
| 902 | _rnx->setReconnectFlag(true);
|
|---|
| 903 | }
|
|---|
| 904 | if ( !_decodeStart.isValid()) {
|
|---|
| 905 | _decodeStop = QDateTime::currentDateTime();
|
|---|
| 906 | }
|
|---|
| 907 | while (1) {
|
|---|
| 908 | sleep(_nextSleep);
|
|---|
| 909 | if ( initRun() == success ) {
|
|---|
| 910 | if ( !_decodeStop.isValid()) {
|
|---|
| 911 | _decodeStart = QDateTime::currentDateTime();
|
|---|
| 912 | }
|
|---|
| 913 | break;
|
|---|
| 914 | }
|
|---|
| 915 | else {
|
|---|
| 916 |
|
|---|
| 917 | // Begin outage threshold
|
|---|
| 918 | // ----------------------
|
|---|
| 919 | if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _adviseFail * 60 ) {
|
|---|
| 920 | _decodeStop.setDate(QDate());
|
|---|
| 921 | _decodeStop.setTime(QTime());
|
|---|
| 922 | if (_inspSegm>0) {
|
|---|
| 923 | _begDateOut = _decodeTime.toUTC().date().toString("yy-MM-dd");
|
|---|
| 924 | _begTimeOut = _decodeTime.toUTC().time().toString("hh:mm:ss");
|
|---|
| 925 | emit(newMessage((_staID + ": Failure threshold exceeded, outage since "
|
|---|
| 926 | + _begDateOut + " " + _begTimeOut).toAscii(), true));
|
|---|
| 927 | callScript(("Begin_Outage " + _begDateOut + " " + _begTimeOut).toAscii());
|
|---|
| 928 | }
|
|---|
| 929 | }
|
|---|
| 930 | _nextSleep *= 2;
|
|---|
| 931 | if (_nextSleep > 256) {
|
|---|
| 932 | _nextSleep = 256;
|
|---|
| 933 | }
|
|---|
| 934 | _nextSleep += rand() % 6;
|
|---|
| 935 | }
|
|---|
| 936 | }
|
|---|
| 937 | _nextSleep = 1;
|
|---|
| 938 | }
|
|---|
| 939 |
|
|---|
| 940 | // Call advisory notice script
|
|---|
| 941 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 942 | void bncGetThread::callScript(const char* _comment) {
|
|---|
| 943 | QMutexLocker locker(&_mutex);
|
|---|
| 944 | if (!_adviseScript.isEmpty()) {
|
|---|
| 945 | msleep(1);
|
|---|
| 946 | #ifdef WIN32
|
|---|
| 947 | QProcess::startDetached(_adviseScript, QStringList() << _staID << _comment) ;
|
|---|
| 948 | #else
|
|---|
| 949 | QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << _comment) ;
|
|---|
| 950 | #endif
|
|---|
| 951 | }
|
|---|
| 952 | }
|
|---|
| 953 |
|
|---|
| 954 | //
|
|---|
| 955 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 956 | void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
|
|---|
| 957 | RTCM2Decoder* decoder = dynamic_cast<RTCM2Decoder*>(_decoder);
|
|---|
| 958 |
|
|---|
| 959 | if ( decoder ) {
|
|---|
| 960 | QMutexLocker locker(&_mutex);
|
|---|
| 961 |
|
|---|
| 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 |
|
|---|
| 973 | emit(newMessage(msg.toAscii(), false));
|
|---|
| 974 | #endif
|
|---|
| 975 | }
|
|---|
| 976 | }
|
|---|
| 977 | }
|
|---|
| 978 |
|
|---|