[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"
|
---|
[35] | 60 |
|
---|
| 61 | using namespace std;
|
---|
| 62 |
|
---|
[1143] | 63 | // Constructor 1
|
---|
[35] | 64 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1138] | 65 | bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
|
---|
| 66 | const QByteArray& format) {
|
---|
| 67 |
|
---|
[1141] | 68 | _format = format;
|
---|
[1139] | 69 |
|
---|
[1159] | 70 | int iSep = rawInpFileName.lastIndexOf(QDir::separator());
|
---|
| 71 | _staID = rawInpFileName.mid(iSep+1,4);
|
---|
| 72 |
|
---|
[1139] | 73 | initialize();
|
---|
| 74 |
|
---|
| 75 | _inspSegm = 0;
|
---|
| 76 |
|
---|
[1138] | 77 | _rawInpFile = new QFile(rawInpFileName);
|
---|
| 78 | _rawInpFile->open(QIODevice::ReadOnly);
|
---|
[1147] | 79 |
|
---|
| 80 | if (!_rnx) {
|
---|
| 81 | cerr << "no RINEX path specified" << endl;
|
---|
| 82 | ::exit(0);
|
---|
| 83 | }
|
---|
[1138] | 84 | }
|
---|
| 85 |
|
---|
[1143] | 86 | // Constructor 2
|
---|
| 87 | ////////////////////////////////////////////////////////////////////////////
|
---|
[278] | 88 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
---|
[366] | 89 | const QByteArray& format,
|
---|
| 90 | const QByteArray& latitude,
|
---|
| 91 | const QByteArray& longitude,
|
---|
| 92 | const QByteArray& nmea, int iMount) {
|
---|
[605] | 93 |
|
---|
| 94 | setTerminationEnabled(true);
|
---|
| 95 |
|
---|
[350] | 96 | _mountPoint = mountPoint;
|
---|
| 97 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
| 98 | _format = format;
|
---|
[366] | 99 | _latitude = latitude;
|
---|
| 100 | _longitude = longitude;
|
---|
| 101 | _nmea = nmea;
|
---|
[1139] | 102 | _iMount = iMount; // index in mountpoints array
|
---|
| 103 |
|
---|
| 104 | initialize();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[1143] | 107 | // Initialization
|
---|
| 108 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1139] | 109 | void bncGetThread::initialize() {
|
---|
| 110 |
|
---|
| 111 | _decoder = 0;
|
---|
[350] | 112 | _socket = 0;
|
---|
[1139] | 113 | _timeOut = 20*1000; // 20 seconds
|
---|
| 114 | _nextSleep = 1; // 1 second
|
---|
[1138] | 115 | _rawInpFile = 0;
|
---|
[1139] | 116 | _rawOutFile = 0;
|
---|
[1143] | 117 | _staID_orig = _staID;
|
---|
[255] | 118 |
|
---|
| 119 | // Check name conflict
|
---|
| 120 | // -------------------
|
---|
| 121 | QSettings settings;
|
---|
| 122 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 123 | int num = 0;
|
---|
[278] | 124 | int ind = -1;
|
---|
[255] | 125 | while (it.hasNext()) {
|
---|
[278] | 126 | ++ind;
|
---|
[255] | 127 | QStringList hlp = it.next().split(" ");
|
---|
| 128 | if (hlp.size() <= 1) continue;
|
---|
| 129 | QUrl url(hlp[0]);
|
---|
| 130 | if (_mountPoint.path() == url.path()) {
|
---|
[1162] | 131 | if (_iMount > ind || _iMount < 0) {
|
---|
[278] | 132 | ++num;
|
---|
[255] | 133 | }
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
[278] | 136 |
|
---|
| 137 | if (num > 0) {
|
---|
| 138 | _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
|
---|
[255] | 139 | }
|
---|
[408] | 140 |
|
---|
[658] | 141 | // Notice threshold
|
---|
| 142 | // ----------------
|
---|
[686] | 143 | _inspSegm = 50;
|
---|
| 144 | if ( settings.value("obsRate").toString().isEmpty() ) { _inspSegm = 0; }
|
---|
[692] | 145 | if ( settings.value("obsRate").toString().indexOf("5 Hz") != -1 ) { _inspSegm = 2; }
|
---|
[686] | 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; }
|
---|
[668] | 150 | _adviseFail = settings.value("adviseFail").toInt();
|
---|
| 151 | _adviseReco = settings.value("adviseReco").toInt();
|
---|
[722] | 152 | _makePause = false;
|
---|
| 153 | if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {_makePause = true; }
|
---|
[668] | 154 | _adviseScript = settings.value("adviseScript").toString();
|
---|
| 155 | expandEnvVar(_adviseScript);
|
---|
[658] | 156 |
|
---|
[709] | 157 | // Latency interval/average
|
---|
| 158 | // ------------------------
|
---|
[728] | 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; }
|
---|
[709] | 167 |
|
---|
[1030] | 168 | // RTCM message types
|
---|
| 169 | // ------------------
|
---|
| 170 | _checkMountPoint = settings.value("messTypes").toString();
|
---|
| 171 |
|
---|
[408] | 172 | // RINEX writer
|
---|
| 173 | // ------------
|
---|
| 174 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
| 175 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
| 176 | _rnx = 0;
|
---|
| 177 | }
|
---|
| 178 | else {
|
---|
[1139] | 179 | _rnx = new bncRinex(_staID, _mountPoint,
|
---|
| 180 | _format, _latitude, _longitude, _nmea);
|
---|
[408] | 181 | }
|
---|
[1044] | 182 | _rnx_set_position = false;
|
---|
[408] | 183 |
|
---|
[1168] | 184 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
| 185 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
| 186 |
|
---|
[1137] | 187 | // Raw Output
|
---|
| 188 | // ----------
|
---|
[1140] | 189 | // QByteArray rawOutFileName = "./" + _staID + ".raw";
|
---|
| 190 | // _rawOutFile = new QFile(rawOutFileName);
|
---|
| 191 | // _rawOutFile->open(QIODevice::WriteOnly);
|
---|
[1137] | 192 |
|
---|
[319] | 193 | msleep(100); //sleep 0.1 sec
|
---|
[35] | 194 | }
|
---|
| 195 |
|
---|
| 196 | // Destructor
|
---|
| 197 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 198 | bncGetThread::~bncGetThread() {
|
---|
[515] | 199 | if (_socket) {
|
---|
| 200 | _socket->close();
|
---|
[613] | 201 | #if QT_VERSION == 0x040203
|
---|
| 202 | delete _socket;
|
---|
| 203 | #else
|
---|
[612] | 204 | _socket->deleteLater();
|
---|
[613] | 205 | #endif
|
---|
[515] | 206 | }
|
---|
[617] | 207 | delete _decoder;
|
---|
[1044] | 208 | delete _rnx;
|
---|
[1138] | 209 | delete _rawInpFile;
|
---|
| 210 | delete _rawOutFile;
|
---|
[35] | 211 | }
|
---|
| 212 |
|
---|
[841] | 213 | #define AGENTVERSION "1.6"
|
---|
[35] | 214 | // Connect to Caster, send the Request (static)
|
---|
| 215 | ////////////////////////////////////////////////////////////////////////////
|
---|
[366] | 216 | QTcpSocket* bncGetThread::request(const QUrl& mountPoint,
|
---|
| 217 | QByteArray& latitude, QByteArray& longitude,
|
---|
| 218 | QByteArray& nmea, int timeOut,
|
---|
[136] | 219 | QString& msg) {
|
---|
[35] | 220 |
|
---|
[88] | 221 | // Connect the Socket
|
---|
| 222 | // ------------------
|
---|
| 223 | QSettings settings;
|
---|
| 224 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
| 225 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
| 226 |
|
---|
[35] | 227 | QTcpSocket* socket = new QTcpSocket();
|
---|
| 228 | if ( proxyHost.isEmpty() ) {
|
---|
[88] | 229 | socket->connectToHost(mountPoint.host(), mountPoint.port());
|
---|
[35] | 230 | }
|
---|
| 231 | else {
|
---|
| 232 | socket->connectToHost(proxyHost, proxyPort);
|
---|
| 233 | }
|
---|
| 234 | if (!socket->waitForConnected(timeOut)) {
|
---|
[82] | 235 | msg += "Connect timeout\n";
|
---|
[35] | 236 | delete socket;
|
---|
| 237 | return 0;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | // Send Request
|
---|
| 241 | // ------------
|
---|
[443] | 242 | QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());
|
---|
| 243 | QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());
|
---|
[645] | 244 | QByteArray userAndPwd;
|
---|
[92] | 245 |
|
---|
[645] | 246 | if(!uName.isEmpty() || !passW.isEmpty())
|
---|
| 247 | {
|
---|
| 248 | userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
|
---|
| 249 | passW.toAscii()).toBase64() + "\r\n";
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[92] | 252 | QUrl hlp;
|
---|
| 253 | hlp.setScheme("http");
|
---|
| 254 | hlp.setHost(mountPoint.host());
|
---|
| 255 | hlp.setPort(mountPoint.port());
|
---|
| 256 | hlp.setPath(mountPoint.path());
|
---|
| 257 |
|
---|
[214] | 258 | QByteArray reqStr;
|
---|
| 259 | if ( proxyHost.isEmpty() ) {
|
---|
[1020] | 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";
|
---|
[205] | 266 | }
|
---|
[645] | 267 | reqStr += "User-Agent: NTRIP BNC/" AGENTVERSION "\r\n"
|
---|
[1020] | 268 | "Host: " + hlp.host().toAscii() + "\r\n"
|
---|
| 269 | + userAndPwd + "\r\n";
|
---|
[205] | 270 |
|
---|
[1020] | 271 | // NMEA string to handle VRS stream
|
---|
| 272 | // --------------------------------
|
---|
[356] | 273 | double lat, lon;
|
---|
[366] | 274 |
|
---|
| 275 | lat = strtod(latitude,NULL);
|
---|
| 276 | lon = strtod(longitude,NULL);
|
---|
| 277 |
|
---|
[410] | 278 | if ((nmea == "yes") && (hlp.path().length() > 2) && (hlp.path().indexOf(".skl") < 0)) {
|
---|
[356] | 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";}
|
---|
[566] | 285 | QTime ttime(QDateTime::currentDateTime().toUTC().time());
|
---|
[356] | 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 |
|
---|
[82] | 315 | msg += reqStr;
|
---|
[35] | 316 |
|
---|
| 317 | socket->write(reqStr, reqStr.length());
|
---|
| 318 |
|
---|
| 319 | if (!socket->waitForBytesWritten(timeOut)) {
|
---|
[82] | 320 | msg += "Write timeout\n";
|
---|
[35] | 321 | delete socket;
|
---|
| 322 | return 0;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | return socket;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[136] | 328 | // Init Run
|
---|
[35] | 329 | ////////////////////////////////////////////////////////////////////////////
|
---|
[138] | 330 | t_irc bncGetThread::initRun() {
|
---|
[35] | 331 |
|
---|
[1138] | 332 | if (!_rawInpFile) {
|
---|
[35] | 333 |
|
---|
[1138] | 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 | }
|
---|
[473] | 363 | }
|
---|
[1138] | 364 | else {
|
---|
| 365 | _socket->waitForReadyRead(_timeOut);
|
---|
| 366 | if (_socket->bytesAvailable() <= 0) {
|
---|
| 367 | break;
|
---|
| 368 | }
|
---|
[473] | 369 | }
|
---|
| 370 | }
|
---|
[1138] | 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 | }
|
---|
[474] | 386 | }
|
---|
[473] | 387 | }
|
---|
[1138] | 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 | }
|
---|
[192] | 399 | }
|
---|
| 400 | }
|
---|
[1138] | 401 | emit(newMessage((_staID + ": Caster Response: " + line +
|
---|
| 402 | " Adjust User-ID and Password Register, see"
|
---|
| 403 | "\n " + reg).toAscii()));
|
---|
| 404 | return fatal;
|
---|
[192] | 405 | }
|
---|
[1138] | 406 | if (line.indexOf("ICY 200 OK") != 0) {
|
---|
| 407 | emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
|
---|
| 408 | return failure;
|
---|
[192] | 409 | }
|
---|
[146] | 410 | }
|
---|
[1138] | 411 | else {
|
---|
| 412 | emit(newMessage(_staID + ": Response Timeout"));
|
---|
[144] | 413 | return failure;
|
---|
[35] | 414 | }
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | // Instantiate the filter
|
---|
| 418 | // ----------------------
|
---|
[423] | 419 | if (!_decoder) {
|
---|
[136] | 420 | if (_format.indexOf("RTCM_2") != -1) {
|
---|
| 421 | emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format"));
|
---|
[1044] | 422 | _decoder = new RTCM2Decoder(_staID.data());
|
---|
[136] | 423 | }
|
---|
| 424 | else if (_format.indexOf("RTCM_3") != -1) {
|
---|
[569] | 425 | emit(newMessage("Get Data: " + _staID + " in RTCM 3.x format"));
|
---|
[880] | 426 | _decoder = new RTCM3Decoder(_staID);
|
---|
[1022] | 427 | connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray)),
|
---|
| 428 | this, SIGNAL(newMessage(QByteArray)));
|
---|
[136] | 429 | }
|
---|
| 430 | else if (_format.indexOf("RTIGS") != -1) {
|
---|
| 431 | emit(newMessage("Get Data: " + _staID + " in RTIGS format"));
|
---|
[293] | 432 | _decoder = new RTIGSDecoder();
|
---|
[136] | 433 | }
|
---|
[867] | 434 | else if (_format.indexOf("ZERO") != -1) {
|
---|
[428] | 435 | emit(newMessage("Get Data: " + _staID + " in original format"));
|
---|
[424] | 436 | _decoder = new bncZeroDecoder(_staID);
|
---|
[406] | 437 | }
|
---|
[136] | 438 | else {
|
---|
[190] | 439 | emit(newMessage(_staID + ": Unknown data format " + _format));
|
---|
[1144] | 440 | if (_rawInpFile) {
|
---|
[1145] | 441 | cerr << "Uknown data format" << endl;
|
---|
[1144] | 442 | ::exit(0);
|
---|
| 443 | }
|
---|
| 444 | else {
|
---|
| 445 | return fatal;
|
---|
| 446 | }
|
---|
[136] | 447 | }
|
---|
[60] | 448 | }
|
---|
[138] | 449 | return success;
|
---|
[136] | 450 | }
|
---|
[59] | 451 |
|
---|
[136] | 452 | // Run
|
---|
| 453 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 454 | void bncGetThread::run() {
|
---|
| 455 |
|
---|
[709] | 456 | const double maxDt = 600.0; // Check observation epoch
|
---|
[699] | 457 | bool wrongEpoch = false;
|
---|
| 458 | bool decode = true;
|
---|
| 459 | int numSucc = 0;
|
---|
| 460 | int secSucc = 0;
|
---|
| 461 | int secFail = 0;
|
---|
[709] | 462 | int initPause = 30; // Initial pause for corrupted streams
|
---|
[699] | 463 | int currPause = 0;
|
---|
| 464 | bool begCorrupt = false;
|
---|
| 465 | bool endCorrupt = false;
|
---|
[728] | 466 | bool followSec = false;
|
---|
[717] | 467 | int oldSecGPS= 0;
|
---|
| 468 | int newSecGPS = 0;
|
---|
[728] | 469 | int numGaps = 0;
|
---|
| 470 | int diffSecGPS = 0;
|
---|
[709] | 471 | int numLat = 0;
|
---|
| 472 | double sumLat = 0.;
|
---|
[1052] | 473 | double sumLatQ = 0.;
|
---|
[728] | 474 | double meanDiff = 0.;
|
---|
[709] | 475 | double minLat = maxDt;
|
---|
| 476 | double maxLat = -maxDt;
|
---|
| 477 | double curLat = 0.;
|
---|
[699] | 478 |
|
---|
| 479 | _decodeTime = QDateTime::currentDateTime();
|
---|
| 480 | _decodeSucc = QDateTime::currentDateTime();
|
---|
[229] | 481 | t_irc irc = initRun();
|
---|
| 482 |
|
---|
| 483 | if (irc == fatal) {
|
---|
[192] | 484 | QThread::exit(1);
|
---|
| 485 | return;
|
---|
| 486 | }
|
---|
[229] | 487 | else if (irc != success) {
|
---|
[190] | 488 | emit(newMessage(_staID + ": initRun failed, reconnecting"));
|
---|
[138] | 489 | tryReconnect();
|
---|
| 490 | }
|
---|
[136] | 491 |
|
---|
[658] | 492 | if (initPause < _inspSegm) {
|
---|
| 493 | initPause = _inspSegm;
|
---|
| 494 | }
|
---|
[727] | 495 | if(!_makePause) {initPause = 0;}
|
---|
[658] | 496 | currPause = initPause;
|
---|
| 497 |
|
---|
[35] | 498 | // Read Incoming Data
|
---|
| 499 | // ------------------
|
---|
| 500 | while (true) {
|
---|
[629] | 501 | try {
|
---|
[1138] | 502 | if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
|
---|
[629] | 503 | emit(newMessage(_staID + ": Socket not connected, reconnecting"));
|
---|
| 504 | tryReconnect();
|
---|
| 505 | }
|
---|
[621] | 506 |
|
---|
| 507 | QListIterator<p_obs> it(_decoder->_obsList);
|
---|
| 508 | while (it.hasNext()) {
|
---|
| 509 | delete it.next();
|
---|
| 510 | }
|
---|
| 511 | _decoder->_obsList.clear();
|
---|
| 512 |
|
---|
[1138] | 513 | qint64 nBytes = 0;
|
---|
| 514 |
|
---|
| 515 | if (_socket) {
|
---|
| 516 | _socket->waitForReadyRead(_timeOut);
|
---|
| 517 | nBytes = _socket->bytesAvailable();
|
---|
| 518 | }
|
---|
| 519 | else if (_rawInpFile) {
|
---|
[1146] | 520 | const qint64 maxBytes = 1024;
|
---|
[1138] | 521 | nBytes = maxBytes;
|
---|
| 522 | }
|
---|
| 523 |
|
---|
[249] | 524 | if (nBytes > 0) {
|
---|
[567] | 525 | emit newBytes(_staID, nBytes);
|
---|
| 526 |
|
---|
[249] | 527 | char* data = new char[nBytes];
|
---|
[406] | 528 |
|
---|
[1138] | 529 | if (_socket) {
|
---|
| 530 | _socket->read(data, nBytes);
|
---|
[1137] | 531 | }
|
---|
[1138] | 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 | }
|
---|
[1137] | 539 |
|
---|
[1138] | 540 | if (_rawOutFile) {
|
---|
| 541 | _rawOutFile->write(data, nBytes);
|
---|
| 542 | _rawOutFile->flush();
|
---|
| 543 | }
|
---|
| 544 |
|
---|
[940] | 545 | if (_inspSegm<1) {
|
---|
[1218] | 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
|
---|
[940] | 553 | }
|
---|
| 554 | else {
|
---|
| 555 |
|
---|
| 556 | // Decode data
|
---|
| 557 | // -----------
|
---|
| 558 | if (!_decodePause.isValid() ||
|
---|
| 559 | _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause ) {
|
---|
| 560 |
|
---|
| 561 | if (decode) {
|
---|
[1218] | 562 | vector<string> errmsg;
|
---|
| 563 | if ( _decoder->Decode(data, nBytes, errmsg) == success ) {
|
---|
[940] | 564 | numSucc += 1;
|
---|
| 565 | }
|
---|
| 566 | if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) {
|
---|
| 567 | decode = false;
|
---|
[658] | 568 | }
|
---|
[1218] | 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
|
---|
[658] | 574 | }
|
---|
[940] | 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());
|
---|
[658] | 590 | }
|
---|
[940] | 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 | }
|
---|
[658] | 609 | }
|
---|
[940] | 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 | }
|
---|
[658] | 622 | else {
|
---|
[940] | 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;
|
---|
[658] | 635 | }
|
---|
| 636 | }
|
---|
[940] | 637 | decode = true;
|
---|
[658] | 638 | }
|
---|
[650] | 639 | }
|
---|
| 640 | }
|
---|
[940] | 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 | }
|
---|
[686] | 653 | }
|
---|
[658] | 654 |
|
---|
[331] | 655 | delete [] data;
|
---|
[1044] | 656 |
|
---|
[621] | 657 | QListIterator<p_obs> it(_decoder->_obsList);
|
---|
| 658 | while (it.hasNext()) {
|
---|
| 659 | p_obs obs = it.next();
|
---|
| 660 |
|
---|
[351] | 661 | // Check observation epoch
|
---|
| 662 | // -----------------------
|
---|
[1142] | 663 | if (!_rawInpFile) {
|
---|
| 664 | int week;
|
---|
| 665 | double sec;
|
---|
[1153] | 666 | currentGPSWeeks(week, sec);
|
---|
[1142] | 667 | const double secPerWeek = 7.0 * 24.0 * 3600.0;
|
---|
| 668 |
|
---|
| 669 | if (week < obs->_o.GPSWeek) {
|
---|
| 670 | week += 1;
|
---|
| 671 | sec -= secPerWeek;
|
---|
[658] | 672 | }
|
---|
[1142] | 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 | }
|
---|
[728] | 716 | }
|
---|
[1142] | 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;
|
---|
[709] | 725 | }
|
---|
[1142] | 726 | if (followSec) {
|
---|
| 727 | diffSecGPS += newSecGPS - oldSecGPS;
|
---|
| 728 | if (meanDiff>0.) {
|
---|
| 729 | if (newSecGPS - oldSecGPS > 1.5 * meanDiff) {
|
---|
| 730 | numGaps += 1;
|
---|
| 731 | }
|
---|
[728] | 732 | }
|
---|
| 733 | }
|
---|
[1142] | 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;
|
---|
[728] | 742 | }
|
---|
[709] | 743 | }
|
---|
| 744 | }
|
---|
[658] | 745 | }
|
---|
[351] | 746 |
|
---|
[408] | 747 | // RINEX Output
|
---|
| 748 | // ------------
|
---|
| 749 | if (_rnx) {
|
---|
[1044] | 750 | bool dump = true;
|
---|
| 751 |
|
---|
[1218] | 752 | // RTCMv2 XYZ
|
---|
| 753 | // ----------
|
---|
| 754 | RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
|
---|
| 755 | if ( decoder2 && !_rnx_set_position ) {
|
---|
[1167] | 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 ) {
|
---|
[1218] | 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;
|
---|
[1167] | 776 | _rnx_set_position = true;
|
---|
[1218] | 777 | emit newMessage(QByteArray(msg2.str().c_str()));
|
---|
[1167] | 778 | }
|
---|
[1218] | 779 | }
|
---|
[1167] | 780 |
|
---|
[1044] | 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);
|
---|
[1029] | 788 | }
|
---|
| 789 | }
|
---|
[408] | 790 |
|
---|
[1044] | 791 | // Emit new observation signal
|
---|
| 792 | // ---------------------------
|
---|
[621] | 793 | bool firstObs = (obs == _decoder->_obsList.first());
|
---|
[624] | 794 | obs->_status = t_obs::posted;
|
---|
[621] | 795 | emit newObs(_staID, firstObs, obs);
|
---|
[249] | 796 | }
|
---|
| 797 | _decoder->_obsList.clear();
|
---|
[1030] | 798 |
|
---|
| 799 | if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
|
---|
[1130] | 800 |
|
---|
[1184] | 801 | // RTCMv3 message types
|
---|
| 802 | // --------------------
|
---|
[1030] | 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]);
|
---|
[1130] | 807 | emit(newMessage(_staID + ": Received message type " + type.toAscii() ));
|
---|
[1030] | 808 | }
|
---|
| 809 | }
|
---|
[1130] | 810 | _decoder->_typeList.clear();
|
---|
| 811 |
|
---|
[1184] | 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()) {
|
---|
[1130] | 841 | QString ant1,ant2,ant3,ant4;
|
---|
[1184] | 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);
|
---|
[1130] | 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"));
|
---|
[1201] | 850 | emit(newMessage(_staID + ": Antenna height above ARP " + ant4.toAscii() + "m"));
|
---|
[1130] | 851 | }
|
---|
| 852 | }
|
---|
[1184] | 853 | _decoder->_antList6.clear();
|
---|
[1030] | 854 | }
|
---|
[249] | 855 | }
|
---|
[1030] | 856 |
|
---|
| 857 | // Timeout, reconnect
|
---|
| 858 | // ------------------
|
---|
[249] | 859 | else {
|
---|
| 860 | emit(newMessage(_staID + ": Data Timeout, reconnecting"));
|
---|
| 861 | tryReconnect();
|
---|
| 862 | }
|
---|
[35] | 863 | }
|
---|
[249] | 864 | catch (const char* msg) {
|
---|
| 865 | emit(newMessage(_staID + msg));
|
---|
[136] | 866 | tryReconnect();
|
---|
[35] | 867 | }
|
---|
| 868 | }
|
---|
| 869 | }
|
---|
| 870 |
|
---|
| 871 | // Exit
|
---|
| 872 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 873 | void bncGetThread::exit(int exitCode) {
|
---|
| 874 | if (exitCode!= 0) {
|
---|
[88] | 875 | emit error(_staID);
|
---|
[35] | 876 | }
|
---|
| 877 | QThread::exit(exitCode);
|
---|
[148] | 878 | terminate();
|
---|
[35] | 879 | }
|
---|
[82] | 880 |
|
---|
[136] | 881 | // Try Re-Connect
|
---|
| 882 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 883 | void bncGetThread::tryReconnect() {
|
---|
[408] | 884 | if (_rnx) {
|
---|
| 885 | _rnx->setReconnectFlag(true);
|
---|
| 886 | }
|
---|
[658] | 887 | if ( !_decodeStart.isValid()) {
|
---|
| 888 | _decodeStop = QDateTime::currentDateTime();
|
---|
| 889 | }
|
---|
[138] | 890 | while (1) {
|
---|
| 891 | delete _socket; _socket = 0;
|
---|
| 892 | sleep(_nextSleep);
|
---|
| 893 | if ( initRun() == success ) {
|
---|
[658] | 894 | if ( !_decodeStop.isValid()) {
|
---|
| 895 | _decodeStart = QDateTime::currentDateTime();
|
---|
| 896 | }
|
---|
[138] | 897 | break;
|
---|
| 898 | }
|
---|
| 899 | else {
|
---|
[658] | 900 |
|
---|
| 901 | // Begin outage threshold
|
---|
| 902 | // ----------------------
|
---|
[668] | 903 | if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _adviseFail * 60 ) {
|
---|
[658] | 904 | _decodeStop.setDate(QDate());
|
---|
| 905 | _decodeStop.setTime(QTime());
|
---|
[686] | 906 | if (_inspSegm>0) {
|
---|
[699] | 907 | _begDateOut = _decodeTime.toUTC().date().toString("yy-MM-dd");
|
---|
| 908 | _begTimeOut = _decodeTime.toUTC().time().toString("hh:mm:ss");
|
---|
[701] | 909 | emit(newMessage((_staID + ": Failure threshold exceeded, outage since " + _begDateOut + " " + _begTimeOut).toAscii()));
|
---|
[696] | 910 | callScript(("Begin_Outage " + _begDateOut + " " + _begTimeOut).toAscii());
|
---|
[686] | 911 | }
|
---|
[658] | 912 | }
|
---|
[138] | 913 | _nextSleep *= 2;
|
---|
[442] | 914 | if (_nextSleep > 256) {
|
---|
| 915 | _nextSleep = 256;
|
---|
[152] | 916 | }
|
---|
[277] | 917 | _nextSleep += rand() % 6;
|
---|
[138] | 918 | }
|
---|
| 919 | }
|
---|
| 920 | _nextSleep = 1;
|
---|
[136] | 921 | }
|
---|
[658] | 922 |
|
---|
[668] | 923 | // Call advisory notice script
|
---|
[658] | 924 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 925 | void bncGetThread::callScript(const char* _comment) {
|
---|
[672] | 926 | QMutexLocker locker(&_mutex);
|
---|
[668] | 927 | if (!_adviseScript.isEmpty()) {
|
---|
[672] | 928 | msleep(1);
|
---|
[658] | 929 | #ifdef WIN32
|
---|
[668] | 930 | QProcess::startDetached(_adviseScript, QStringList() << _staID << _comment) ;
|
---|
[658] | 931 | #else
|
---|
[668] | 932 | QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << _comment) ;
|
---|
[658] | 933 | #endif
|
---|
| 934 | }
|
---|
| 935 | }
|
---|
[1044] | 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 |
|
---|
[1218] | 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 | }
|
---|
[1044] | 959 | }
|
---|
| 960 | }
|
---|
| 961 |
|
---|