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