[756] | 1 | /* -------------------------------------------------------------------------
|
---|
| 2 | * BKG NTRIP Server
|
---|
| 3 | * -------------------------------------------------------------------------
|
---|
| 4 | *
|
---|
| 5 | * Class: bns
|
---|
| 6 | *
|
---|
| 7 | * Purpose: This class implements the main application behaviour
|
---|
| 8 | *
|
---|
| 9 | * Author: L. Mervart
|
---|
| 10 | *
|
---|
| 11 | * Created: 29-Mar-2008
|
---|
| 12 | *
|
---|
| 13 | * Changes:
|
---|
| 14 | *
|
---|
| 15 | * -----------------------------------------------------------------------*/
|
---|
| 16 |
|
---|
[858] | 17 | #include <math.h>
|
---|
[756] | 18 | #include <iostream>
|
---|
[800] | 19 | #include <newmatio.h>
|
---|
[756] | 20 |
|
---|
| 21 | #include "bns.h"
|
---|
[799] | 22 | #include "bnsutils.h"
|
---|
[847] | 23 | #include "bnsrinex.h"
|
---|
[848] | 24 | #include "bnssp3.h"
|
---|
[1668] | 25 | #include "bnssettings.h"
|
---|
[1838] | 26 | extern "C" {
|
---|
| 27 | #include "RTCM/rtcm3torinex.h"
|
---|
| 28 | }
|
---|
[756] | 29 |
|
---|
| 30 | using namespace std;
|
---|
| 31 |
|
---|
[1838] | 32 | // Error Handling
|
---|
| 33 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 34 | void RTCM3Error(const char*, ...) {
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[756] | 37 | // Constructor
|
---|
| 38 | ////////////////////////////////////////////////////////////////////////////
|
---|
[757] | 39 | t_bns::t_bns(QObject* parent) : QThread(parent) {
|
---|
[760] | 40 |
|
---|
[764] | 41 | this->setTerminationEnabled(true);
|
---|
[828] | 42 |
|
---|
[836] | 43 | connect(this, SIGNAL(moveSocket(QThread*)),
|
---|
| 44 | this, SLOT(slotMoveSocket(QThread*)));
|
---|
| 45 |
|
---|
[1668] | 46 | bnsSettings settings;
|
---|
[979] | 47 |
|
---|
| 48 | // Set Proxy (application-wide)
|
---|
| 49 | // ----------------------------
|
---|
| 50 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
| 51 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
[980] | 52 |
|
---|
| 53 | QNetworkProxy proxy;
|
---|
| 54 | if (proxyHost.isEmpty()) {
|
---|
| 55 | proxy.setType(QNetworkProxy::NoProxy);
|
---|
| 56 | }
|
---|
| 57 | else {
|
---|
[979] | 58 | proxy.setType(QNetworkProxy::Socks5Proxy);
|
---|
| 59 | proxy.setHostName(proxyHost);
|
---|
| 60 | proxy.setPort(proxyPort);
|
---|
| 61 | }
|
---|
[980] | 62 | QNetworkProxy::setApplicationProxy(proxy);
|
---|
[979] | 63 |
|
---|
[828] | 64 | // Thread that handles broadcast ephemeris
|
---|
| 65 | // ---------------------------------------
|
---|
| 66 | _bnseph = new t_bnseph(parent);
|
---|
[827] | 67 |
|
---|
[1059] | 68 | connect(_bnseph, SIGNAL(newEph(t_eph*, int)),
|
---|
[1058] | 69 | this, SLOT(slotNewEph(t_eph*, int)));
|
---|
[828] | 70 | connect(_bnseph, SIGNAL(newMessage(QByteArray)),
|
---|
| 71 | this, SLOT(slotMessage(const QByteArray)));
|
---|
| 72 | connect(_bnseph, SIGNAL(error(QByteArray)),
|
---|
| 73 | this, SLOT(slotError(const QByteArray)));
|
---|
[760] | 74 |
|
---|
[827] | 75 | // Server listening for rtnet results
|
---|
| 76 | // ----------------------------------
|
---|
[828] | 77 | _clkSocket = 0;
|
---|
[827] | 78 | _clkServer = new QTcpServer;
|
---|
| 79 | _clkServer->listen(QHostAddress::Any, settings.value("clkPort").toInt());
|
---|
[828] | 80 | connect(_clkServer, SIGNAL(newConnection()),this, SLOT(slotNewConnection()));
|
---|
[827] | 81 |
|
---|
[828] | 82 | // Socket and file for outputting the results
|
---|
| 83 | // -------------------------------------------
|
---|
[2349] | 84 | for (int ic = 1; ic <= 10; ic++) {
|
---|
[1069] | 85 | QString mountpoint = settings.value(QString("mountpoint_%1").arg(ic)).toString();
|
---|
[1123] | 86 | QString outFileName = settings.value(QString("outFile_%1").arg(ic)).toString();
|
---|
| 87 | if (!mountpoint.isEmpty() || !outFileName.isEmpty()) {
|
---|
[1698] | 88 | _caster.push_back(new t_bnscaster(mountpoint, outFileName, ic));
|
---|
[1068] | 89 | connect(_caster.back(), SIGNAL(error(const QByteArray)),
|
---|
| 90 | this, SLOT(slotError(const QByteArray)));
|
---|
| 91 | connect(_caster.back(), SIGNAL(newMessage(const QByteArray)),
|
---|
| 92 | this, SLOT(slotMessage(const QByteArray)));
|
---|
| 93 | }
|
---|
[1067] | 94 | }
|
---|
| 95 |
|
---|
[1796] | 96 | // Socket for outputting the Ephemerides
|
---|
| 97 | // -------------------------------------
|
---|
| 98 | QString mountpoint = settings.value("mountpoint_Eph").toString();
|
---|
| 99 | if (mountpoint.isEmpty()) {
|
---|
| 100 | _casterEph = 0;
|
---|
| 101 | }
|
---|
| 102 | else {
|
---|
| 103 | _casterEph = new t_bnscaster(mountpoint);
|
---|
[1800] | 104 | connect(_casterEph, SIGNAL(error(const QByteArray)),
|
---|
[1796] | 105 | this, SLOT(slotError(const QByteArray)));
|
---|
[1800] | 106 | connect(_casterEph, SIGNAL(newMessage(const QByteArray)),
|
---|
[1796] | 107 | this, SLOT(slotMessage(const QByteArray)));
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[1065] | 110 | // Log File
|
---|
| 111 | // --------
|
---|
[983] | 112 | QIODevice::OpenMode oMode;
|
---|
| 113 | if (Qt::CheckState(settings.value("fileAppend").toInt()) == Qt::Checked) {
|
---|
| 114 | oMode = QIODevice::WriteOnly | QIODevice::Unbuffered | QIODevice::Append;
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | oMode = QIODevice::WriteOnly | QIODevice::Unbuffered;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[816] | 120 | QString logFileName = settings.value("logFile").toString();
|
---|
| 121 | if (logFileName.isEmpty()) {
|
---|
[947] | 122 | _logFile = 0;
|
---|
| 123 | _logStream = 0;
|
---|
[812] | 124 | }
|
---|
[816] | 125 | else {
|
---|
| 126 | _logFile = new QFile(logFileName);
|
---|
[983] | 127 | if (_logFile->open(oMode)) {
|
---|
[816] | 128 | _logStream = new QTextStream(_logFile);
|
---|
| 129 | }
|
---|
[948] | 130 | else {
|
---|
| 131 | _logStream = 0;
|
---|
| 132 | }
|
---|
[816] | 133 | }
|
---|
[847] | 134 |
|
---|
[1072] | 135 | // Echo input from RTNet into a file
|
---|
| 136 | // ---------------------------------
|
---|
| 137 | QString echoFileName = settings.value("inpEcho").toString();
|
---|
| 138 | if (echoFileName.isEmpty()) {
|
---|
| 139 | _echoFile = 0;
|
---|
| 140 | _echoStream = 0;
|
---|
| 141 | }
|
---|
| 142 | else {
|
---|
| 143 | _echoFile = new QFile(echoFileName);
|
---|
| 144 | if (_echoFile->open(oMode)) {
|
---|
| 145 | _echoStream = new QTextStream(_echoFile);
|
---|
| 146 | }
|
---|
| 147 | else {
|
---|
| 148 | _echoStream = 0;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[847] | 152 | // RINEX writer
|
---|
| 153 | // ------------
|
---|
| 154 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
| 155 | _rnx = 0;
|
---|
| 156 | }
|
---|
| 157 | else {
|
---|
[850] | 158 | QString prep = "BNS";
|
---|
[857] | 159 | QString ext = ".clk";
|
---|
[850] | 160 | QString path = settings.value("rnxPath").toString();
|
---|
| 161 | QString intr = settings.value("rnxIntr").toString();
|
---|
| 162 | int sampl = settings.value("rnxSampl").toInt();
|
---|
| 163 | _rnx = new bnsRinex(prep, ext, path, intr, sampl);
|
---|
[847] | 164 | }
|
---|
[848] | 165 |
|
---|
| 166 | // SP3 writer
|
---|
| 167 | // ----------
|
---|
| 168 | if ( settings.value("sp3Path").toString().isEmpty() ) {
|
---|
| 169 | _sp3 = 0;
|
---|
| 170 | }
|
---|
| 171 | else {
|
---|
[850] | 172 | QString prep = "BNS";
|
---|
[857] | 173 | QString ext = ".sp3";
|
---|
[850] | 174 | QString path = settings.value("sp3Path").toString();
|
---|
| 175 | QString intr = settings.value("sp3Intr").toString();
|
---|
| 176 | int sampl = settings.value("sp3Sampl").toInt();
|
---|
| 177 | _sp3 = new bnsSP3(prep, ext, path, intr, sampl);
|
---|
[848] | 178 | }
|
---|
[756] | 179 | }
|
---|
| 180 |
|
---|
| 181 | // Destructor
|
---|
| 182 | ////////////////////////////////////////////////////////////////////////////
|
---|
[757] | 183 | t_bns::~t_bns() {
|
---|
[763] | 184 | deleteBnsEph();
|
---|
[769] | 185 | delete _clkServer;
|
---|
[837] | 186 | delete _clkSocket;
|
---|
[1066] | 187 | for (int ic = 0; ic < _caster.size(); ic++) {
|
---|
| 188 | delete _caster.at(ic);
|
---|
| 189 | }
|
---|
[1796] | 190 | delete _casterEph;
|
---|
[816] | 191 | delete _logStream;
|
---|
[812] | 192 | delete _logFile;
|
---|
[1072] | 193 | delete _echoStream;
|
---|
| 194 | delete _echoFile;
|
---|
[779] | 195 | QMapIterator<QString, t_ephPair*> it(_ephList);
|
---|
| 196 | while (it.hasNext()) {
|
---|
| 197 | it.next();
|
---|
| 198 | delete it.value();
|
---|
| 199 | }
|
---|
[849] | 200 | delete _rnx;
|
---|
| 201 | delete _sp3;
|
---|
[756] | 202 | }
|
---|
| 203 |
|
---|
[763] | 204 | // Delete bns thread
|
---|
| 205 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 206 | void t_bns::deleteBnsEph() {
|
---|
| 207 | if (_bnseph) {
|
---|
| 208 | _bnseph->terminate();
|
---|
[764] | 209 | _bnseph->wait(100);
|
---|
[763] | 210 | delete _bnseph;
|
---|
| 211 | _bnseph = 0;
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[756] | 215 | // Write a Program Message
|
---|
| 216 | ////////////////////////////////////////////////////////////////////////////
|
---|
[758] | 217 | void t_bns::slotMessage(const QByteArray msg) {
|
---|
[816] | 218 | if (_logStream) {
|
---|
[1217] | 219 | QString txt = QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ");
|
---|
| 220 | *_logStream << txt << msg << endl;
|
---|
[818] | 221 | _logStream->flush();
|
---|
[812] | 222 | }
|
---|
[757] | 223 | emit(newMessage(msg));
|
---|
[756] | 224 | }
|
---|
| 225 |
|
---|
[760] | 226 | // Write a Program Message
|
---|
| 227 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 228 | void t_bns::slotError(const QByteArray msg) {
|
---|
[816] | 229 | if (_logStream) {
|
---|
| 230 | *_logStream << msg << endl;
|
---|
[818] | 231 | _logStream->flush();
|
---|
[812] | 232 | }
|
---|
[763] | 233 | deleteBnsEph();
|
---|
[760] | 234 | emit(error(msg));
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[769] | 237 | // New Connection
|
---|
| 238 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 239 | void t_bns::slotNewConnection() {
|
---|
[1208] | 240 | //slotMessage("t_bns::slotNewConnection");
|
---|
| 241 | slotMessage("Clocks & orbits port: Waiting for client to connect"); // weber
|
---|
[787] | 242 | delete _clkSocket;
|
---|
[769] | 243 | _clkSocket = _clkServer->nextPendingConnection();
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[784] | 246 | //
|
---|
| 247 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1058] | 248 | void t_bns::slotNewEph(t_eph* ep, int nBytes) {
|
---|
[784] | 249 |
|
---|
| 250 | QMutexLocker locker(&_mutex);
|
---|
| 251 |
|
---|
[1058] | 252 | emit(newEphBytes(nBytes));
|
---|
| 253 |
|
---|
[1801] | 254 | // Output Ephemerides as they are
|
---|
| 255 | // ------------------------------
|
---|
| 256 | if (_casterEph) {
|
---|
[1802] | 257 | _casterEph->open();
|
---|
[1867] | 258 | unsigned char Array[67];
|
---|
| 259 | int size = ep->RTCM3(Array);
|
---|
| 260 | if (size > 0) {
|
---|
| 261 | _casterEph->write((char*) Array, size);
|
---|
| 262 | emit(newOutEphBytes(size));
|
---|
[1803] | 263 | }
|
---|
[1867] | 264 | //// QByteArray buffer = "New Ephemeris " + ep->prn().toAscii() + "\n";
|
---|
| 265 | //// _casterEph->write(buffer.data(), buffer.length());
|
---|
| 266 | //// int len = buffer.length();
|
---|
| 267 | //// if (len > 0) {
|
---|
| 268 | //// emit(newOutEphBytes(len));
|
---|
| 269 | //// }
|
---|
[1801] | 270 | }
|
---|
| 271 |
|
---|
[784] | 272 | t_ephPair* pair;
|
---|
[884] | 273 | if ( !_ephList.contains(ep->prn()) ) {
|
---|
[784] | 274 | pair = new t_ephPair();
|
---|
[884] | 275 | _ephList.insert(ep->prn(), pair);
|
---|
[784] | 276 | }
|
---|
| 277 | else {
|
---|
[884] | 278 | pair = _ephList[ep->prn()];
|
---|
[784] | 279 | }
|
---|
| 280 |
|
---|
| 281 | if (pair->eph == 0) {
|
---|
| 282 | pair->eph = ep;
|
---|
| 283 | }
|
---|
| 284 | else {
|
---|
[884] | 285 | if (ep->isNewerThan(pair->eph)) {
|
---|
[784] | 286 | delete pair->oldEph;
|
---|
| 287 | pair->oldEph = pair->eph;
|
---|
| 288 | pair->eph = ep;
|
---|
| 289 | }
|
---|
| 290 | else {
|
---|
| 291 | delete ep;
|
---|
| 292 | }
|
---|
| 293 | }
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[756] | 296 | // Start
|
---|
| 297 | ////////////////////////////////////////////////////////////////////////////
|
---|
[757] | 298 | void t_bns::run() {
|
---|
[769] | 299 |
|
---|
[758] | 300 | slotMessage("============ Start BNS ============");
|
---|
[770] | 301 |
|
---|
[828] | 302 | // Start Thread that retrieves broadcast Ephemeris
|
---|
| 303 | // -----------------------------------------------
|
---|
[758] | 304 | _bnseph->start();
|
---|
[769] | 305 |
|
---|
[770] | 306 | // Endless loop
|
---|
| 307 | // ------------
|
---|
[769] | 308 | while (true) {
|
---|
[836] | 309 |
|
---|
| 310 | if (_clkSocket && _clkSocket->thread() != currentThread()) {
|
---|
| 311 | emit(moveSocket(currentThread()));
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[796] | 314 | if (_clkSocket && _clkSocket->state() == QAbstractSocket::ConnectedState) {
|
---|
| 315 | if ( _clkSocket->canReadLine()) {
|
---|
| 316 | readEpoch();
|
---|
| 317 | }
|
---|
[809] | 318 | else {
|
---|
| 319 | _clkSocket->waitForReadyRead(10);
|
---|
| 320 | }
|
---|
[769] | 321 | }
|
---|
| 322 | else {
|
---|
[794] | 323 | msleep(10);
|
---|
[769] | 324 | }
|
---|
| 325 | }
|
---|
[756] | 326 | }
|
---|
| 327 |
|
---|
[778] | 328 | //
|
---|
| 329 | ////////////////////////////////////////////////////////////////////////////
|
---|
[784] | 330 | void t_bns::readEpoch() {
|
---|
[778] | 331 |
|
---|
[1670] | 332 | bnsSettings settings;
|
---|
| 333 |
|
---|
[1197] | 334 | // Read the first line (if not already read)
|
---|
| 335 | // -----------------------------------------
|
---|
| 336 | if (_clkLine.indexOf('*') == -1) {
|
---|
| 337 | _clkLine = _clkSocket->readLine();
|
---|
| 338 | if (_echoStream) {
|
---|
| 339 | *_echoStream << _clkLine;
|
---|
| 340 | _echoStream->flush();
|
---|
| 341 | }
|
---|
| 342 | emit(newClkBytes(_clkLine.length()));
|
---|
[1072] | 343 | }
|
---|
| 344 |
|
---|
[1197] | 345 | if (_clkLine.indexOf('*') == -1) {
|
---|
[784] | 346 | return;
|
---|
[778] | 347 | }
|
---|
| 348 |
|
---|
[1197] | 349 | QTextStream in(_clkLine);
|
---|
[784] | 350 |
|
---|
| 351 | QString hlp;
|
---|
[1197] | 352 | int year, month, day, hour, min;
|
---|
| 353 | double sec;
|
---|
| 354 | in >> hlp >> year >> month >> day >> hour >> min >> sec;
|
---|
| 355 |
|
---|
| 356 | int GPSweek;
|
---|
[798] | 357 | double GPSweeks;
|
---|
[784] | 358 |
|
---|
[1197] | 359 | GPSweekFromYMDhms(year, month, day, hour, min, sec, GPSweek, GPSweeks);
|
---|
[784] | 360 |
|
---|
[1197] | 361 | QStringList prns;
|
---|
[874] | 362 |
|
---|
[1197] | 363 | // Loop over all satellites
|
---|
| 364 | // ------------------------
|
---|
| 365 | QStringList lines;
|
---|
| 366 | for (;;) {
|
---|
| 367 | if (!_clkSocket->canReadLine()) {
|
---|
[1198] | 368 | break;
|
---|
[1197] | 369 | }
|
---|
| 370 | _clkLine = _clkSocket->readLine();
|
---|
| 371 | if (_echoStream) {
|
---|
| 372 | *_echoStream << _clkLine;
|
---|
| 373 | _echoStream->flush();
|
---|
| 374 | }
|
---|
| 375 | if (_clkLine[0] == '*') {
|
---|
| 376 | return;
|
---|
| 377 | }
|
---|
| 378 | if (_clkLine[0] == 'P') {
|
---|
| 379 | _clkLine.remove(0,1);
|
---|
| 380 | lines.push_back(_clkLine);
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | if (lines.size() > 0) {
|
---|
| 385 |
|
---|
[922] | 386 | QStringList prns;
|
---|
| 387 |
|
---|
[1066] | 388 | for (int ic = 0; ic < _caster.size(); ic++) {
|
---|
| 389 | _caster.at(ic)->open();
|
---|
[927] | 390 |
|
---|
[1066] | 391 | for (int oldEph = 0; oldEph <= 0; oldEph++) { // TODO: handle old ephemeris
|
---|
| 392 |
|
---|
| 393 | struct ClockOrbit co;
|
---|
| 394 | memset(&co, 0, sizeof(co));
|
---|
| 395 | co.GPSEpochTime = (int)GPSweeks;
|
---|
[1838] | 396 | co.GLONASSEpochTime = (int)fmod(GPSweeks, 86400.0)
|
---|
| 397 | + 3 * 3600 - gnumleap(year, month, day);
|
---|
[1066] | 398 | co.ClockDataSupplied = 1;
|
---|
| 399 | co.OrbitDataSupplied = 1;
|
---|
| 400 | co.SatRefDatum = DATUM_ITRF;
|
---|
| 401 |
|
---|
[2291] | 402 | struct Bias bias;
|
---|
| 403 | memset(&bias, 0, sizeof(bias));
|
---|
| 404 | bias.GPSEpochTime = (int)GPSweeks;
|
---|
| 405 | bias.GLONASSEpochTime = (int)fmod(GPSweeks, 86400.0)
|
---|
| 406 | + 3 * 3600 - gnumleap(year, month, day);
|
---|
| 407 |
|
---|
[1197] | 408 | for (int ii = 0; ii < lines.size(); ii++) {
|
---|
| 409 |
|
---|
[1066] | 410 | QString prn;
|
---|
[2294] | 411 | ColumnVector xx(14); xx = 0.0;
|
---|
[1066] | 412 | t_eph* ep = 0;
|
---|
| 413 |
|
---|
[1075] | 414 | if (oldEph == 0 && ic == 0) {
|
---|
[1197] | 415 | QTextStream in(lines[ii].toAscii());
|
---|
[1066] | 416 | in >> prn;
|
---|
| 417 | prns << prn;
|
---|
| 418 | if ( _ephList.contains(prn) ) {
|
---|
[2046] | 419 | in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5)
|
---|
[2294] | 420 | >> xx(6) >> xx(7) >> xx(8) >> xx(9) >> xx(10)
|
---|
| 421 | >> xx(11) >> xx(12) >> xx(13) >> xx(14);
|
---|
[2420] | 422 | xx(1) *= 1e3; // x-crd
|
---|
| 423 | xx(2) *= 1e3; // y-crd
|
---|
| 424 | xx(3) *= 1e3; // z-crd
|
---|
| 425 | xx(4) *= 1e-6; // clk
|
---|
| 426 | xx(5) *= 1e-6; // rel. corr.
|
---|
| 427 | // xx(6), xx(7), xx(8) ... PhaseCent - CoM
|
---|
[2429] | 428 | // xx(9) ... P1-C1 DCB in meters
|
---|
| 429 | // xx(10) ... P1-P2 DCB in meters
|
---|
[2420] | 430 | // xx(11) ... dT
|
---|
| 431 | xx(12) *= 1e3; // x-crd at time + dT
|
---|
| 432 | xx(13) *= 1e3; // y-crd at time + dT
|
---|
| 433 | xx(14) *= 1e3; // z-crd at time + dT
|
---|
[1670] | 434 |
|
---|
[1066] | 435 | t_ephPair* pair = _ephList[prn];
|
---|
| 436 | pair->xx = xx;
|
---|
| 437 | ep = pair->eph;
|
---|
| 438 | }
|
---|
[872] | 439 | }
|
---|
[1066] | 440 | else {
|
---|
[1197] | 441 | prn = prns[ii];
|
---|
[1066] | 442 | if ( _ephList.contains(prn) ) {
|
---|
| 443 | t_ephPair* pair = _ephList[prn];
|
---|
| 444 | prn = pair->eph->prn();
|
---|
| 445 | xx = pair->xx;
|
---|
[1076] | 446 | if (oldEph) {
|
---|
| 447 | ep = pair->oldEph;
|
---|
| 448 | }
|
---|
| 449 | else {
|
---|
| 450 | ep = pair->eph;
|
---|
| 451 | }
|
---|
[1066] | 452 | }
|
---|
[873] | 453 | }
|
---|
[1066] | 454 |
|
---|
| 455 | if (ep != 0) {
|
---|
| 456 | struct ClockOrbit::SatData* sd = 0;
|
---|
| 457 | if (prn[0] == 'G') {
|
---|
| 458 | sd = co.Sat + co.NumberOfGPSSat;
|
---|
| 459 | ++co.NumberOfGPSSat;
|
---|
| 460 | }
|
---|
| 461 | else if (prn[0] == 'R') {
|
---|
| 462 | sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
|
---|
| 463 | ++co.NumberOfGLONASSSat;
|
---|
| 464 | }
|
---|
| 465 | if (sd) {
|
---|
| 466 | QString outLine;
|
---|
[1733] | 467 | processSatellite(oldEph, ic, _caster.at(ic)->crdTrafo(),
|
---|
[2046] | 468 | _caster.at(ic)->CoM(), ep,
|
---|
[1102] | 469 | GPSweek, GPSweeks, prn, xx, sd, outLine);
|
---|
[1074] | 470 | _caster.at(ic)->printAscii(outLine);
|
---|
[1066] | 471 | }
|
---|
[2291] | 472 |
|
---|
| 473 | struct Bias::BiasSat* biasSat = 0;
|
---|
| 474 | if (prn[0] == 'G') {
|
---|
| 475 | biasSat = bias.Sat + bias.NumberOfGPSSat;
|
---|
| 476 | ++bias.NumberOfGPSSat;
|
---|
| 477 | }
|
---|
[2427] | 478 | else if (prn[0] == 'R') {
|
---|
| 479 | biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfGLONASSSat;
|
---|
| 480 | ++bias.NumberOfGLONASSSat;
|
---|
| 481 | }
|
---|
[2291] | 482 |
|
---|
[2419] | 483 | // Coefficient of Ionosphere-Free LC
|
---|
| 484 | // ---------------------------------
|
---|
| 485 | const static double a_L1_GPS = 2.54572778;
|
---|
| 486 | const static double a_L2_GPS = -1.54572778;
|
---|
| 487 | const static double a_L1_Glo = 2.53125000;
|
---|
| 488 | const static double a_L2_Glo = -1.53125000;
|
---|
| 489 |
|
---|
[2291] | 490 | if (biasSat) {
|
---|
[2314] | 491 | biasSat->ID = prn.mid(1).toInt();
|
---|
[2298] | 492 | biasSat->NumberOfCodeBiases = 3;
|
---|
[2314] | 493 | if (prn[0] == 'G') {
|
---|
[2364] | 494 | biasSat->Biases[0].Type = CODETYPEGPS_L1_Z;
|
---|
[2423] | 495 | biasSat->Biases[0].Bias = - a_L2_GPS * xx(10);
|
---|
[2314] | 496 | biasSat->Biases[1].Type = CODETYPEGPS_L1_CA;
|
---|
[2423] | 497 | biasSat->Biases[1].Bias = - a_L2_GPS * xx(10) + xx(9);
|
---|
[2364] | 498 | biasSat->Biases[2].Type = CODETYPEGPS_L2_Z;
|
---|
[2423] | 499 | biasSat->Biases[2].Bias = a_L1_GPS * xx(10);
|
---|
[2314] | 500 | }
|
---|
| 501 | else if (prn[0] == 'R') {
|
---|
| 502 | biasSat->Biases[0].Type = CODETYPEGLONASS_L1_P;
|
---|
[2423] | 503 | biasSat->Biases[0].Bias = - a_L2_Glo * xx(10);
|
---|
[2314] | 504 | biasSat->Biases[1].Type = CODETYPEGLONASS_L1_CA;
|
---|
[2423] | 505 | biasSat->Biases[1].Bias = - a_L2_Glo * xx(10) + xx(9);
|
---|
[2314] | 506 | biasSat->Biases[2].Type = CODETYPEGLONASS_L2_P;
|
---|
[2423] | 507 | biasSat->Biases[2].Bias = a_L1_Glo * xx(10);
|
---|
[2314] | 508 | }
|
---|
[2291] | 509 | }
|
---|
[1066] | 510 | }
|
---|
[873] | 511 | }
|
---|
[1066] | 512 |
|
---|
[1123] | 513 | if ( _caster.at(ic)->usedSocket() &&
|
---|
[1066] | 514 | (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
|
---|
| 515 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
[2047] | 516 |
|
---|
[1066] | 517 | int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
| 518 | if (len > 0) {
|
---|
[2349] | 519 | if (_caster.at(ic)->ic() == 1) { emit(newOutBytes1(len));}
|
---|
| 520 | if (_caster.at(ic)->ic() == 2) { emit(newOutBytes2(len));}
|
---|
| 521 | if (_caster.at(ic)->ic() == 3) { emit(newOutBytes3(len));}
|
---|
| 522 | if (_caster.at(ic)->ic() == 4) { emit(newOutBytes4(len));}
|
---|
| 523 | if (_caster.at(ic)->ic() == 5) { emit(newOutBytes5(len));}
|
---|
| 524 | if (_caster.at(ic)->ic() == 6) { emit(newOutBytes6(len));}
|
---|
| 525 | if (_caster.at(ic)->ic() == 7) { emit(newOutBytes7(len));}
|
---|
| 526 | if (_caster.at(ic)->ic() == 8) { emit(newOutBytes8(len));}
|
---|
| 527 | if (_caster.at(ic)->ic() == 9) { emit(newOutBytes9(len));}
|
---|
| 528 | if (_caster.at(ic)->ic() == 10) { emit(newOutBytes10(len));}
|
---|
[1066] | 529 | _caster.at(ic)->write(obuffer, len);
|
---|
[872] | 530 | }
|
---|
| 531 | }
|
---|
[2291] | 532 |
|
---|
| 533 | if ( _caster.at(ic)->usedSocket() &&
|
---|
| 534 | (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) ) {
|
---|
| 535 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
| 536 | int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
| 537 | if (len > 0) {
|
---|
| 538 | _caster.at(ic)->write(obuffer, len);
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
[863] | 541 | }
|
---|
| 542 | }
|
---|
[780] | 543 | }
|
---|
[778] | 544 | }
|
---|
[784] | 545 |
|
---|
| 546 | //
|
---|
| 547 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1772] | 548 | void t_bns::processSatellite(int oldEph, int iCaster, const QString trafo,
|
---|
[2046] | 549 | bool CoM, t_eph* ep, int GPSweek,
|
---|
[1733] | 550 | double GPSweeks, const QString& prn,
|
---|
[1066] | 551 | const ColumnVector& xx,
|
---|
[1065] | 552 | struct ClockOrbit::SatData* sd,
|
---|
| 553 | QString& outLine) {
|
---|
[784] | 554 |
|
---|
[2294] | 555 | const double secPerWeek = 7.0 * 86400.0;
|
---|
[799] | 556 |
|
---|
[2294] | 557 | ColumnVector rsw(3);
|
---|
| 558 | ColumnVector rsw2(3);
|
---|
| 559 | double dClk;
|
---|
[799] | 560 |
|
---|
[2294] | 561 | for (int ii = 1; ii <= 2; ++ii) {
|
---|
[2046] | 562 |
|
---|
[2294] | 563 | int GPSweek12 = GPSweek;
|
---|
| 564 | double GPSweeks12 = GPSweeks;
|
---|
| 565 | if (ii == 2) {
|
---|
| 566 | GPSweeks12 += xx(11);
|
---|
| 567 | if (GPSweeks12 > secPerWeek) {
|
---|
| 568 | GPSweek12 += 1;
|
---|
| 569 | GPSweeks12 -= secPerWeek;
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
[2046] | 572 |
|
---|
[2294] | 573 | ColumnVector xB(4);
|
---|
| 574 | ColumnVector vv(3);
|
---|
| 575 |
|
---|
| 576 | ep->position(GPSweek12, GPSweeks12, xB, vv);
|
---|
| 577 |
|
---|
| 578 | ColumnVector xyz;
|
---|
| 579 | if (ii == 1) {
|
---|
| 580 | xyz = xx.Rows(1,3);
|
---|
| 581 | }
|
---|
| 582 | else {
|
---|
| 583 | xyz = xx.Rows(12,14);
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | // Correction Center of Mass -> Antenna Phase Center
|
---|
| 587 | // -------------------------------------------------
|
---|
| 588 | if (! CoM) {
|
---|
| 589 | xyz(1) += xx(6);
|
---|
| 590 | xyz(2) += xx(7);
|
---|
| 591 | xyz(3) += xx(8);
|
---|
| 592 | }
|
---|
| 593 |
|
---|
| 594 | if (trafo != "IGS05") {
|
---|
| 595 | crdTrafo(GPSweek12, xyz, trafo);
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[2418] | 598 | ColumnVector dx = xB.Rows(1,3) - xyz ;
|
---|
[2294] | 599 |
|
---|
| 600 | if (ii == 1) {
|
---|
| 601 | XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw);
|
---|
[2417] | 602 | dClk = (xx(4) + xx(5) - xB(4)) * 299792458.0;
|
---|
[2294] | 603 | }
|
---|
| 604 | else {
|
---|
| 605 | XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw2);
|
---|
| 606 | }
|
---|
[984] | 607 | }
|
---|
[927] | 608 |
|
---|
[863] | 609 | if (sd) {
|
---|
| 610 | sd->ID = prn.mid(1).toInt();
|
---|
[884] | 611 | sd->IOD = ep->IOD();
|
---|
[862] | 612 | sd->Clock.DeltaA0 = dClk;
|
---|
| 613 | sd->Orbit.DeltaRadial = rsw(1);
|
---|
| 614 | sd->Orbit.DeltaAlongTrack = rsw(2);
|
---|
| 615 | sd->Orbit.DeltaCrossTrack = rsw(3);
|
---|
[2294] | 616 | sd->Orbit.DotDeltaRadial = (rsw2(1) - rsw(1)) / xx(11);
|
---|
| 617 | sd->Orbit.DotDeltaAlongTrack = (rsw2(2) - rsw(2)) / xx(11);
|
---|
| 618 | sd->Orbit.DotDeltaCrossTrack = (rsw2(3) - rsw(3)) / xx(11);
|
---|
[863] | 619 | }
|
---|
[862] | 620 |
|
---|
[1065] | 621 | char oldCh = (oldEph ? '!' : ' ');
|
---|
[2046] | 622 | outLine.sprintf("%c %d %.1f %s %3d %10.3f %8.3f %8.3f %8.3f\n",
|
---|
[1065] | 623 | oldCh, GPSweek, GPSweeks, ep->prn().toAscii().data(),
|
---|
[2046] | 624 | ep->IOD(), dClk, rsw(1), rsw(2), rsw(3));
|
---|
[1065] | 625 |
|
---|
[1102] | 626 | if (!oldEph && iCaster == 0) {
|
---|
[923] | 627 | if (_rnx) {
|
---|
| 628 | _rnx->write(GPSweek, GPSweeks, prn, xx);
|
---|
| 629 | }
|
---|
| 630 | if (_sp3) {
|
---|
| 631 | _sp3->write(GPSweek, GPSweeks, prn, xx);
|
---|
| 632 | }
|
---|
[847] | 633 | }
|
---|
[784] | 634 | }
|
---|
[836] | 635 |
|
---|
| 636 | //
|
---|
| 637 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 638 | void t_bns::slotMoveSocket(QThread* tt) {
|
---|
| 639 | _clkSocket->setParent(0);
|
---|
| 640 | _clkSocket->moveToThread(tt);
|
---|
[1209] | 641 | //slotMessage("bns::slotMoveSocket");
|
---|
| 642 | slotMessage("Clocks & orbits port: Socket moved to thread"); // weber
|
---|
[836] | 643 | }
|
---|
[984] | 644 |
|
---|
[1772] | 645 | // Transform Coordinates
|
---|
[984] | 646 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1772] | 647 | void t_bns::crdTrafo(int GPSWeek, ColumnVector& xyz, const QString trafo) {
|
---|
[984] | 648 |
|
---|
[1772] | 649 | bnsSettings settings;
|
---|
| 650 |
|
---|
| 651 | if (trafo == "ETRF2000") {
|
---|
[2333] | 652 | _dx = 0.0541;
|
---|
| 653 | _dy = 0.0502;
|
---|
| 654 | _dz = -0.0538;
|
---|
| 655 | _dxr = -0.0002;
|
---|
| 656 | _dyr = 0.0001;
|
---|
| 657 | _dzr = -0.0018;
|
---|
[1776] | 658 | _ox = 0.000891;
|
---|
| 659 | _oy = 0.005390;
|
---|
| 660 | _oz = -0.008712;
|
---|
| 661 | _oxr = 0.000081;
|
---|
| 662 | _oyr = 0.000490;
|
---|
| 663 | _ozr = -0.000792;
|
---|
[2333] | 664 | _sc = 0.40;
|
---|
| 665 | _scr = 0.08;
|
---|
| 666 | _t0 = 2000.0;
|
---|
[1772] | 667 | }
|
---|
[2327] | 668 | else if (trafo == "NAD83") {
|
---|
[2335] | 669 | _dx = 0.9963;
|
---|
| 670 | _dy = -1.9024;
|
---|
| 671 | _dz = -0.5210;
|
---|
| 672 | _dxr = 0.0005;
|
---|
| 673 | _dyr = -0.0006;
|
---|
| 674 | _dzr = -0.0013;
|
---|
[2333] | 675 | _ox = 0.025915;
|
---|
| 676 | _oy = 0.009426;
|
---|
| 677 | _oz = 0.011599;
|
---|
| 678 | _oxr = 0.000067;
|
---|
| 679 | _oyr = -0.000757;
|
---|
| 680 | _ozr = -0.000051;
|
---|
[2335] | 681 | _sc = 0.78;
|
---|
| 682 | _scr = -0.10;
|
---|
[2333] | 683 | _t0 = 1997.0;
|
---|
[2327] | 684 | }
|
---|
[2333] | 685 | else if (trafo == "GDA94") {
|
---|
[2351] | 686 | _dx = 0.07167;
|
---|
| 687 | _dy = 0.00486;
|
---|
| 688 | _dz = -0.04711;
|
---|
| 689 | _dxr = -0.00342;
|
---|
| 690 | _dyr = 0.00055;
|
---|
| 691 | _dzr = 0.00136;
|
---|
| 692 | _ox = 0.0091362;
|
---|
| 693 | _oy = 0.0093086;
|
---|
| 694 | _oz = 0.0091599;
|
---|
| 695 | _oxr = 0.0014652;
|
---|
| 696 | _oyr = 0.0011005;
|
---|
| 697 | _ozr = 0.0011480;
|
---|
| 698 | _sc = -8.239;
|
---|
| 699 | _scr = -0.212;
|
---|
| 700 | _t0 = 2000.0;
|
---|
[2333] | 701 | }
|
---|
[2347] | 702 | else if (trafo == "SIRGAS2000") {
|
---|
[2350] | 703 | _dx = -0.0051;
|
---|
| 704 | _dy = -0.0065;
|
---|
| 705 | _dz = -0.0099;
|
---|
[2347] | 706 | _dxr = 0.0000;
|
---|
| 707 | _dyr = 0.0000;
|
---|
| 708 | _dzr = 0.0000;
|
---|
| 709 | _ox = 0.000150;
|
---|
| 710 | _oy = 0.000020;
|
---|
| 711 | _oz = 0.000021;
|
---|
| 712 | _oxr = 0.000000;
|
---|
| 713 | _oyr = 0.000000;
|
---|
| 714 | _ozr = 0.000000;
|
---|
| 715 | _sc = 0.000;
|
---|
| 716 | _scr = 0.000;
|
---|
| 717 | _t0 = 0000.0;
|
---|
| 718 | }
|
---|
[2359] | 719 | else if (trafo == "SIRGAS95") {
|
---|
| 720 | _dx = 0.0077;
|
---|
| 721 | _dy = 0.0058;
|
---|
| 722 | _dz = -0.0138;
|
---|
| 723 | _dxr = 0.0000;
|
---|
| 724 | _dyr = 0.0000;
|
---|
| 725 | _dzr = 0.0000;
|
---|
| 726 | _ox = 0.000000;
|
---|
| 727 | _oy = 0.000000;
|
---|
[2361] | 728 | _oz = -0.000030;
|
---|
[2359] | 729 | _oxr = 0.000000;
|
---|
| 730 | _oyr = 0.000000;
|
---|
| 731 | _ozr = 0.000000;
|
---|
[2361] | 732 | _sc = 1.570;
|
---|
[2359] | 733 | _scr = 0.000;
|
---|
[2369] | 734 | _t0 = 0000.0;
|
---|
[2359] | 735 | }
|
---|
[1772] | 736 | else if (trafo == "Custom") {
|
---|
[1776] | 737 | _dx = settings.value("trafo_dx").toDouble();
|
---|
| 738 | _dy = settings.value("trafo_dy").toDouble();
|
---|
| 739 | _dz = settings.value("trafo_dz").toDouble();
|
---|
| 740 | _dxr = settings.value("trafo_dxr").toDouble();
|
---|
| 741 | _dyr = settings.value("trafo_dyr").toDouble();
|
---|
| 742 | _dzr = settings.value("trafo_dzr").toDouble();
|
---|
| 743 | _ox = settings.value("trafo_ox").toDouble();
|
---|
| 744 | _oy = settings.value("trafo_oy").toDouble();
|
---|
| 745 | _oz = settings.value("trafo_oz").toDouble();
|
---|
| 746 | _oxr = settings.value("trafo_oxr").toDouble();
|
---|
| 747 | _oyr = settings.value("trafo_oyr").toDouble();
|
---|
| 748 | _ozr = settings.value("trafo_ozr").toDouble();
|
---|
| 749 | _sc = settings.value("trafo_sc").toDouble();
|
---|
| 750 | _scr = settings.value("trafo_scr").toDouble();
|
---|
| 751 | _t0 = settings.value("trafo_t0").toDouble();
|
---|
[1772] | 752 | }
|
---|
| 753 |
|
---|
[1243] | 754 | // Current epoch minus 2000.0 in years
|
---|
| 755 | // ------------------------------------
|
---|
[1772] | 756 | double dt = (GPSWeek - (1042.0+6.0/7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
|
---|
[1243] | 757 |
|
---|
[985] | 758 | ColumnVector dx(3);
|
---|
[1243] | 759 |
|
---|
[1772] | 760 | dx(1) = _dx + dt * _dxr;
|
---|
| 761 | dx(2) = _dy + dt * _dyr;
|
---|
| 762 | dx(3) = _dz + dt * _dzr;
|
---|
| 763 |
|
---|
[1100] | 764 | static const double arcSec = 180.0 * 3600.0 / M_PI;
|
---|
[984] | 765 |
|
---|
[1772] | 766 | double ox = (_ox + dt * _oxr) / arcSec;
|
---|
| 767 | double oy = (_oy + dt * _oyr) / arcSec;
|
---|
| 768 | double oz = (_oz + dt * _ozr) / arcSec;
|
---|
[1243] | 769 |
|
---|
[1772] | 770 | double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
|
---|
| 771 |
|
---|
[1245] | 772 | Matrix rMat(3,3);
|
---|
| 773 | rMat(1,1) = 1.0;
|
---|
[985] | 774 | rMat(1,2) = -oz;
|
---|
| 775 | rMat(1,3) = oy;
|
---|
| 776 | rMat(2,1) = oz;
|
---|
[1245] | 777 | rMat(2,2) = 1.0;
|
---|
[985] | 778 | rMat(2,3) = -ox;
|
---|
| 779 | rMat(3,1) = -oy;
|
---|
| 780 | rMat(3,2) = ox;
|
---|
[1245] | 781 | rMat(3,3) = 1.0;
|
---|
[985] | 782 |
|
---|
[1245] | 783 | xyz = sc * rMat * xyz + dx;
|
---|
[984] | 784 | }
|
---|