source: ntrip/trunk/BNC/src/ephemeris.cpp@ 8798

Last change on this file since 8798 was 8790, checked in by stuerze, 5 years ago

some updates regarding IRNSS RTCM data decoding

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