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

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

minor changes to exclude unhealthy satellites from satellite coordinates determination

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