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