| [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"
|
|---|
| [756] | 26 |
|
|---|
| 27 | using namespace std;
|
|---|
| 28 |
|
|---|
| 29 | // Constructor
|
|---|
| 30 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [757] | 31 | t_bns::t_bns(QObject* parent) : QThread(parent) {
|
|---|
| [760] | 32 |
|
|---|
| [764] | 33 | this->setTerminationEnabled(true);
|
|---|
| [828] | 34 |
|
|---|
| [836] | 35 | connect(this, SIGNAL(moveSocket(QThread*)),
|
|---|
| 36 | this, SLOT(slotMoveSocket(QThread*)));
|
|---|
| 37 |
|
|---|
| [1668] | 38 | bnsSettings settings;
|
|---|
| [979] | 39 |
|
|---|
| 40 | // Set Proxy (application-wide)
|
|---|
| 41 | // ----------------------------
|
|---|
| 42 | QString proxyHost = settings.value("proxyHost").toString();
|
|---|
| 43 | int proxyPort = settings.value("proxyPort").toInt();
|
|---|
| [980] | 44 |
|
|---|
| 45 | QNetworkProxy proxy;
|
|---|
| 46 | if (proxyHost.isEmpty()) {
|
|---|
| 47 | proxy.setType(QNetworkProxy::NoProxy);
|
|---|
| 48 | }
|
|---|
| 49 | else {
|
|---|
| [979] | 50 | proxy.setType(QNetworkProxy::Socks5Proxy);
|
|---|
| 51 | proxy.setHostName(proxyHost);
|
|---|
| 52 | proxy.setPort(proxyPort);
|
|---|
| 53 | }
|
|---|
| [980] | 54 | QNetworkProxy::setApplicationProxy(proxy);
|
|---|
| [979] | 55 |
|
|---|
| [828] | 56 | // Thread that handles broadcast ephemeris
|
|---|
| 57 | // ---------------------------------------
|
|---|
| 58 | _bnseph = new t_bnseph(parent);
|
|---|
| [827] | 59 |
|
|---|
| [1059] | 60 | connect(_bnseph, SIGNAL(newEph(t_eph*, int)),
|
|---|
| [1058] | 61 | this, SLOT(slotNewEph(t_eph*, int)));
|
|---|
| [828] | 62 | connect(_bnseph, SIGNAL(newMessage(QByteArray)),
|
|---|
| 63 | this, SLOT(slotMessage(const QByteArray)));
|
|---|
| 64 | connect(_bnseph, SIGNAL(error(QByteArray)),
|
|---|
| 65 | this, SLOT(slotError(const QByteArray)));
|
|---|
| [760] | 66 |
|
|---|
| [827] | 67 | // Server listening for rtnet results
|
|---|
| 68 | // ----------------------------------
|
|---|
| [828] | 69 | _clkSocket = 0;
|
|---|
| [827] | 70 | _clkServer = new QTcpServer;
|
|---|
| 71 | _clkServer->listen(QHostAddress::Any, settings.value("clkPort").toInt());
|
|---|
| [828] | 72 | connect(_clkServer, SIGNAL(newConnection()),this, SLOT(slotNewConnection()));
|
|---|
| [827] | 73 |
|
|---|
| [828] | 74 | // Socket and file for outputting the results
|
|---|
| 75 | // -------------------------------------------
|
|---|
| [1067] | 76 | for (int ic = 1; ic <= 2; ic++) {
|
|---|
| [1069] | 77 | QString mountpoint = settings.value(QString("mountpoint_%1").arg(ic)).toString();
|
|---|
| [1123] | 78 | QString outFileName = settings.value(QString("outFile_%1").arg(ic)).toString();
|
|---|
| 79 | if (!mountpoint.isEmpty() || !outFileName.isEmpty()) {
|
|---|
| [1698] | 80 | _caster.push_back(new t_bnscaster(mountpoint, outFileName, ic));
|
|---|
| [1068] | 81 | connect(_caster.back(), SIGNAL(error(const QByteArray)),
|
|---|
| 82 | this, SLOT(slotError(const QByteArray)));
|
|---|
| 83 | connect(_caster.back(), SIGNAL(newMessage(const QByteArray)),
|
|---|
| 84 | this, SLOT(slotMessage(const QByteArray)));
|
|---|
| 85 | }
|
|---|
| [1067] | 86 | }
|
|---|
| 87 |
|
|---|
| [1065] | 88 | // Log File
|
|---|
| 89 | // --------
|
|---|
| [983] | 90 | QIODevice::OpenMode oMode;
|
|---|
| 91 | if (Qt::CheckState(settings.value("fileAppend").toInt()) == Qt::Checked) {
|
|---|
| 92 | oMode = QIODevice::WriteOnly | QIODevice::Unbuffered | QIODevice::Append;
|
|---|
| 93 | }
|
|---|
| 94 | else {
|
|---|
| 95 | oMode = QIODevice::WriteOnly | QIODevice::Unbuffered;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| [816] | 98 | QString logFileName = settings.value("logFile").toString();
|
|---|
| 99 | if (logFileName.isEmpty()) {
|
|---|
| [947] | 100 | _logFile = 0;
|
|---|
| 101 | _logStream = 0;
|
|---|
| [812] | 102 | }
|
|---|
| [816] | 103 | else {
|
|---|
| 104 | _logFile = new QFile(logFileName);
|
|---|
| [983] | 105 | if (_logFile->open(oMode)) {
|
|---|
| [816] | 106 | _logStream = new QTextStream(_logFile);
|
|---|
| 107 | }
|
|---|
| [948] | 108 | else {
|
|---|
| 109 | _logStream = 0;
|
|---|
| 110 | }
|
|---|
| [816] | 111 | }
|
|---|
| [847] | 112 |
|
|---|
| [1072] | 113 | // Echo input from RTNet into a file
|
|---|
| 114 | // ---------------------------------
|
|---|
| 115 | QString echoFileName = settings.value("inpEcho").toString();
|
|---|
| 116 | if (echoFileName.isEmpty()) {
|
|---|
| 117 | _echoFile = 0;
|
|---|
| 118 | _echoStream = 0;
|
|---|
| 119 | }
|
|---|
| 120 | else {
|
|---|
| 121 | _echoFile = new QFile(echoFileName);
|
|---|
| 122 | if (_echoFile->open(oMode)) {
|
|---|
| 123 | _echoStream = new QTextStream(_echoFile);
|
|---|
| 124 | }
|
|---|
| 125 | else {
|
|---|
| 126 | _echoStream = 0;
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| [847] | 130 | // RINEX writer
|
|---|
| 131 | // ------------
|
|---|
| 132 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
|---|
| 133 | _rnx = 0;
|
|---|
| 134 | }
|
|---|
| 135 | else {
|
|---|
| [850] | 136 | QString prep = "BNS";
|
|---|
| [857] | 137 | QString ext = ".clk";
|
|---|
| [850] | 138 | QString path = settings.value("rnxPath").toString();
|
|---|
| 139 | QString intr = settings.value("rnxIntr").toString();
|
|---|
| 140 | int sampl = settings.value("rnxSampl").toInt();
|
|---|
| 141 | _rnx = new bnsRinex(prep, ext, path, intr, sampl);
|
|---|
| [847] | 142 | }
|
|---|
| [848] | 143 |
|
|---|
| 144 | // SP3 writer
|
|---|
| 145 | // ----------
|
|---|
| 146 | if ( settings.value("sp3Path").toString().isEmpty() ) {
|
|---|
| 147 | _sp3 = 0;
|
|---|
| 148 | }
|
|---|
| 149 | else {
|
|---|
| [850] | 150 | QString prep = "BNS";
|
|---|
| [857] | 151 | QString ext = ".sp3";
|
|---|
| [850] | 152 | QString path = settings.value("sp3Path").toString();
|
|---|
| 153 | QString intr = settings.value("sp3Intr").toString();
|
|---|
| 154 | int sampl = settings.value("sp3Sampl").toInt();
|
|---|
| 155 | _sp3 = new bnsSP3(prep, ext, path, intr, sampl);
|
|---|
| [848] | 156 | }
|
|---|
| [756] | 157 | }
|
|---|
| 158 |
|
|---|
| 159 | // Destructor
|
|---|
| 160 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [757] | 161 | t_bns::~t_bns() {
|
|---|
| [763] | 162 | deleteBnsEph();
|
|---|
| [769] | 163 | delete _clkServer;
|
|---|
| [837] | 164 | delete _clkSocket;
|
|---|
| [1066] | 165 | for (int ic = 0; ic < _caster.size(); ic++) {
|
|---|
| 166 | delete _caster.at(ic);
|
|---|
| 167 | }
|
|---|
| [816] | 168 | delete _logStream;
|
|---|
| [812] | 169 | delete _logFile;
|
|---|
| [1072] | 170 | delete _echoStream;
|
|---|
| 171 | delete _echoFile;
|
|---|
| [779] | 172 | QMapIterator<QString, t_ephPair*> it(_ephList);
|
|---|
| 173 | while (it.hasNext()) {
|
|---|
| 174 | it.next();
|
|---|
| 175 | delete it.value();
|
|---|
| 176 | }
|
|---|
| [849] | 177 | delete _rnx;
|
|---|
| 178 | delete _sp3;
|
|---|
| [756] | 179 | }
|
|---|
| 180 |
|
|---|
| [763] | 181 | // Delete bns thread
|
|---|
| 182 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 183 | void t_bns::deleteBnsEph() {
|
|---|
| 184 | if (_bnseph) {
|
|---|
| 185 | _bnseph->terminate();
|
|---|
| [764] | 186 | _bnseph->wait(100);
|
|---|
| [763] | 187 | delete _bnseph;
|
|---|
| 188 | _bnseph = 0;
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| [756] | 192 | // Write a Program Message
|
|---|
| 193 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [758] | 194 | void t_bns::slotMessage(const QByteArray msg) {
|
|---|
| [816] | 195 | if (_logStream) {
|
|---|
| [1217] | 196 | QString txt = QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ");
|
|---|
| 197 | *_logStream << txt << msg << endl;
|
|---|
| [818] | 198 | _logStream->flush();
|
|---|
| [812] | 199 | }
|
|---|
| [757] | 200 | emit(newMessage(msg));
|
|---|
| [756] | 201 | }
|
|---|
| 202 |
|
|---|
| [760] | 203 | // Write a Program Message
|
|---|
| 204 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 205 | void t_bns::slotError(const QByteArray msg) {
|
|---|
| [816] | 206 | if (_logStream) {
|
|---|
| 207 | *_logStream << msg << endl;
|
|---|
| [818] | 208 | _logStream->flush();
|
|---|
| [812] | 209 | }
|
|---|
| [763] | 210 | deleteBnsEph();
|
|---|
| [760] | 211 | emit(error(msg));
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| [769] | 214 | // New Connection
|
|---|
| 215 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 216 | void t_bns::slotNewConnection() {
|
|---|
| [1208] | 217 | //slotMessage("t_bns::slotNewConnection");
|
|---|
| 218 | slotMessage("Clocks & orbits port: Waiting for client to connect"); // weber
|
|---|
| [787] | 219 | delete _clkSocket;
|
|---|
| [769] | 220 | _clkSocket = _clkServer->nextPendingConnection();
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| [784] | 223 | //
|
|---|
| 224 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [1058] | 225 | void t_bns::slotNewEph(t_eph* ep, int nBytes) {
|
|---|
| [784] | 226 |
|
|---|
| 227 | QMutexLocker locker(&_mutex);
|
|---|
| 228 |
|
|---|
| [1058] | 229 | emit(newEphBytes(nBytes));
|
|---|
| 230 |
|
|---|
| [784] | 231 | t_ephPair* pair;
|
|---|
| [884] | 232 | if ( !_ephList.contains(ep->prn()) ) {
|
|---|
| [784] | 233 | pair = new t_ephPair();
|
|---|
| [884] | 234 | _ephList.insert(ep->prn(), pair);
|
|---|
| [784] | 235 | }
|
|---|
| 236 | else {
|
|---|
| [884] | 237 | pair = _ephList[ep->prn()];
|
|---|
| [784] | 238 | }
|
|---|
| 239 |
|
|---|
| 240 | if (pair->eph == 0) {
|
|---|
| 241 | pair->eph = ep;
|
|---|
| 242 | }
|
|---|
| 243 | else {
|
|---|
| [884] | 244 | if (ep->isNewerThan(pair->eph)) {
|
|---|
| [784] | 245 | delete pair->oldEph;
|
|---|
| 246 | pair->oldEph = pair->eph;
|
|---|
| 247 | pair->eph = ep;
|
|---|
| 248 | }
|
|---|
| 249 | else {
|
|---|
| 250 | delete ep;
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| [756] | 255 | // Start
|
|---|
| 256 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [757] | 257 | void t_bns::run() {
|
|---|
| [769] | 258 |
|
|---|
| [758] | 259 | slotMessage("============ Start BNS ============");
|
|---|
| [770] | 260 |
|
|---|
| [828] | 261 | // Start Thread that retrieves broadcast Ephemeris
|
|---|
| 262 | // -----------------------------------------------
|
|---|
| [758] | 263 | _bnseph->start();
|
|---|
| [769] | 264 |
|
|---|
| [770] | 265 | // Endless loop
|
|---|
| 266 | // ------------
|
|---|
| [769] | 267 | while (true) {
|
|---|
| [836] | 268 |
|
|---|
| 269 | if (_clkSocket && _clkSocket->thread() != currentThread()) {
|
|---|
| 270 | emit(moveSocket(currentThread()));
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| [796] | 273 | if (_clkSocket && _clkSocket->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 274 | if ( _clkSocket->canReadLine()) {
|
|---|
| 275 | readEpoch();
|
|---|
| 276 | }
|
|---|
| [809] | 277 | else {
|
|---|
| 278 | _clkSocket->waitForReadyRead(10);
|
|---|
| 279 | }
|
|---|
| [769] | 280 | }
|
|---|
| 281 | else {
|
|---|
| [794] | 282 | msleep(10);
|
|---|
| [769] | 283 | }
|
|---|
| 284 | }
|
|---|
| [756] | 285 | }
|
|---|
| 286 |
|
|---|
| [778] | 287 | //
|
|---|
| 288 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [784] | 289 | void t_bns::readEpoch() {
|
|---|
| [778] | 290 |
|
|---|
| [1670] | 291 | bnsSettings settings;
|
|---|
| 292 |
|
|---|
| [1197] | 293 | // Read the first line (if not already read)
|
|---|
| 294 | // -----------------------------------------
|
|---|
| 295 | if (_clkLine.indexOf('*') == -1) {
|
|---|
| 296 | _clkLine = _clkSocket->readLine();
|
|---|
| 297 | if (_echoStream) {
|
|---|
| 298 | *_echoStream << _clkLine;
|
|---|
| 299 | _echoStream->flush();
|
|---|
| 300 | }
|
|---|
| 301 | emit(newClkBytes(_clkLine.length()));
|
|---|
| [1072] | 302 | }
|
|---|
| 303 |
|
|---|
| [1197] | 304 | if (_clkLine.indexOf('*') == -1) {
|
|---|
| [784] | 305 | return;
|
|---|
| [778] | 306 | }
|
|---|
| 307 |
|
|---|
| [1197] | 308 | QTextStream in(_clkLine);
|
|---|
| [784] | 309 |
|
|---|
| 310 | QString hlp;
|
|---|
| [1197] | 311 | int year, month, day, hour, min;
|
|---|
| 312 | double sec;
|
|---|
| 313 | in >> hlp >> year >> month >> day >> hour >> min >> sec;
|
|---|
| 314 |
|
|---|
| 315 | int GPSweek;
|
|---|
| [798] | 316 | double GPSweeks;
|
|---|
| [784] | 317 |
|
|---|
| [1197] | 318 | GPSweekFromYMDhms(year, month, day, hour, min, sec, GPSweek, GPSweeks);
|
|---|
| [784] | 319 |
|
|---|
| [1197] | 320 | QStringList prns;
|
|---|
| [874] | 321 |
|
|---|
| [1197] | 322 | // Loop over all satellites
|
|---|
| 323 | // ------------------------
|
|---|
| 324 | QStringList lines;
|
|---|
| 325 | for (;;) {
|
|---|
| 326 | if (!_clkSocket->canReadLine()) {
|
|---|
| [1198] | 327 | break;
|
|---|
| [1197] | 328 | }
|
|---|
| 329 | _clkLine = _clkSocket->readLine();
|
|---|
| 330 | if (_echoStream) {
|
|---|
| 331 | *_echoStream << _clkLine;
|
|---|
| 332 | _echoStream->flush();
|
|---|
| 333 | }
|
|---|
| 334 | if (_clkLine[0] == '*') {
|
|---|
| 335 | return;
|
|---|
| 336 | }
|
|---|
| 337 | if (_clkLine[0] == 'P') {
|
|---|
| 338 | _clkLine.remove(0,1);
|
|---|
| 339 | lines.push_back(_clkLine);
|
|---|
| 340 | }
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | if (lines.size() > 0) {
|
|---|
| 344 |
|
|---|
| [922] | 345 | QStringList prns;
|
|---|
| 346 |
|
|---|
| [1066] | 347 | for (int ic = 0; ic < _caster.size(); ic++) {
|
|---|
| 348 | _caster.at(ic)->open();
|
|---|
| [927] | 349 |
|
|---|
| [1066] | 350 | for (int oldEph = 0; oldEph <= 0; oldEph++) { // TODO: handle old ephemeris
|
|---|
| 351 |
|
|---|
| 352 | struct ClockOrbit co;
|
|---|
| 353 | memset(&co, 0, sizeof(co));
|
|---|
| 354 | co.GPSEpochTime = (int)GPSweeks;
|
|---|
| 355 | co.GLONASSEpochTime = (int)fmod(GPSweeks, 86400.0);
|
|---|
| 356 | co.ClockDataSupplied = 1;
|
|---|
| 357 | co.OrbitDataSupplied = 1;
|
|---|
| 358 | co.SatRefPoint = POINT_CENTER;
|
|---|
| 359 | co.SatRefDatum = DATUM_ITRF;
|
|---|
| 360 |
|
|---|
| [1197] | 361 | for (int ii = 0; ii < lines.size(); ii++) {
|
|---|
| 362 |
|
|---|
| [1066] | 363 | QString prn;
|
|---|
| 364 | ColumnVector xx(5);
|
|---|
| 365 | t_eph* ep = 0;
|
|---|
| 366 |
|
|---|
| [1075] | 367 | if (oldEph == 0 && ic == 0) {
|
|---|
| [1197] | 368 | QTextStream in(lines[ii].toAscii());
|
|---|
| [1066] | 369 | in >> prn;
|
|---|
| 370 | prns << prn;
|
|---|
| 371 | if ( _ephList.contains(prn) ) {
|
|---|
| [1698] | 372 | in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5);
|
|---|
| [1197] | 373 | xx(1) *= 1e3;
|
|---|
| 374 | xx(2) *= 1e3;
|
|---|
| 375 | xx(3) *= 1e3;
|
|---|
| 376 | xx(4) *= 1e-6;
|
|---|
| [1670] | 377 |
|
|---|
| [1698] | 378 | // Clocks without corrections
|
|---|
| 379 | // --------------------------
|
|---|
| 380 | if ( _caster.at(ic)->beClocks() ) {
|
|---|
| 381 | xx(4) -= xx(5) / 299792458.0;
|
|---|
| 382 | }
|
|---|
| [1066] | 383 |
|
|---|
| 384 | t_ephPair* pair = _ephList[prn];
|
|---|
| 385 | pair->xx = xx;
|
|---|
| 386 | ep = pair->eph;
|
|---|
| 387 | }
|
|---|
| [872] | 388 | }
|
|---|
| [1066] | 389 | else {
|
|---|
| [1197] | 390 | prn = prns[ii];
|
|---|
| [1066] | 391 | if ( _ephList.contains(prn) ) {
|
|---|
| 392 | t_ephPair* pair = _ephList[prn];
|
|---|
| 393 | prn = pair->eph->prn();
|
|---|
| 394 | xx = pair->xx;
|
|---|
| [1076] | 395 | if (oldEph) {
|
|---|
| 396 | ep = pair->oldEph;
|
|---|
| 397 | }
|
|---|
| 398 | else {
|
|---|
| 399 | ep = pair->eph;
|
|---|
| 400 | }
|
|---|
| [1066] | 401 | }
|
|---|
| [873] | 402 | }
|
|---|
| [1066] | 403 |
|
|---|
| 404 | if (ep != 0) {
|
|---|
| 405 | struct ClockOrbit::SatData* sd = 0;
|
|---|
| 406 | if (prn[0] == 'G') {
|
|---|
| 407 | sd = co.Sat + co.NumberOfGPSSat;
|
|---|
| 408 | ++co.NumberOfGPSSat;
|
|---|
| 409 | }
|
|---|
| 410 | else if (prn[0] == 'R') {
|
|---|
| 411 | sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
|
|---|
| 412 | ++co.NumberOfGLONASSSat;
|
|---|
| 413 | }
|
|---|
| 414 | if (sd) {
|
|---|
| 415 | QString outLine;
|
|---|
| [1102] | 416 | processSatellite(oldEph, ic, _caster.at(ic)->crdTrafo(), ep,
|
|---|
| 417 | GPSweek, GPSweeks, prn, xx, sd, outLine);
|
|---|
| [1074] | 418 | _caster.at(ic)->printAscii(outLine);
|
|---|
| [1066] | 419 | }
|
|---|
| 420 | }
|
|---|
| [873] | 421 | }
|
|---|
| [1066] | 422 |
|
|---|
| [1123] | 423 | if ( _caster.at(ic)->usedSocket() &&
|
|---|
| [1066] | 424 | (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
|
|---|
| 425 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
|---|
| 426 | int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
|---|
| 427 | if (len > 0) {
|
|---|
| [1262] | 428 | if (_caster.at(ic)->ic() == 1) { emit(newOutBytes1(len));}
|
|---|
| 429 | if (_caster.at(ic)->ic() == 2) { emit(newOutBytes2(len));}
|
|---|
| [1066] | 430 | _caster.at(ic)->write(obuffer, len);
|
|---|
| [872] | 431 | }
|
|---|
| 432 | }
|
|---|
| [863] | 433 | }
|
|---|
| 434 | }
|
|---|
| [780] | 435 | }
|
|---|
| [778] | 436 | }
|
|---|
| [784] | 437 |
|
|---|
| 438 | //
|
|---|
| 439 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [1102] | 440 | void t_bns::processSatellite(int oldEph, int iCaster, bool trafo, t_eph* ep,
|
|---|
| 441 | int GPSweek, double GPSweeks, const QString& prn,
|
|---|
| [1066] | 442 | const ColumnVector& xx,
|
|---|
| [1065] | 443 | struct ClockOrbit::SatData* sd,
|
|---|
| 444 | QString& outLine) {
|
|---|
| [784] | 445 |
|
|---|
| [799] | 446 | ColumnVector xB(4);
|
|---|
| [802] | 447 | ColumnVector vv(3);
|
|---|
| [799] | 448 |
|
|---|
| [884] | 449 | ep->position(GPSweek, GPSweeks, xB, vv);
|
|---|
| [799] | 450 |
|
|---|
| [984] | 451 | ColumnVector xyz = xx.Rows(1,3);
|
|---|
| [1066] | 452 | if (trafo) {
|
|---|
| [985] | 453 | crdTrafo(GPSweek, xyz);
|
|---|
| [984] | 454 | }
|
|---|
| [927] | 455 |
|
|---|
| [984] | 456 | ColumnVector dx = xyz - xB.Rows(1,3);
|
|---|
| 457 |
|
|---|
| [804] | 458 | double dClk = (xx(4) - xB(4)) * 299792458.0;
|
|---|
| 459 | ColumnVector rsw(3);
|
|---|
| [800] | 460 |
|
|---|
| [806] | 461 | XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw);
|
|---|
| [804] | 462 |
|
|---|
| [863] | 463 | if (sd) {
|
|---|
| 464 | sd->ID = prn.mid(1).toInt();
|
|---|
| [884] | 465 | sd->IOD = ep->IOD();
|
|---|
| [862] | 466 | sd->Clock.DeltaA0 = dClk;
|
|---|
| 467 | sd->Orbit.DeltaRadial = rsw(1);
|
|---|
| 468 | sd->Orbit.DeltaAlongTrack = rsw(2);
|
|---|
| 469 | sd->Orbit.DeltaCrossTrack = rsw(3);
|
|---|
| [863] | 470 | }
|
|---|
| [862] | 471 |
|
|---|
| [1065] | 472 | char oldCh = (oldEph ? '!' : ' ');
|
|---|
| 473 | outLine.sprintf("%c %d %.1f %s %3d %10.3f %8.3f %8.3f %8.3f\n",
|
|---|
| 474 | oldCh, GPSweek, GPSweeks, ep->prn().toAscii().data(),
|
|---|
| 475 | ep->IOD(), dClk, rsw(1), rsw(2), rsw(3));
|
|---|
| 476 |
|
|---|
| [1102] | 477 | if (!oldEph && iCaster == 0) {
|
|---|
| [923] | 478 | if (_rnx) {
|
|---|
| 479 | _rnx->write(GPSweek, GPSweeks, prn, xx);
|
|---|
| 480 | }
|
|---|
| 481 | if (_sp3) {
|
|---|
| 482 | _sp3->write(GPSweek, GPSweeks, prn, xx);
|
|---|
| 483 | }
|
|---|
| [847] | 484 | }
|
|---|
| [784] | 485 | }
|
|---|
| [836] | 486 |
|
|---|
| 487 | //
|
|---|
| 488 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 489 | void t_bns::slotMoveSocket(QThread* tt) {
|
|---|
| 490 | _clkSocket->setParent(0);
|
|---|
| 491 | _clkSocket->moveToThread(tt);
|
|---|
| [1209] | 492 | //slotMessage("bns::slotMoveSocket");
|
|---|
| 493 | slotMessage("Clocks & orbits port: Socket moved to thread"); // weber
|
|---|
| [836] | 494 | }
|
|---|
| [984] | 495 |
|
|---|
| 496 | // Transform Coordinates IGS -> ETRF
|
|---|
| 497 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [985] | 498 | void t_bns::crdTrafo(int GPSWeek, ColumnVector& xyz) {
|
|---|
| [984] | 499 |
|
|---|
| [1243] | 500 | // Current epoch minus 2000.0 in years
|
|---|
| 501 | // ------------------------------------
|
|---|
| 502 | double dt = (GPSWeek - (1042.0+6.0/7.0)) / 365.2422 * 7.0;
|
|---|
| 503 |
|
|---|
| [985] | 504 | ColumnVector dx(3);
|
|---|
| [1243] | 505 | dx(1) = 0.0541 - dt * 0.0002;
|
|---|
| 506 | dx(2) = 0.0502 + dt * 0.0001;
|
|---|
| 507 | dx(3) = -0.0538 - dt * 0.0018;
|
|---|
| 508 |
|
|---|
| [1100] | 509 | static const double arcSec = 180.0 * 3600.0 / M_PI;
|
|---|
| [1245] | 510 | double ox = ( 0.000891 + dt * 0.000081) / arcSec;
|
|---|
| 511 | double oy = ( 0.005390 + dt * 0.000490) / arcSec;
|
|---|
| 512 | double oz = (-0.008712 - dt * 0.000792) / arcSec;
|
|---|
| [984] | 513 |
|
|---|
| [1245] | 514 | double sc = 1.0 + 0.4e-9 + dt * 0.08e-9;
|
|---|
| [1243] | 515 |
|
|---|
| [1245] | 516 | Matrix rMat(3,3);
|
|---|
| 517 | rMat(1,1) = 1.0;
|
|---|
| [985] | 518 | rMat(1,2) = -oz;
|
|---|
| 519 | rMat(1,3) = oy;
|
|---|
| 520 | rMat(2,1) = oz;
|
|---|
| [1245] | 521 | rMat(2,2) = 1.0;
|
|---|
| [985] | 522 | rMat(2,3) = -ox;
|
|---|
| 523 | rMat(3,1) = -oy;
|
|---|
| 524 | rMat(3,2) = ox;
|
|---|
| [1245] | 525 | rMat(3,3) = 1.0;
|
|---|
| [985] | 526 |
|
|---|
| 527 |
|
|---|
| [1245] | 528 | xyz = sc * rMat * xyz + dx;
|
|---|
| [984] | 529 | }
|
|---|