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