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