source: ntrip/branches/BNC_2.12/src/ephemeris.cpp@ 8942

Last change on this file since 8942 was 8942, checked in by stuerze, 4 years ago

BDS SSR IOD is changed from 24 into 8 bit with respect to RTCM SSR proposal version 08

File size: 48.0 KB
RevLine 
[1025]1#include <sstream>
[2234]2#include <iostream>
[1025]3#include <iomanip>
[1239]4#include <cstring>
[1025]5
[2234]6#include <newmatio.h>
7
[1025]8#include "ephemeris.h"
[2221]9#include "bncutils.h"
[2285]10#include "bnctime.h"
[5070]11#include "bnccore.h"
[5839]12#include "bncutils.h"
[6141]13#include "satObs.h"
[6044]14#include "pppInclude.h"
[6400]15#include "pppModel.h"
[1025]16
17using namespace std;
18
[5749]19// Constructor
20////////////////////////////////////////////////////////////////////////////
21t_eph::t_eph() {
[6518]22 _checkState = unchecked;
23 _orbCorr = 0;
24 _clkCorr = 0;
[5749]25}
[7278]26// Destructor
27////////////////////////////////////////////////////////////////////////////
28t_eph::~t_eph() {
29 if (_orbCorr)
30 delete _orbCorr;
31 if (_clkCorr)
32 delete _clkCorr;
33}
[5749]34
[7481]35//
[5749]36////////////////////////////////////////////////////////////////////////////
[6141]37void t_eph::setOrbCorr(const t_orbCorr* orbCorr) {
[8006]38 if (_orbCorr) {
39 delete _orbCorr;
40 _orbCorr = 0;
41 }
[6141]42 _orbCorr = new t_orbCorr(*orbCorr);
[5749]43}
44
[7481]45//
[5749]46////////////////////////////////////////////////////////////////////////////
[6141]47void t_eph::setClkCorr(const t_clkCorr* clkCorr) {
[8006]48 if (_clkCorr) {
49 delete _clkCorr;
50 _clkCorr = 0;
51 }
[6141]52 _clkCorr = new t_clkCorr(*clkCorr);
[5749]53}
54
[7481]55//
[5749]56////////////////////////////////////////////////////////////////////////////
[6109]57t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
[6518]58
[8420]59 if (_checkState == bad ||
[8615]60 _checkState == unhealthy ||
61 _checkState == outdated) {
[6518]62 return failure;
63 }
[6556]64 const QVector<int> updateInt = QVector<int>() << 1 << 2 << 5 << 10 << 15 << 30
65 << 60 << 120 << 240 << 300 << 600
66 << 900 << 1800 << 3600 << 7200
67 << 10800;
[8541]68 xc.ReSize(6);
[5749]69 vv.ReSize(3);
[6213]70 if (position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data()) != success) {
71 return failure;
72 }
[5789]73 if (useCorr) {
[5839]74 if (_orbCorr && _clkCorr) {
[5849]75 double dtO = tt - _orbCorr->_time;
[6556]76 if (_orbCorr->_updateInt) {
77 dtO -= (0.5 * updateInt[_orbCorr->_updateInt]);
78 }
[5839]79 ColumnVector dx(3);
[5849]80 dx[0] = _orbCorr->_xr[0] + _orbCorr->_dotXr[0] * dtO;
81 dx[1] = _orbCorr->_xr[1] + _orbCorr->_dotXr[1] * dtO;
82 dx[2] = _orbCorr->_xr[2] + _orbCorr->_dotXr[2] * dtO;
83
[7133]84 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), dx, dx);
[5849]85
[5839]86 xc[0] -= dx[0];
87 xc[1] -= dx[1];
88 xc[2] -= dx[2];
[5849]89
[7133]90 ColumnVector dv(3);
91 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), _orbCorr->_dotXr, dv);
92
93 vv[0] -= dv[0];
94 vv[1] -= dv[1];
95 vv[2] -= dv[2];
96
[5849]97 double dtC = tt - _clkCorr->_time;
[6556]98 if (_clkCorr->_updateInt) {
99 dtC -= (0.5 * updateInt[_clkCorr->_updateInt]);
100 }
[7014]101 xc[3] += _clkCorr->_dClk + _clkCorr->_dotDClk * dtC + _clkCorr->_dotDotDClk * dtC * dtC;
[5839]102 }
103 else {
104 return failure;
105 }
[5749]106 }
107 return success;
108}
109
[6801]110//
111//////////////////////////////////////////////////////////////////////////////
112QString t_eph::rinexDateStr(const bncTime& tt, const t_prn& prn, double version) {
113 QString prnStr(prn.toString().c_str());
114 return rinexDateStr(tt, prnStr, version);
115}
116
117//
118//////////////////////////////////////////////////////////////////////////////
119QString t_eph::rinexDateStr(const bncTime& tt, const QString& prnStr, double version) {
120
121 QString datStr;
122
123 unsigned year, month, day, hour, min;
124 double sec;
125 tt.civil_date(year, month, day);
126 tt.civil_time(hour, min, sec);
127
128 QTextStream out(&datStr);
129
130 if (version < 3.0) {
131 QString prnHlp = prnStr.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
132 out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
133 .arg(year % 100, 2, 10, QChar('0'))
134 .arg(month, 2)
135 .arg(day, 2)
136 .arg(hour, 2)
137 .arg(min, 2)
138 .arg(sec, 5, 'f',1);
139 }
140 else {
141 out << prnStr << QString(" %1 %2 %3 %4 %5 %6")
142 .arg(year, 4)
143 .arg(month, 2, 10, QChar('0'))
144 .arg(day, 2, 10, QChar('0'))
145 .arg(hour, 2, 10, QChar('0'))
146 .arg(min, 2, 10, QChar('0'))
147 .arg(int(sec), 2, 10, QChar('0'));
148 }
149
150 return datStr;
151}
152
153// Constructor
154//////////////////////////////////////////////////////////////////////////////
155t_ephGPS::t_ephGPS(float rnxVersion, const QStringList& lines) {
156
157 const int nLines = 8;
158
159 if (lines.size() != nLines) {
160 _checkState = bad;
161 return;
162 }
163
164 // RINEX Format
165 // ------------
166 int fieldLen = 19;
167
168 int pos[4];
169 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
170 pos[1] = pos[0] + fieldLen;
171 pos[2] = pos[1] + fieldLen;
172 pos[3] = pos[2] + fieldLen;
173
174 // Read eight lines
175 // ----------------
176 for (int iLine = 0; iLine < nLines; iLine++) {
177 QString line = lines[iLine];
178
179 if ( iLine == 0 ) {
180 QTextStream in(line.left(pos[1]).toAscii());
181 int year, month, day, hour, min;
182 double sec;
183
[7139]184 QString prnStr, n;
[6880]185 in >> prnStr;
[7639]186
187 if (prnStr.size() == 1 &&
[8167]188 (prnStr[0] == 'G' ||
189 prnStr[0] == 'J' ||
190 prnStr[0] == 'I')) {
[7139]191 in >> n;
192 prnStr.append(n);
[6880]193 }
[7639]194
[6880]195 in >> year >> month >> day >> hour >> min >> sec;
[6801]196 if (prnStr.at(0) == 'G') {
197 _prn.set('G', prnStr.mid(1).toInt());
198 }
199 else if (prnStr.at(0) == 'J') {
200 _prn.set('J', prnStr.mid(1).toInt());
201 }
[8167]202 else if (prnStr.at(0) == 'I') {
203 _prn.set('I', prnStr.mid(1).toInt());
204 }
[6801]205 else {
206 _prn.set('G', prnStr.toInt());
207 }
208
209 if (year < 80) {
210 year += 2000;
211 }
212 else if (year < 100) {
213 year += 1900;
214 }
215
216 _TOC.set(year, month, day, hour, min, sec);
217
218 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
219 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
220 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
221 _checkState = bad;
222 return;
223 }
224 }
225
226 else if ( iLine == 1 ) {
227 if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
228 readDbl(line, pos[1], fieldLen, _Crs ) ||
229 readDbl(line, pos[2], fieldLen, _Delta_n) ||
230 readDbl(line, pos[3], fieldLen, _M0 ) ) {
231 _checkState = bad;
232 return;
233 }
234 }
235
236 else if ( iLine == 2 ) {
237 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
238 readDbl(line, pos[1], fieldLen, _e ) ||
239 readDbl(line, pos[2], fieldLen, _Cus ) ||
240 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
241 _checkState = bad;
242 return;
243 }
244 }
245
246 else if ( iLine == 3 ) {
247 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
248 readDbl(line, pos[1], fieldLen, _Cic ) ||
249 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
250 readDbl(line, pos[3], fieldLen, _Cis ) ) {
251 _checkState = bad;
252 return;
253 }
254 }
255
256 else if ( iLine == 4 ) {
257 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
258 readDbl(line, pos[1], fieldLen, _Crc ) ||
259 readDbl(line, pos[2], fieldLen, _omega ) ||
260 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
261 _checkState = bad;
262 return;
263 }
264 }
265
[8167]266 else if ( iLine == 5 && type() != t_eph::IRNSS) {
[6801]267 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
268 readDbl(line, pos[1], fieldLen, _L2Codes) ||
269 readDbl(line, pos[2], fieldLen, _TOEweek ) ||
270 readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
271 _checkState = bad;
272 return;
273 }
274 }
[8167]275 else if ( iLine == 5 && type() == t_eph::IRNSS) {
276 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
277 readDbl(line, pos[2], fieldLen, _TOEweek) ) {
278 _checkState = bad;
279 return;
280 }
281 }
[6801]282
[8167]283 else if ( iLine == 6 && type() != t_eph::IRNSS) {
[6801]284 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
285 readDbl(line, pos[1], fieldLen, _health) ||
286 readDbl(line, pos[2], fieldLen, _TGD ) ||
287 readDbl(line, pos[3], fieldLen, _IODC ) ) {
288 _checkState = bad;
289 return;
290 }
291 }
[8167]292 else if ( iLine == 6 && type() == t_eph::IRNSS) {
293 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
294 readDbl(line, pos[1], fieldLen, _health) ||
295 readDbl(line, pos[2], fieldLen, _TGD ) ) {
296 _checkState = bad;
297 return;
298 }
299 }
[6801]300 else if ( iLine == 7 ) {
301 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
302 _checkState = bad;
303 return;
304 }
[8926]305 // fitInterval is not valid for IRNSS
306 if (type() != t_eph::IRNSS) {
307 double fitIntervalRnx;
308 readDbl(line, pos[1], fieldLen, fitIntervalRnx);
[8932]309 if (type() == t_eph::GPS) { // in RINEX specified allways as time period for GPS
[8929]310 _fitInterval = fitIntervalRnx;
[8932]311 } else if (type() == t_eph::QZSS) { // specified as flag for QZSS
312 if (rnxVersion == 3.02) {
313 _fitInterval = fitIntervalRnx; // specified as time period
[8929]314 }
[8932]315 else {
316 _fitInterval = fitIntervalFromFlag(fitIntervalRnx, _IODC, t_eph::QZSS);
317 }
[8926]318 }
319 }
[6801]320 }
321 }
322}
323
[2222]324// Compute GPS Satellite Position (virtual)
[1025]325////////////////////////////////////////////////////////////////////////////
[6213]326t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[1025]327
[1098]328 static const double omegaEarth = 7292115.1467e-11;
[5277]329 static const double gmGRS = 398.6005e12;
[1025]330
[8541]331 memset(xc, 0, 6*sizeof(double));
[1025]332 memset(vv, 0, 3*sizeof(double));
333
334 double a0 = _sqrt_A * _sqrt_A;
335 if (a0 == 0) {
[6213]336 return failure;
[1025]337 }
338
[5277]339 double n0 = sqrt(gmGRS/(a0*a0*a0));
[4018]340
341 bncTime tt(GPSweek, GPSweeks);
[4543]342 double tk = tt - bncTime(int(_TOEweek), _TOEsec);
[4018]343
[1025]344 double n = n0 + _Delta_n;
345 double M = _M0 + n*tk;
346 double E = M;
347 double E_last;
[8370]348 int nLoop = 0;
[1025]349 do {
350 E_last = E;
351 E = M + _e*sin(E);
[8455]352
[8370]353 if (++nLoop == 100) {
354 return failure;
355 }
[1025]356 } while ( fabs(E-E_last)*a0 > 0.001 );
357 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
358 double u0 = v + _omega;
359 double sin2u0 = sin(2*u0);
360 double cos2u0 = cos(2*u0);
361 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
362 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
363 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
364 double xp = r*cos(u);
365 double yp = r*sin(u);
[7481]366 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
[4018]367 omegaEarth*_TOEsec;
[7278]368
[1025]369 double sinom = sin(OM);
370 double cosom = cos(OM);
371 double sini = sin(i);
372 double cosi = cos(i);
373 xc[0] = xp*cosom - yp*cosi*sinom;
374 xc[1] = xp*sinom + yp*cosi*cosom;
[7481]375 xc[2] = yp*sini;
376
[4018]377 double tc = tt - _TOC;
[2429]378 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
[1025]379
380 // Velocity
381 // --------
382 double tanv2 = tan(v/2);
383 double dEdM = 1 / (1 - _e*cos(E));
[7278]384 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
[1025]385 * dEdM * n;
386 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
387 double dotom = _OMEGADOT - omegaEarth;
388 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
[7278]389 double dotr = a0 * _e*sin(E) * dEdM * n
[1025]390 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
391 double dotx = dotr*cos(u) - r*sin(u)*dotu;
392 double doty = dotr*sin(u) + r*cos(u)*dotu;
393
394 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
395 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
396 + yp*sini*sinom*doti; // dX / di
397
398 vv[1] = sinom *dotx + cosi*cosom *doty
399 + xp*cosom*dotom - yp*cosi*sinom*dotom
400 - yp*sini*cosom*doti;
401
402 vv[2] = sini *doty + yp*cosi *doti;
[2429]403
404 // Relativistic Correction
405 // -----------------------
[7481]406 // correspondent to IGS convention and GPS ICD (and SSR standard)
[2429]407 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
[6213]408
[8541]409 xc[4] = _clock_drift + _clock_driftrate*tc;
410 xc[5] = _clock_driftrate;
411
[6213]412 return success;
[1025]413}
414
[6801]415// RINEX Format String
416//////////////////////////////////////////////////////////////////////////////
417QString t_ephGPS::toString(double version) const {
[2221]418
[6801]419 QString rnxStr = rinexDateStr(_TOC, _prn, version);
[2221]420
[6801]421 QTextStream out(&rnxStr);
[2221]422
[6801]423 out << QString("%1%2%3\n")
424 .arg(_clock_bias, 19, 'e', 12)
425 .arg(_clock_drift, 19, 'e', 12)
426 .arg(_clock_driftrate, 19, 'e', 12);
[2221]427
[6801]428 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
[2221]429
[8167]430 out << QString(fmt)
[6801]431 .arg(_IODE, 19, 'e', 12)
432 .arg(_Crs, 19, 'e', 12)
433 .arg(_Delta_n, 19, 'e', 12)
434 .arg(_M0, 19, 'e', 12);
435
436 out << QString(fmt)
437 .arg(_Cuc, 19, 'e', 12)
438 .arg(_e, 19, 'e', 12)
439 .arg(_Cus, 19, 'e', 12)
440 .arg(_sqrt_A, 19, 'e', 12);
441
442 out << QString(fmt)
443 .arg(_TOEsec, 19, 'e', 12)
444 .arg(_Cic, 19, 'e', 12)
445 .arg(_OMEGA0, 19, 'e', 12)
446 .arg(_Cis, 19, 'e', 12);
447
448 out << QString(fmt)
449 .arg(_i0, 19, 'e', 12)
450 .arg(_Crc, 19, 'e', 12)
451 .arg(_omega, 19, 'e', 12)
452 .arg(_OMEGADOT, 19, 'e', 12);
453
[8167]454 if (type() == t_eph::IRNSS) {
455 out << QString(fmt)
456 .arg(_IDOT, 19, 'e', 12)
[8804]457 .arg(0.0, 19, 'e', 12)
[8167]458 .arg(_TOEweek, 19, 'e', 12)
[8804]459 .arg(0.0, 19, 'e', 12);
[8167]460 }
461 else {
462 out << QString(fmt)
463 .arg(_IDOT, 19, 'e', 12)
464 .arg(_L2Codes, 19, 'e', 12)
465 .arg(_TOEweek, 19, 'e', 12)
466 .arg(_L2PFlag, 19, 'e', 12);
467 }
[6801]468
[8167]469 if (type() == t_eph::IRNSS) {
470 out << QString(fmt)
471 .arg(_ura, 19, 'e', 12)
472 .arg(_health, 19, 'e', 12)
473 .arg(_TGD, 19, 'e', 12)
[8804]474 .arg(0.0, 19, 'e', 12);
[8167]475 }
476 else {
477 out << QString(fmt)
478 .arg(_ura, 19, 'e', 12)
479 .arg(_health, 19, 'e', 12)
480 .arg(_TGD, 19, 'e', 12)
481 .arg(_IODC, 19, 'e', 12);
482 }
[6801]483
[7923]484 double tot = _TOT;
485 if (tot == 0.9999e9 && version < 3.0) {
486 tot = 0.0;
487 }
[8926]488 // fitInterval
[8930]489 if (type() == t_eph::IRNSS) {// not valid for IRNSS
[8167]490 out << QString(fmt)
491 .arg(tot, 19, 'e', 12)
[8804]492 .arg(0.0, 19, 'e', 12)
[8167]493 .arg("", 19, QChar(' '))
494 .arg("", 19, QChar(' '));
495 }
496 else {
[8932]497 // for GPS and QZSS in version 3.02 specified in hours
498 double fitIntervalRnx = _fitInterval;
499 // otherwise specified as flag
500 if (type() == t_eph::QZSS && version != 3.02) {
[8926]501 (_fitInterval == 2.0) ? fitIntervalRnx = 0.0 : fitIntervalRnx = 1.0;
502 }
[8167]503 out << QString(fmt)
[8926]504 .arg(tot, 19, 'e', 12)
505 .arg(fitIntervalRnx, 19, 'e', 12)
506 .arg("", 19, QChar(' '))
507 .arg("", 19, QChar(' '));
[8167]508 }
[6801]509 return rnxStr;
[2221]510}
511
[6801]512// Constructor
513//////////////////////////////////////////////////////////////////////////////
514t_ephGlo::t_ephGlo(float rnxVersion, const QStringList& lines) {
[2221]515
[6801]516 const int nLines = 4;
517
518 if (lines.size() != nLines) {
519 _checkState = bad;
520 return;
[6518]521 }
522
[6801]523 // RINEX Format
524 // ------------
525 int fieldLen = 19;
[2221]526
[6801]527 int pos[4];
528 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
529 pos[1] = pos[0] + fieldLen;
530 pos[2] = pos[1] + fieldLen;
531 pos[3] = pos[2] + fieldLen;
[2221]532
[6801]533 // Read four lines
534 // ---------------
535 for (int iLine = 0; iLine < nLines; iLine++) {
536 QString line = lines[iLine];
[2221]537
[6801]538 if ( iLine == 0 ) {
539 QTextStream in(line.left(pos[1]).toAscii());
[6213]540
[6801]541 int year, month, day, hour, min;
542 double sec;
[2221]543
[7139]544 QString prnStr, n;
[6880]545 in >> prnStr;
[7639]546 if (prnStr.size() == 1 && prnStr[0] == 'R') {
[7139]547 in >> n;
548 prnStr.append(n);
[6880]549 }
550 in >> year >> month >> day >> hour >> min >> sec;
[6801]551 if (prnStr.at(0) == 'R') {
552 _prn.set('R', prnStr.mid(1).toInt());
553 }
554 else {
555 _prn.set('R', prnStr.toInt());
556 }
[2221]557
[6801]558 if (year < 80) {
559 year += 2000;
560 }
561 else if (year < 100) {
562 year += 1900;
563 }
[2221]564
[6801]565 _gps_utc = gnumleap(year, month, day);
[2221]566
[6801]567 _TOC.set(year, month, day, hour, min, sec);
568 _TOC = _TOC + _gps_utc;
[8804]569 int nd = int((_TOC.gpssec())) / (24.0*60.0*60.0);
[6801]570 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
571 readDbl(line, pos[2], fieldLen, _gamma) ||
572 readDbl(line, pos[3], fieldLen, _tki ) ) {
573 _checkState = bad;
574 return;
575 }
[8804]576 _tki -= nd * 86400.0;
577 _tau = -_tau;
[6801]578 }
579
580 else if ( iLine == 1 ) {
581 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
582 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
583 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
584 readDbl(line, pos[3], fieldLen, _health ) ) {
585 _checkState = bad;
586 return;
587 }
588 }
589
590 else if ( iLine == 2 ) {
591 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
592 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
593 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
594 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
595 _checkState = bad;
596 return;
597 }
598 }
599
600 else if ( iLine == 3 ) {
601 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
602 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
603 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
604 readDbl(line, pos[3], fieldLen, _E ) ) {
605 _checkState = bad;
606 return;
607 }
608 }
609 }
610
611 // Initialize status vector
612 // ------------------------
613 _tt = _TOC;
[8697]614 _xv.ReSize(6); _xv = 0.0;
[6801]615 _xv(1) = _x_pos * 1.e3;
616 _xv(2) = _y_pos * 1.e3;
617 _xv(3) = _z_pos * 1.e3;
618 _xv(4) = _x_velocity * 1.e3;
619 _xv(5) = _y_velocity * 1.e3;
620 _xv(6) = _z_velocity * 1.e3;
[2221]621}
622
[6801]623// Compute Glonass Satellite Position (virtual)
[2771]624////////////////////////////////////////////////////////////////////////////
[6801]625t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[2771]626
[6801]627 static const double nominalStep = 10.0;
[2771]628
[8541]629 memset(xc, 0, 6*sizeof(double));
[2771]630 memset(vv, 0, 3*sizeof(double));
631
[6801]632 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
633
[8690]634 if (fabs(dtPos) > 24 * 3600.0) {
[6213]635 return failure;
[2771]636 }
637
[6801]638 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
639 double step = dtPos / nSteps;
[4018]640
[6801]641 double acc[3];
642 acc[0] = _x_acceleration * 1.e3;
643 acc[1] = _y_acceleration * 1.e3;
644 acc[2] = _z_acceleration * 1.e3;
645 for (int ii = 1; ii <= nSteps; ii++) {
646 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
647 _tt = _tt + step;
648 }
[4018]649
[6801]650 // Position and Velocity
651 // ---------------------
652 xc[0] = _xv(1);
653 xc[1] = _xv(2);
654 xc[2] = _xv(3);
[2771]655
[6801]656 vv[0] = _xv(4);
657 vv[1] = _xv(5);
658 vv[2] = _xv(6);
[2771]659
[6801]660 // Clock Correction
661 // ----------------
662 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
663 xc[3] = -_tau + _gamma * dtClk;
[2771]664
[8541]665 xc[4] = _gamma;
666 xc[5] = 0.0;
[8484]667
[6213]668 return success;
[2771]669}
670
[6801]671// RINEX Format String
[3659]672//////////////////////////////////////////////////////////////////////////////
[6801]673QString t_ephGlo::toString(double version) const {
[3664]674
[8804]675 QString rnxStr = rinexDateStr(_TOC -_gps_utc, _prn, version);
676 int nd = int((_TOC - _gps_utc).gpssec()) / (24.0*60.0*60.0);
[6801]677 QTextStream out(&rnxStr);
[3664]678
[6801]679 out << QString("%1%2%3\n")
[8804]680 .arg(-_tau, 19, 'e', 12)
681 .arg(_gamma, 19, 'e', 12)
682 .arg(_tki+nd*86400.0, 19, 'e', 12);
[3668]683
[6801]684 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
[3664]685
[6801]686 out << QString(fmt)
687 .arg(_x_pos, 19, 'e', 12)
688 .arg(_x_velocity, 19, 'e', 12)
689 .arg(_x_acceleration, 19, 'e', 12)
690 .arg(_health, 19, 'e', 12);
[3664]691
[6801]692 out << QString(fmt)
693 .arg(_y_pos, 19, 'e', 12)
694 .arg(_y_velocity, 19, 'e', 12)
695 .arg(_y_acceleration, 19, 'e', 12)
696 .arg(_frequency_number, 19, 'e', 12);
[3666]697
[6801]698 out << QString(fmt)
699 .arg(_z_pos, 19, 'e', 12)
700 .arg(_z_velocity, 19, 'e', 12)
701 .arg(_z_acceleration, 19, 'e', 12)
702 .arg(_E, 19, 'e', 12);
[3666]703
[6801]704 return rnxStr;
[3659]705}
706
[6801]707// Derivative of the state vector using a simple force model (static)
708////////////////////////////////////////////////////////////////////////////
709ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
710 double* acc) {
[3659]711
[6801]712 // State vector components
713 // -----------------------
714 ColumnVector rr = xv.rows(1,3);
715 ColumnVector vv = xv.rows(4,6);
[3699]716
[6801]717 // Acceleration
[3699]718 // ------------
[6801]719 static const double gmWGS = 398.60044e12;
720 static const double AE = 6378136.0;
721 static const double OMEGA = 7292115.e-11;
722 static const double C20 = -1082.6257e-6;
[3699]723
[6801]724 double rho = rr.norm_Frobenius();
725 double t1 = -gmWGS/(rho*rho*rho);
726 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
727 double t3 = OMEGA * OMEGA;
728 double t4 = 2.0 * OMEGA;
729 double z2 = rr(3) * rr(3);
[3699]730
[6801]731 // Vector of derivatives
732 // ---------------------
733 ColumnVector va(6);
734 va(1) = vv(1);
735 va(2) = vv(2);
736 va(3) = vv(3);
737 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
738 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
739 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
[3699]740
[6801]741 return va;
742}
[3699]743
[6801]744// IOD of Glonass Ephemeris (virtual)
745////////////////////////////////////////////////////////////////////////////
[7169]746unsigned int t_ephGlo::IOD() const {
[6801]747 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
[7054]748 return (unsigned long)tMoscow.daysec() / 900;
[3659]749}
750
[8188]751// Health status of Glonass Ephemeris (virtual)
752////////////////////////////////////////////////////////////////////////////
753unsigned int t_ephGlo::isUnhealthy() const {
[8216]754
[8218]755 if (_almanac_health_availablility_indicator) {
[8216]756 if ((_health == 0 && _almanac_health == 0) ||
757 (_health == 1 && _almanac_health == 0) ||
758 (_health == 1 && _almanac_health == 1)) {
759 return 1;
760 }
[8188]761 }
[8218]762 else if (!_almanac_health_availablility_indicator) {
763 if (_health) {
764 return 1;
765 }
766 }
[8216]767 return 0; /* (_health == 0 && _almanac_health == 1) or (_health == 0) */
[8188]768}
769
[3659]770// Constructor
771//////////////////////////////////////////////////////////////////////////////
[4891]772t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
[6809]773 int year, month, day, hour, min;
774 double sec;
775 QString prnStr;
[4891]776 const int nLines = 8;
777 if (lines.size() != nLines) {
[6518]778 _checkState = bad;
[4891]779 return;
780 }
781
782 // RINEX Format
783 // ------------
784 int fieldLen = 19;
[6792]785 double SVhealth = 0.0;
786 double datasource = 0.0;
[6798]787
[4891]788 int pos[4];
789 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
790 pos[1] = pos[0] + fieldLen;
791 pos[2] = pos[1] + fieldLen;
792 pos[3] = pos[2] + fieldLen;
793
794 // Read eight lines
795 // ----------------
796 for (int iLine = 0; iLine < nLines; iLine++) {
797 QString line = lines[iLine];
798
799 if ( iLine == 0 ) {
800 QTextStream in(line.left(pos[1]).toAscii());
[7140]801 QString n;
[6880]802 in >> prnStr;
[7639]803 if (prnStr.size() == 1 && prnStr[0] == 'E') {
[7139]804 in >> n;
805 prnStr.append(n);
[6880]806 }
807 in >> year >> month >> day >> hour >> min >> sec;
[4891]808 if (year < 80) {
809 year += 2000;
810 }
811 else if (year < 100) {
812 year += 1900;
813 }
814
815 _TOC.set(year, month, day, hour, min, sec);
816
817 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
818 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
819 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
[6518]820 _checkState = bad;
[4891]821 return;
822 }
823 }
824
825 else if ( iLine == 1 ) {
826 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
827 readDbl(line, pos[1], fieldLen, _Crs ) ||
828 readDbl(line, pos[2], fieldLen, _Delta_n) ||
829 readDbl(line, pos[3], fieldLen, _M0 ) ) {
[6518]830 _checkState = bad;
[4891]831 return;
832 }
833 }
834
835 else if ( iLine == 2 ) {
836 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
837 readDbl(line, pos[1], fieldLen, _e ) ||
838 readDbl(line, pos[2], fieldLen, _Cus ) ||
839 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
[6518]840 _checkState = bad;
[4891]841 return;
842 }
843 }
844
845 else if ( iLine == 3 ) {
846 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
847 readDbl(line, pos[1], fieldLen, _Cic ) ||
848 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
849 readDbl(line, pos[3], fieldLen, _Cis ) ) {
[6518]850 _checkState = bad;
[4891]851 return;
852 }
853 }
854
855 else if ( iLine == 4 ) {
856 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
857 readDbl(line, pos[1], fieldLen, _Crc ) ||
858 readDbl(line, pos[2], fieldLen, _omega ) ||
859 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
[6518]860 _checkState = bad;
[4891]861 return;
862 }
863 }
864
865 else if ( iLine == 5 ) {
[6792]866 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
867 readDbl(line, pos[1], fieldLen, datasource) ||
868 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
[6518]869 _checkState = bad;
[4891]870 return;
[6792]871 } else {
872 if (int(datasource) & (1<<8)) {
[6812]873 _fnav = true;
874 _inav = false;
[6792]875 } else if (int(datasource) & (1<<9)) {
[6812]876 _fnav = false;
877 _inav = true;
[6792]878 }
[6892]879 _TOEweek -= 1024.0;
[4891]880 }
881 }
882
883 else if ( iLine == 6 ) {
884 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
[6792]885 readDbl(line, pos[1], fieldLen, SVhealth) ||
[4891]886 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
887 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
[6518]888 _checkState = bad;
[4891]889 return;
[6792]890 } else {
891 // Bit 0
[6812]892 _e1DataInValid = (int(SVhealth) & (1<<0));
[6792]893 // Bit 1-2
[6802]894 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
[6792]895 // Bit 3
[6812]896 _e5aDataInValid = (int(SVhealth) & (1<<3));
[6792]897 // Bit 4-5
[6802]898 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
[6792]899 // Bit 6
[6812]900 _e5bDataInValid = (int(SVhealth) & (1<<6));
[6792]901 // Bit 7-8
[6802]902 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
[6809]903
904 if (prnStr.at(0) == 'E') {
[7140]905 _prn.set('E', prnStr.mid(1).toInt(), _inav ? 1 : 0);
[6809]906 }
[4891]907 }
908 }
909
910 else if ( iLine == 7 ) {
911 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
[6518]912 _checkState = bad;
[4891]913 return;
914 }
915 }
916 }
[3659]917}
[4013]918
[6801]919// Compute Galileo Satellite Position (virtual)
920////////////////////////////////////////////////////////////////////////////
921t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[4013]922
[6801]923 static const double omegaEarth = 7292115.1467e-11;
[8213]924 static const double gmWGS = 398.6004418e12;
[4023]925
[8541]926 memset(xc, 0, 6*sizeof(double));
[6801]927 memset(vv, 0, 3*sizeof(double));
[4023]928
[6801]929 double a0 = _sqrt_A * _sqrt_A;
930 if (a0 == 0) {
931 return failure;
932 }
[4023]933
[6801]934 double n0 = sqrt(gmWGS/(a0*a0*a0));
[4023]935
[6801]936 bncTime tt(GPSweek, GPSweeks);
937 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
[4023]938
[6801]939 double n = n0 + _Delta_n;
940 double M = _M0 + n*tk;
941 double E = M;
942 double E_last;
[8370]943 int nLoop = 0;
[6801]944 do {
945 E_last = E;
946 E = M + _e*sin(E);
[8370]947
948 if (++nLoop == 100) {
949 return failure;
950 }
[6801]951 } while ( fabs(E-E_last)*a0 > 0.001 );
952 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
953 double u0 = v + _omega;
954 double sin2u0 = sin(2*u0);
955 double cos2u0 = cos(2*u0);
956 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
957 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
958 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
959 double xp = r*cos(u);
960 double yp = r*sin(u);
961 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
962 omegaEarth*_TOEsec;
[4023]963
[6801]964 double sinom = sin(OM);
965 double cosom = cos(OM);
966 double sini = sin(i);
967 double cosi = cos(i);
968 xc[0] = xp*cosom - yp*cosi*sinom;
969 xc[1] = xp*sinom + yp*cosi*cosom;
970 xc[2] = yp*sini;
[4023]971
[6801]972 double tc = tt - _TOC;
973 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
[4023]974
[6801]975 // Velocity
976 // --------
977 double tanv2 = tan(v/2);
978 double dEdM = 1 / (1 - _e*cos(E));
979 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
980 * dEdM * n;
981 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
982 double dotom = _OMEGADOT - omegaEarth;
983 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
984 double dotr = a0 * _e*sin(E) * dEdM * n
985 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
986 double dotx = dotr*cos(u) - r*sin(u)*dotu;
987 double doty = dotr*sin(u) + r*cos(u)*dotu;
[4023]988
[6801]989 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
990 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
991 + yp*sini*sinom*doti; // dX / di
992
993 vv[1] = sinom *dotx + cosi*cosom *doty
994 + xp*cosom*dotom - yp*cosi*sinom*dotom
995 - yp*sini*cosom*doti;
996
997 vv[2] = sini *doty + yp*cosi *doti;
998
999 // Relativistic Correction
1000 // -----------------------
[7481]1001 // correspondent to Galileo ICD and to SSR standard
1002 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1003 // correspondent to IGS convention
1004 //xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
[6801]1005
[8541]1006 xc[4] = _clock_drift + _clock_driftrate*tc;
1007 xc[5] = _clock_driftrate;
1008
[6801]1009 return success;
[4023]1010}
1011
[8188]1012// Health status of Galileo Ephemeris (virtual)
1013////////////////////////////////////////////////////////////////////////////
1014unsigned int t_ephGal::isUnhealthy() const {
1015 if (_E5aHS && _E5bHS && _E1_bHS) {
1016 return 1;
1017 }
1018 return 0;
1019}
1020
[4023]1021// RINEX Format String
1022//////////////////////////////////////////////////////////////////////////////
1023QString t_ephGal::toString(double version) const {
1024
[4029]1025 QString rnxStr = rinexDateStr(_TOC, _prn, version);
[4023]1026
1027 QTextStream out(&rnxStr);
1028
1029 out << QString("%1%2%3\n")
1030 .arg(_clock_bias, 19, 'e', 12)
1031 .arg(_clock_drift, 19, 'e', 12)
1032 .arg(_clock_driftrate, 19, 'e', 12);
1033
1034 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1035
1036 out << QString(fmt)
1037 .arg(_IODnav, 19, 'e', 12)
1038 .arg(_Crs, 19, 'e', 12)
1039 .arg(_Delta_n, 19, 'e', 12)
1040 .arg(_M0, 19, 'e', 12);
1041
1042 out << QString(fmt)
1043 .arg(_Cuc, 19, 'e', 12)
1044 .arg(_e, 19, 'e', 12)
1045 .arg(_Cus, 19, 'e', 12)
1046 .arg(_sqrt_A, 19, 'e', 12);
1047
1048 out << QString(fmt)
1049 .arg(_TOEsec, 19, 'e', 12)
1050 .arg(_Cic, 19, 'e', 12)
1051 .arg(_OMEGA0, 19, 'e', 12)
1052 .arg(_Cis, 19, 'e', 12);
1053
1054 out << QString(fmt)
1055 .arg(_i0, 19, 'e', 12)
1056 .arg(_Crc, 19, 'e', 12)
1057 .arg(_omega, 19, 'e', 12)
1058 .arg(_OMEGADOT, 19, 'e', 12);
1059
[6792]1060 int dataSource = 0;
1061 int SVhealth = 0;
1062 double BGD_1_5A = _BGD_1_5A;
1063 double BGD_1_5B = _BGD_1_5B;
[6812]1064 if (_fnav) {
[6792]1065 dataSource |= (1<<1);
1066 dataSource |= (1<<8);
1067 BGD_1_5B = 0.0;
1068 // SVhealth
1069 // Bit 3 : E5a DVS
[6812]1070 if (_e5aDataInValid) {
[6792]1071 SVhealth |= (1<<3);
1072 }
1073 // Bit 4-5: E5a HS
1074 if (_E5aHS == 1.0) {
1075 SVhealth |= (1<<4);
1076 }
1077 else if (_E5aHS == 2.0) {
1078 SVhealth |= (1<<5);
1079 }
1080 else if (_E5aHS == 3.0) {
1081 SVhealth |= (1<<4);
1082 SVhealth |= (1<<5);
1083 }
1084 }
[6812]1085 else if(_inav) {
[6803]1086 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1087 // and RNXv3.03 says both can be set if the navigation messages were merged
[5539]1088 dataSource |= (1<<0);
[6792]1089 dataSource |= (1<<2);
[5540]1090 dataSource |= (1<<9);
[6792]1091 // SVhealth
1092 // Bit 0 : E1-B DVS
[6812]1093 if (_e1DataInValid) {
[6792]1094 SVhealth |= (1<<0);
1095 }
1096 // Bit 1-2: E1-B HS
1097 if (_E1_bHS == 1.0) {
1098 SVhealth |= (1<<1);
1099 }
1100 else if (_E1_bHS == 2.0) {
1101 SVhealth |= (1<<2);
1102 }
[6803]1103 else if (_E1_bHS == 3.0) {
[6792]1104 SVhealth |= (1<<1);
1105 SVhealth |= (1<<2);
1106 }
[6802]1107 // Bit 3 : E5a DVS
[6812]1108 if (_e5aDataInValid) {
[6802]1109 SVhealth |= (1<<3);
1110 }
1111 // Bit 4-5: E5a HS
1112 if (_E5aHS == 1.0) {
1113 SVhealth |= (1<<4);
1114 }
1115 else if (_E5aHS == 2.0) {
1116 SVhealth |= (1<<5);
1117 }
[6803]1118 else if (_E5aHS == 3.0) {
[6802]1119 SVhealth |= (1<<4);
1120 SVhealth |= (1<<5);
1121 }
[6792]1122 // Bit 6 : E5b DVS
[6812]1123 if (_e5bDataInValid) {
[6792]1124 SVhealth |= (1<<6);
1125 }
1126 // Bit 7-8: E5b HS
1127 if (_E5bHS == 1.0) {
1128 SVhealth |= (1<<7);
1129 }
1130 else if (_E5bHS == 2.0) {
1131 SVhealth |= (1<<8);
1132 }
[6803]1133 else if (_E5bHS == 3.0) {
[6792]1134 SVhealth |= (1<<7);
1135 SVhealth |= (1<<8);
1136 }
[5539]1137 }
[6792]1138
[4023]1139 out << QString(fmt)
[5532]1140 .arg(_IDOT, 19, 'e', 12)
1141 .arg(double(dataSource), 19, 'e', 12)
[6892]1142 .arg(_TOEweek + 1024.0, 19, 'e', 12)
[5532]1143 .arg(0.0, 19, 'e', 12);
[4023]1144
1145 out << QString(fmt)
[6798]1146 .arg(_SISA, 19, 'e', 12)
[6792]1147 .arg(double(SVhealth), 19, 'e', 12)
1148 .arg(BGD_1_5A, 19, 'e', 12)
1149 .arg(BGD_1_5B, 19, 'e', 12);
[4023]1150
[7923]1151 double tot = _TOT;
1152 if (tot == 0.9999e9 && version < 3.0) {
1153 tot = 0.0;
1154 }
[4023]1155 out << QString(fmt)
[7923]1156 .arg(tot, 19, 'e', 12)
[4024]1157 .arg("", 19, QChar(' '))
1158 .arg("", 19, QChar(' '))
1159 .arg("", 19, QChar(' '));
[4023]1160
1161 return rnxStr;
1162}
1163
[6385]1164// Constructor
1165//////////////////////////////////////////////////////////////////////////////
[6390]1166t_ephSBAS::t_ephSBAS(float rnxVersion, const QStringList& lines) {
1167
1168 const int nLines = 4;
1169
1170 if (lines.size() != nLines) {
[6518]1171 _checkState = bad;
[6390]1172 return;
1173 }
1174
1175 // RINEX Format
1176 // ------------
1177 int fieldLen = 19;
1178
1179 int pos[4];
1180 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1181 pos[1] = pos[0] + fieldLen;
1182 pos[2] = pos[1] + fieldLen;
1183 pos[3] = pos[2] + fieldLen;
1184
1185 // Read four lines
1186 // ---------------
1187 for (int iLine = 0; iLine < nLines; iLine++) {
1188 QString line = lines[iLine];
1189
1190 if ( iLine == 0 ) {
1191 QTextStream in(line.left(pos[1]).toAscii());
1192
1193 int year, month, day, hour, min;
1194 double sec;
[6880]1195
[7139]1196 QString prnStr, n;
[6880]1197 in >> prnStr;
[7639]1198 if (prnStr.size() == 1 && prnStr[0] == 'S') {
[7139]1199 in >> n;
1200 prnStr.append(n);
[6880]1201 }
1202 in >> year >> month >> day >> hour >> min >> sec;
[6390]1203 if (prnStr.at(0) == 'S') {
1204 _prn.set('S', prnStr.mid(1).toInt());
1205 }
1206 else {
1207 _prn.set('S', prnStr.toInt());
1208 }
1209
1210 if (year < 80) {
1211 year += 2000;
1212 }
1213 else if (year < 100) {
1214 year += 1900;
1215 }
1216
1217 _TOC.set(year, month, day, hour, min, sec);
1218
1219 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1220 readDbl(line, pos[2], fieldLen, _agf1 ) ||
[8455]1221 readDbl(line, pos[3], fieldLen, _TOT ) ) {
[6518]1222 _checkState = bad;
[6390]1223 return;
1224 }
1225 }
1226
1227 else if ( iLine == 1 ) {
1228 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1229 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1230 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1231 readDbl(line, pos[3], fieldLen, _health ) ) {
[6518]1232 _checkState = bad;
[6390]1233 return;
1234 }
1235 }
1236
1237 else if ( iLine == 2 ) {
1238 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1239 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1240 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1241 readDbl(line, pos[3], fieldLen, _ura ) ) {
[6518]1242 _checkState = bad;
[6390]1243 return;
1244 }
1245 }
1246
1247 else if ( iLine == 3 ) {
[6536]1248 double iodn;
[6390]1249 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1250 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1251 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
[6536]1252 readDbl(line, pos[3], fieldLen, iodn ) ) {
[6518]1253 _checkState = bad;
[6390]1254 return;
[6891]1255 } else {
[6536]1256 _IODN = int(iodn);
[6390]1257 }
1258 }
1259 }
1260
[7278]1261 _x_pos *= 1.e3;
1262 _y_pos *= 1.e3;
1263 _z_pos *= 1.e3;
1264 _x_velocity *= 1.e3;
1265 _y_velocity *= 1.e3;
1266 _z_velocity *= 1.e3;
1267 _x_acceleration *= 1.e3;
1268 _y_acceleration *= 1.e3;
1269 _z_acceleration *= 1.e3;
[6385]1270}
1271
[7054]1272// IOD of SBAS Ephemeris (virtual)
1273////////////////////////////////////////////////////////////////////////////
1274
[7169]1275unsigned int t_ephSBAS::IOD() const {
[7054]1276 unsigned char buffer[80];
1277 int size = 0;
1278 int numbits = 0;
1279 long long bitbuffer = 0;
1280 unsigned char *startbuffer = buffer;
1281
1282 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1283 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1284 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1285 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1286 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1287 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1288 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1289 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1290 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1291 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1292 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1293 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1294
1295 return CRC24(size, startbuffer);
1296}
1297
[6385]1298// Compute SBAS Satellite Position (virtual)
1299////////////////////////////////////////////////////////////////////////////
1300t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[6386]1301
1302 bncTime tt(GPSweek, GPSweeks);
1303 double dt = tt - _TOC;
1304
[7278]1305 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1306 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1307 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
[6386]1308
1309 vv[0] = _x_velocity + _x_acceleration * dt;
1310 vv[1] = _y_velocity + _y_acceleration * dt;
1311 vv[2] = _z_velocity + _z_acceleration * dt;
1312
1313 xc[3] = _agf0 + _agf1 * dt;
1314
[8541]1315 xc[4] = _agf1;
1316 xc[5] = 0.0;
[8484]1317
[6386]1318 return success;
[6385]1319}
1320
1321// RINEX Format String
1322//////////////////////////////////////////////////////////////////////////////
[6388]1323QString t_ephSBAS::toString(double version) const {
1324
1325 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1326
1327 QTextStream out(&rnxStr);
1328
1329 out << QString("%1%2%3\n")
[6390]1330 .arg(_agf0, 19, 'e', 12)
1331 .arg(_agf1, 19, 'e', 12)
[8455]1332 .arg(_TOT, 19, 'e', 12);
[6388]1333
1334 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1335
1336 out << QString(fmt)
1337 .arg(1.e-3*_x_pos, 19, 'e', 12)
1338 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1339 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
[6390]1340 .arg(_health, 19, 'e', 12);
[6388]1341
1342 out << QString(fmt)
1343 .arg(1.e-3*_y_pos, 19, 'e', 12)
1344 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1345 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
[6390]1346 .arg(_ura, 19, 'e', 12);
[6388]1347
1348 out << QString(fmt)
1349 .arg(1.e-3*_z_pos, 19, 'e', 12)
1350 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1351 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
[6536]1352 .arg(double(_IODN), 19, 'e', 12);
[6388]1353
1354 return rnxStr;
[6385]1355}
[6400]1356
1357// Constructor
1358//////////////////////////////////////////////////////////////////////////////
[6600]1359t_ephBDS::t_ephBDS(float rnxVersion, const QStringList& lines) {
[6400]1360
1361 const int nLines = 8;
1362
1363 if (lines.size() != nLines) {
[6518]1364 _checkState = bad;
[6400]1365 return;
1366 }
1367
1368 // RINEX Format
1369 // ------------
1370 int fieldLen = 19;
1371
1372 int pos[4];
1373 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1374 pos[1] = pos[0] + fieldLen;
1375 pos[2] = pos[1] + fieldLen;
1376 pos[3] = pos[2] + fieldLen;
1377
1378 // Read eight lines
1379 // ----------------
1380 for (int iLine = 0; iLine < nLines; iLine++) {
1381 QString line = lines[iLine];
1382
1383 if ( iLine == 0 ) {
1384 QTextStream in(line.left(pos[1]).toAscii());
1385
1386 int year, month, day, hour, min;
1387 double sec;
[6880]1388
[7139]1389 QString prnStr, n;
[6880]1390 in >> prnStr;
[7639]1391 if (prnStr.size() == 1 && prnStr[0] == 'C') {
[7139]1392 in >> n;
1393 prnStr.append(n);
[6880]1394 }
1395 in >> year >> month >> day >> hour >> min >> sec;
[6400]1396 if (prnStr.at(0) == 'C') {
1397 _prn.set('C', prnStr.mid(1).toInt());
1398 }
1399 else {
1400 _prn.set('C', prnStr.toInt());
1401 }
1402
1403 if (year < 80) {
1404 year += 2000;
1405 }
1406 else if (year < 100) {
1407 year += 1900;
1408 }
1409
[6812]1410 _TOC.setBDS(year, month, day, hour, min, sec);
[6400]1411
1412 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1413 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1414 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
[6518]1415 _checkState = bad;
[6400]1416 return;
1417 }
1418 }
1419
1420 else if ( iLine == 1 ) {
1421 double aode;
1422 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1423 readDbl(line, pos[1], fieldLen, _Crs ) ||
1424 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1425 readDbl(line, pos[3], fieldLen, _M0 ) ) {
[6518]1426 _checkState = bad;
[6400]1427 return;
1428 }
1429 _AODE = int(aode);
1430 }
1431
1432 else if ( iLine == 2 ) {
1433 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1434 readDbl(line, pos[1], fieldLen, _e ) ||
1435 readDbl(line, pos[2], fieldLen, _Cus ) ||
1436 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
[6518]1437 _checkState = bad;
[6400]1438 return;
1439 }
1440 }
1441
1442 else if ( iLine == 3 ) {
[6812]1443 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
[6400]1444 readDbl(line, pos[1], fieldLen, _Cic ) ||
1445 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1446 readDbl(line, pos[3], fieldLen, _Cis ) ) {
[6518]1447 _checkState = bad;
[6400]1448 return;
1449 }
1450 }
1451
1452 else if ( iLine == 4 ) {
1453 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1454 readDbl(line, pos[1], fieldLen, _Crc ) ||
1455 readDbl(line, pos[2], fieldLen, _omega ) ||
1456 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
[6518]1457 _checkState = bad;
[6400]1458 return;
1459 }
1460 }
1461
1462 else if ( iLine == 5 ) {
1463 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
[6812]1464 readDbl(line, pos[2], fieldLen, _TOEweek)) {
[6518]1465 _checkState = bad;
[6400]1466 return;
1467 }
1468 }
1469
1470 else if ( iLine == 6 ) {
1471 double SatH1;
[6755]1472 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
1473 readDbl(line, pos[1], fieldLen, SatH1) ||
[6400]1474 readDbl(line, pos[2], fieldLen, _TGD1) ||
1475 readDbl(line, pos[3], fieldLen, _TGD2) ) {
[6518]1476 _checkState = bad;
[6400]1477 return;
1478 }
1479 _SatH1 = int(SatH1);
1480 }
1481
1482 else if ( iLine == 7 ) {
1483 double aodc;
[6812]1484 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
[6400]1485 readDbl(line, pos[1], fieldLen, aodc) ) {
[6518]1486 _checkState = bad;
[6400]1487 return;
1488 }
[6812]1489 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
1490 _TOT = _TOEsec;
[6400]1491 }
1492 _AODC = int(aodc);
1493 }
1494 }
1495
[7138]1496 _TOE.setBDS(int(_TOEweek), _TOEsec);
1497
[6400]1498 // remark: actually should be computed from second_tot
1499 // but it seems to be unreliable in RINEX files
[6843]1500 //_TOT = _TOC.bdssec();
[6400]1501}
1502
[7054]1503// IOD of BDS Ephemeris (virtual)
1504////////////////////////////////////////////////////////////////////////////
[7169]1505unsigned int t_ephBDS::IOD() const {
[8942]1506 return (int(_TOEsec)/720) % 240;
[7054]1507}
1508
[6601]1509// Compute BDS Satellite Position (virtual)
[6400]1510//////////////////////////////////////////////////////////////////////////////
[6600]1511t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[6400]1512
[6602]1513 static const double gmBDS = 398.6004418e12;
1514 static const double omegaBDS = 7292115.0000e-11;
[6400]1515
1516 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
1517 vv[0] = vv[1] = vv[2] = 0.0;
1518
1519 bncTime tt(GPSweek, GPSweeks);
1520
1521 if (_sqrt_A == 0) {
1522 return failure;
1523 }
1524 double a0 = _sqrt_A * _sqrt_A;
1525
[6602]1526 double n0 = sqrt(gmBDS/(a0*a0*a0));
[6400]1527 double tk = tt - _TOE;
1528 double n = n0 + _Delta_n;
1529 double M = _M0 + n*tk;
1530 double E = M;
1531 double E_last;
1532 int nLoop = 0;
1533 do {
1534 E_last = E;
1535 E = M + _e*sin(E);
1536
1537 if (++nLoop == 100) {
1538 return failure;
1539 }
1540 } while ( fabs(E-E_last)*a0 > 0.001 );
1541
1542 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
1543 double u0 = v + _omega;
1544 double sin2u0 = sin(2*u0);
1545 double cos2u0 = cos(2*u0);
1546 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1547 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1548 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1549 double xp = r*cos(u);
1550 double yp = r*sin(u);
1551 double toesec = (_TOE.gpssec() - 14.0);
1552 double sinom = 0;
1553 double cosom = 0;
1554 double sini = 0;
1555 double cosi = 0;
[7278]1556
[7481]1557 // Velocity
1558 // --------
1559 double tanv2 = tan(v/2);
1560 double dEdM = 1 / (1 - _e*cos(E));
1561 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
1562 / (1 + tanv2*tanv2) * dEdM * n;
1563 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1564 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1565 double dotr = a0 * _e*sin(E) * dEdM * n
1566 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1567
1568 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1569 double doty = dotr*sin(u) + r*cos(u)*dotu;
1570
[6400]1571 const double iMaxGEO = 10.0 / 180.0 * M_PI;
1572
1573 // MEO/IGSO satellite
1574 // ------------------
1575 if (_i0 > iMaxGEO) {
[6602]1576 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
[6400]1577
1578 sinom = sin(OM);
1579 cosom = cos(OM);
1580 sini = sin(i);
1581 cosi = cos(i);
1582
1583 xc[0] = xp*cosom - yp*cosi*sinom;
1584 xc[1] = xp*sinom + yp*cosi*cosom;
[7278]1585 xc[2] = yp*sini;
[7481]1586
1587 // Velocity
1588 // --------
1589
1590 double dotom = _OMEGADOT - t_CST::omega;
1591
1592 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1593 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1594 + yp*sini*sinom*doti; // dX / di
1595
1596 vv[1] = sinom *dotx + cosi*cosom *doty
1597 + xp*cosom*dotom - yp*cosi*sinom*dotom
1598 - yp*sini*cosom*doti;
1599
1600 vv[2] = sini *doty + yp*cosi *doti;
1601
[6400]1602 }
1603
1604 // GEO satellite
1605 // -------------
1606 else {
[6602]1607 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
1608 double ll = omegaBDS*tk;
[6400]1609
1610 sinom = sin(OM);
1611 cosom = cos(OM);
1612 sini = sin(i);
1613 cosi = cos(i);
1614
1615 double xx = xp*cosom - yp*cosi*sinom;
1616 double yy = xp*sinom + yp*cosi*cosom;
[7278]1617 double zz = yp*sini;
[6400]1618
[7487]1619 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
1620 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
[6400]1621
1622 ColumnVector X1(3); X1 << xx << yy << zz;
[7487]1623 ColumnVector X2 = RZ*RX*X1;
[6400]1624
1625 xc[0] = X2(1);
1626 xc[1] = X2(2);
1627 xc[2] = X2(3);
[7278]1628
[7481]1629 double dotom = _OMEGADOT;
[6400]1630
[7481]1631 double vx = cosom *dotx - cosi*sinom *doty
1632 - xp*sinom*dotom - yp*cosi*cosom*dotom
1633 + yp*sini*sinom*doti;
[6400]1634
[7481]1635 double vy = sinom *dotx + cosi*cosom *doty
1636 + xp*cosom*dotom - yp*cosi*sinom*dotom
1637 - yp*sini*cosom*doti;
[7278]1638
[7501]1639 double vz = sini *doty + yp*cosi *doti;
[6400]1640
[7501]1641 ColumnVector V(3); V << vx << vy << vz;
[7481]1642
[7487]1643 Matrix RdotZ(3,3);
[7481]1644 double C = cos(ll);
1645 double S = sin(ll);
1646 Matrix UU(3,3);
1647 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
1648 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
1649 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
[7487]1650 RdotZ = omegaBDS * UU;
[7481]1651
1652 ColumnVector VV(3);
[7487]1653 VV = RZ*RX*V + RdotZ*RX*X1;
[7481]1654
1655 vv[0] = VV(1);
1656 vv[1] = VV(2);
1657 vv[2] = VV(3);
1658 }
1659
1660 double tc = tt - _TOC;
1661 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1662
[7278]1663 // dotC = _clock_drift + _clock_driftrate*tc
[6400]1664 // - 4.442807633e-10*_e*sqrt(a0)*cos(E) * dEdM * n;
1665
[7481]1666 // Relativistic Correction
1667 // -----------------------
1668 // correspondent to BDS ICD and to SSR standard
[8541]1669 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
[7481]1670 // correspondent to IGS convention
1671 // xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
1672
[8541]1673 xc[4] = _clock_drift + _clock_driftrate*tc;
1674 xc[5] = _clock_driftrate;
1675
[6400]1676 return success;
1677}
1678
1679// RINEX Format String
1680//////////////////////////////////////////////////////////////////////////////
[6600]1681QString t_ephBDS::toString(double version) const {
[6400]1682
[6812]1683 QString rnxStr = rinexDateStr(_TOC-14.0, _prn, version);
[6400]1684
1685 QTextStream out(&rnxStr);
1686
1687 out << QString("%1%2%3\n")
1688 .arg(_clock_bias, 19, 'e', 12)
1689 .arg(_clock_drift, 19, 'e', 12)
1690 .arg(_clock_driftrate, 19, 'e', 12);
1691
1692 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1693
1694 out << QString(fmt)
1695 .arg(double(_AODE), 19, 'e', 12)
1696 .arg(_Crs, 19, 'e', 12)
1697 .arg(_Delta_n, 19, 'e', 12)
1698 .arg(_M0, 19, 'e', 12);
1699
1700 out << QString(fmt)
1701 .arg(_Cuc, 19, 'e', 12)
1702 .arg(_e, 19, 'e', 12)
1703 .arg(_Cus, 19, 'e', 12)
1704 .arg(_sqrt_A, 19, 'e', 12);
1705
[6843]1706 double toes = 0.0;
1707 if (_TOEweek > -1.0) {// RINEX input
1708 toes = _TOEsec;
1709 }
1710 else {// RTCM stream input
[6812]1711 toes = _TOE.bdssec();
[6755]1712 }
[6400]1713 out << QString(fmt)
[6843]1714 .arg(toes, 19, 'e', 12)
[6755]1715 .arg(_Cic, 19, 'e', 12)
1716 .arg(_OMEGA0, 19, 'e', 12)
1717 .arg(_Cis, 19, 'e', 12);
[6400]1718
1719 out << QString(fmt)
1720 .arg(_i0, 19, 'e', 12)
1721 .arg(_Crc, 19, 'e', 12)
1722 .arg(_omega, 19, 'e', 12)
1723 .arg(_OMEGADOT, 19, 'e', 12);
1724
[6843]1725 double toew = 0.0;
1726 if (_TOEweek > -1.0) {// RINEX input
1727 toew = _TOEweek;
1728 }
1729 else {// RTCM stream input
1730 toew = double(_TOE.bdsw());
1731 }
[6400]1732 out << QString(fmt)
[6843]1733 .arg(_IDOT, 19, 'e', 12)
1734 .arg(0.0, 19, 'e', 12)
1735 .arg(toew, 19, 'e', 12)
1736 .arg(0.0, 19, 'e', 12);
[6400]1737
1738 out << QString(fmt)
[6798]1739 .arg(_URA, 19, 'e', 12)
[6400]1740 .arg(double(_SatH1), 19, 'e', 12)
1741 .arg(_TGD1, 19, 'e', 12)
1742 .arg(_TGD2, 19, 'e', 12);
1743
[6843]1744 double tots = 0.0;
1745 if (_TOEweek > -1.0) {// RINEX input
1746 tots = _TOT;
1747 }
1748 else {// RTCM stream input
[6812]1749 tots = _TOE.bdssec();
[6755]1750 }
[6400]1751 out << QString(fmt)
[6792]1752 .arg(tots, 19, 'e', 12)
[6755]1753 .arg(double(_AODC), 19, 'e', 12)
1754 .arg("", 19, QChar(' '))
1755 .arg("", 19, QChar(' '));
[6400]1756 return rnxStr;
1757}
Note: See TracBrowser for help on using the repository browser.