source: ntrip/trunk/BNS/bns.cpp@ 2617

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