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

Last change on this file since 8456 was 8456, checked in by stuerze, 3 years ago

bug fixed regarding TOT in BDS and SBAS RTCM3 ephemeris message

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
633 for (int ii = 1; ii <= nSteps; ii++) {
634 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
635 _tt = _tt + step;
636 }
637
638 // Position and Velocity
639 // ---------------------
640 xc[0] = _xv(1);
641 xc[1] = _xv(2);
642 xc[2] = _xv(3);
643
644 vv[0] = _xv(4);
645 vv[1] = _xv(5);
646 vv[2] = _xv(6);
647
648 // Clock Correction
649 // ----------------
650 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
651 xc[3] = -_tau + _gamma * dtClk;
652
653 return success;
654}
655
656// RINEX Format String
657//////////////////////////////////////////////////////////////////////////////
658QString t_ephGlo::toString(double version) const {
659
660 QString rnxStr = rinexDateStr(_TOC-_gps_utc, _prn, version);
661
662 QTextStream out(&rnxStr);
663
664 out << QString("%1%2%3\n")
665 .arg(-_tau, 19, 'e', 12)
666 .arg(_gamma, 19, 'e', 12)
667 .arg(_tki, 19, 'e', 12);
668
669 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
670
671 out << QString(fmt)
672 .arg(_x_pos, 19, 'e', 12)
673 .arg(_x_velocity, 19, 'e', 12)
674 .arg(_x_acceleration, 19, 'e', 12)
675 .arg(_health, 19, 'e', 12);
676
677 out << QString(fmt)
678 .arg(_y_pos, 19, 'e', 12)
679 .arg(_y_velocity, 19, 'e', 12)
680 .arg(_y_acceleration, 19, 'e', 12)
681 .arg(_frequency_number, 19, 'e', 12);
682
683 out << QString(fmt)
684 .arg(_z_pos, 19, 'e', 12)
685 .arg(_z_velocity, 19, 'e', 12)
686 .arg(_z_acceleration, 19, 'e', 12)
687 .arg(_E, 19, 'e', 12);
688
689 return rnxStr;
690}
691
692// Derivative of the state vector using a simple force model (static)
693////////////////////////////////////////////////////////////////////////////
694ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
695 double* acc) {
696
697 // State vector components
698 // -----------------------
699 ColumnVector rr = xv.rows(1,3);
700 ColumnVector vv = xv.rows(4,6);
701
702 // Acceleration
703 // ------------
704 static const double gmWGS = 398.60044e12;
705 static const double AE = 6378136.0;
706 static const double OMEGA = 7292115.e-11;
707 static const double C20 = -1082.6257e-6;
708
709 double rho = rr.norm_Frobenius();
710 double t1 = -gmWGS/(rho*rho*rho);
711 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
712 double t3 = OMEGA * OMEGA;
713 double t4 = 2.0 * OMEGA;
714 double z2 = rr(3) * rr(3);
715
716 // Vector of derivatives
717 // ---------------------
718 ColumnVector va(6);
719 va(1) = vv(1);
720 va(2) = vv(2);
721 va(3) = vv(3);
722 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
723 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
724 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
725
726 return va;
727}
728
729// IOD of Glonass Ephemeris (virtual)
730////////////////////////////////////////////////////////////////////////////
731unsigned int t_ephGlo::IOD() const {
732 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
733 return (unsigned long)tMoscow.daysec() / 900;
734}
735
736// Health status of Glonass Ephemeris (virtual)
737////////////////////////////////////////////////////////////////////////////
738unsigned int t_ephGlo::isUnhealthy() const {
739
740 if (_almanac_health_availablility_indicator) {
741 if ((_health == 0 && _almanac_health == 0) ||
742 (_health == 1 && _almanac_health == 0) ||
743 (_health == 1 && _almanac_health == 1)) {
744 return 1;
745 }
746 }
747 else if (!_almanac_health_availablility_indicator) {
748 if (_health) {
749 return 1;
750 }
751 }
752 return 0; /* (_health == 0 && _almanac_health == 1) or (_health == 0) */
753}
754
755
756// Constructor
757//////////////////////////////////////////////////////////////////////////////
758t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
759 int year, month, day, hour, min;
760 double sec;
761 QString prnStr;
762 const int nLines = 8;
763 if (lines.size() != nLines) {
764 _checkState = bad;
765 return;
766 }
767
768 // RINEX Format
769 // ------------
770 int fieldLen = 19;
771 double SVhealth = 0.0;
772 double datasource = 0.0;
773
774 int pos[4];
775 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
776 pos[1] = pos[0] + fieldLen;
777 pos[2] = pos[1] + fieldLen;
778 pos[3] = pos[2] + fieldLen;
779
780 // Read eight lines
781 // ----------------
782 for (int iLine = 0; iLine < nLines; iLine++) {
783 QString line = lines[iLine];
784
785 if ( iLine == 0 ) {
786 QTextStream in(line.left(pos[1]).toLatin1());
787 QString n;
788 in >> prnStr;
789 if (prnStr.size() == 1 && prnStr[0] == 'E') {
790 in >> n;
791 prnStr.append(n);
792 }
793 in >> year >> month >> day >> hour >> min >> sec;
794 if (year < 80) {
795 year += 2000;
796 }
797 else if (year < 100) {
798 year += 1900;
799 }
800
801 _TOC.set(year, month, day, hour, min, sec);
802
803 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
804 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
805 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
806 _checkState = bad;
807 return;
808 }
809 }
810
811 else if ( iLine == 1 ) {
812 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
813 readDbl(line, pos[1], fieldLen, _Crs ) ||
814 readDbl(line, pos[2], fieldLen, _Delta_n) ||
815 readDbl(line, pos[3], fieldLen, _M0 ) ) {
816 _checkState = bad;
817 return;
818 }
819 }
820
821 else if ( iLine == 2 ) {
822 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
823 readDbl(line, pos[1], fieldLen, _e ) ||
824 readDbl(line, pos[2], fieldLen, _Cus ) ||
825 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
826 _checkState = bad;
827 return;
828 }
829 }
830
831 else if ( iLine == 3 ) {
832 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
833 readDbl(line, pos[1], fieldLen, _Cic ) ||
834 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
835 readDbl(line, pos[3], fieldLen, _Cis ) ) {
836 _checkState = bad;
837 return;
838 }
839 }
840
841 else if ( iLine == 4 ) {
842 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
843 readDbl(line, pos[1], fieldLen, _Crc ) ||
844 readDbl(line, pos[2], fieldLen, _omega ) ||
845 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
846 _checkState = bad;
847 return;
848 }
849 }
850
851 else if ( iLine == 5 ) {
852 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
853 readDbl(line, pos[1], fieldLen, datasource) ||
854 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
855 _checkState = bad;
856 return;
857 } else {
858 if (int(datasource) & (1<<8)) {
859 _fnav = true;
860 _inav = false;
861 } else if (int(datasource) & (1<<9)) {
862 _fnav = false;
863 _inav = true;
864 }
865 _TOEweek -= 1024.0;
866 }
867 }
868
869 else if ( iLine == 6 ) {
870 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
871 readDbl(line, pos[1], fieldLen, SVhealth) ||
872 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
873 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
874 _checkState = bad;
875 return;
876 } else {
877 // Bit 0
878 _e1DataInValid = (int(SVhealth) & (1<<0));
879 // Bit 1-2
880 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
881 // Bit 3
882 _e5aDataInValid = (int(SVhealth) & (1<<3));
883 // Bit 4-5
884 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
885 // Bit 6
886 _e5bDataInValid = (int(SVhealth) & (1<<6));
887 // Bit 7-8
888 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
889
890 if (prnStr.at(0) == 'E') {
891 _prn.set('E', prnStr.mid(1).toInt(), _inav ? 1 : 0);
892 }
893 }
894 }
895
896 else if ( iLine == 7 ) {
897 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
898 _checkState = bad;
899 return;
900 }
901 }
902 }
903}
904
905// Compute Galileo Satellite Position (virtual)
906////////////////////////////////////////////////////////////////////////////
907t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
908
909 if (_checkState == bad ||
910 _checkState == unhealthy) {
911 return failure;
912 }
913
914 static const double omegaEarth = 7292115.1467e-11;
915 static const double gmWGS = 398.6004418e12;
916
917 memset(xc, 0, 4*sizeof(double));
918 memset(vv, 0, 3*sizeof(double));
919
920 double a0 = _sqrt_A * _sqrt_A;
921 if (a0 == 0) {
922 return failure;
923 }
924
925 double n0 = sqrt(gmWGS/(a0*a0*a0));
926
927 bncTime tt(GPSweek, GPSweeks);
928 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
929
930 double n = n0 + _Delta_n;
931 double M = _M0 + n*tk;
932 double E = M;
933 double E_last;
934 int nLoop = 0;
935 do {
936 E_last = E;
937 E = M + _e*sin(E);
938
939 if (++nLoop == 100) {
940 return failure;
941 }
942 } while ( fabs(E-E_last)*a0 > 0.001 );
943 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
944 double u0 = v + _omega;
945 double sin2u0 = sin(2*u0);
946 double cos2u0 = cos(2*u0);
947 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
948 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
949 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
950 double xp = r*cos(u);
951 double yp = r*sin(u);
952 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
953 omegaEarth*_TOEsec;
954
955 double sinom = sin(OM);
956 double cosom = cos(OM);
957 double sini = sin(i);
958 double cosi = cos(i);
959 xc[0] = xp*cosom - yp*cosi*sinom;
960 xc[1] = xp*sinom + yp*cosi*cosom;
961 xc[2] = yp*sini;
962
963 double tc = tt - _TOC;
964 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
965
966 // Velocity
967 // --------
968 double tanv2 = tan(v/2);
969 double dEdM = 1 / (1 - _e*cos(E));
970 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
971 * dEdM * n;
972 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
973 double dotom = _OMEGADOT - omegaEarth;
974 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
975 double dotr = a0 * _e*sin(E) * dEdM * n
976 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
977 double dotx = dotr*cos(u) - r*sin(u)*dotu;
978 double doty = dotr*sin(u) + r*cos(u)*dotu;
979
980 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
981 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
982 + yp*sini*sinom*doti; // dX / di
983
984 vv[1] = sinom *dotx + cosi*cosom *doty
985 + xp*cosom*dotom - yp*cosi*sinom*dotom
986 - yp*sini*cosom*doti;
987
988 vv[2] = sini *doty + yp*cosi *doti;
989
990 // Relativistic Correction
991 // -----------------------
992 // correspondent to Galileo ICD and to SSR standard
993 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
994 // correspondent to IGS convention
995 //xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
996
997 return success;
998}
999
1000// Health status of Galileo Ephemeris (virtual)
1001////////////////////////////////////////////////////////////////////////////
1002unsigned int t_ephGal::isUnhealthy() const {
1003 if (_E5aHS && _E5bHS && _E1_bHS) {
1004 return 1;
1005 }
1006 return 0;
1007}
1008
1009// RINEX Format String
1010//////////////////////////////////////////////////////////////////////////////
1011QString t_ephGal::toString(double version) const {
1012
1013 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1014
1015 QTextStream out(&rnxStr);
1016
1017 out << QString("%1%2%3\n")
1018 .arg(_clock_bias, 19, 'e', 12)
1019 .arg(_clock_drift, 19, 'e', 12)
1020 .arg(_clock_driftrate, 19, 'e', 12);
1021
1022 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1023
1024 out << QString(fmt)
1025 .arg(_IODnav, 19, 'e', 12)
1026 .arg(_Crs, 19, 'e', 12)
1027 .arg(_Delta_n, 19, 'e', 12)
1028 .arg(_M0, 19, 'e', 12);
1029
1030 out << QString(fmt)
1031 .arg(_Cuc, 19, 'e', 12)
1032 .arg(_e, 19, 'e', 12)
1033 .arg(_Cus, 19, 'e', 12)
1034 .arg(_sqrt_A, 19, 'e', 12);
1035
1036 out << QString(fmt)
1037 .arg(_TOEsec, 19, 'e', 12)
1038 .arg(_Cic, 19, 'e', 12)
1039 .arg(_OMEGA0, 19, 'e', 12)
1040 .arg(_Cis, 19, 'e', 12);
1041
1042 out << QString(fmt)
1043 .arg(_i0, 19, 'e', 12)
1044 .arg(_Crc, 19, 'e', 12)
1045 .arg(_omega, 19, 'e', 12)
1046 .arg(_OMEGADOT, 19, 'e', 12);
1047
1048 int dataSource = 0;
1049 int SVhealth = 0;
1050 double BGD_1_5A = _BGD_1_5A;
1051 double BGD_1_5B = _BGD_1_5B;
1052 if (_fnav) {
1053 dataSource |= (1<<1);
1054 dataSource |= (1<<8);
1055 BGD_1_5B = 0.0;
1056 // SVhealth
1057 // Bit 3 : E5a DVS
1058 if (_e5aDataInValid) {
1059 SVhealth |= (1<<3);
1060 }
1061 // Bit 4-5: E5a HS
1062 if (_E5aHS == 1.0) {
1063 SVhealth |= (1<<4);
1064 }
1065 else if (_E5aHS == 2.0) {
1066 SVhealth |= (1<<5);
1067 }
1068 else if (_E5aHS == 3.0) {
1069 SVhealth |= (1<<4);
1070 SVhealth |= (1<<5);
1071 }
1072 }
1073 else if(_inav) {
1074 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1075 // and RNXv3.03 says both can be set if the navigation messages were merged
1076 dataSource |= (1<<0);
1077 dataSource |= (1<<2);
1078 dataSource |= (1<<9);
1079 // SVhealth
1080 // Bit 0 : E1-B DVS
1081 if (_e1DataInValid) {
1082 SVhealth |= (1<<0);
1083 }
1084 // Bit 1-2: E1-B HS
1085 if (_E1_bHS == 1.0) {
1086 SVhealth |= (1<<1);
1087 }
1088 else if (_E1_bHS == 2.0) {
1089 SVhealth |= (1<<2);
1090 }
1091 else if (_E1_bHS == 3.0) {
1092 SVhealth |= (1<<1);
1093 SVhealth |= (1<<2);
1094 }
1095 // Bit 3 : E5a DVS
1096 if (_e5aDataInValid) {
1097 SVhealth |= (1<<3);
1098 }
1099 // Bit 4-5: E5a HS
1100 if (_E5aHS == 1.0) {
1101 SVhealth |= (1<<4);
1102 }
1103 else if (_E5aHS == 2.0) {
1104 SVhealth |= (1<<5);
1105 }
1106 else if (_E5aHS == 3.0) {
1107 SVhealth |= (1<<4);
1108 SVhealth |= (1<<5);
1109 }
1110 // Bit 6 : E5b DVS
1111 if (_e5bDataInValid) {
1112 SVhealth |= (1<<6);
1113 }
1114 // Bit 7-8: E5b HS
1115 if (_E5bHS == 1.0) {
1116 SVhealth |= (1<<7);
1117 }
1118 else if (_E5bHS == 2.0) {
1119 SVhealth |= (1<<8);
1120 }
1121 else if (_E5bHS == 3.0) {
1122 SVhealth |= (1<<7);
1123 SVhealth |= (1<<8);
1124 }
1125 }
1126
1127 out << QString(fmt)
1128 .arg(_IDOT, 19, 'e', 12)
1129 .arg(double(dataSource), 19, 'e', 12)
1130 .arg(_TOEweek + 1024.0, 19, 'e', 12)
1131 .arg(0.0, 19, 'e', 12);
1132
1133 out << QString(fmt)
1134 .arg(_SISA, 19, 'e', 12)
1135 .arg(double(SVhealth), 19, 'e', 12)
1136 .arg(BGD_1_5A, 19, 'e', 12)
1137 .arg(BGD_1_5B, 19, 'e', 12);
1138
1139
1140 double tot = _TOT;
1141 if (tot == 0.9999e9 && version < 3.0) {
1142 tot = 0.0;
1143 }
1144 out << QString(fmt)
1145 .arg(tot, 19, 'e', 12)
1146 .arg("", 19, QChar(' '))
1147 .arg("", 19, QChar(' '))
1148 .arg("", 19, QChar(' '));
1149
1150 return rnxStr;
1151}
1152
1153// Constructor
1154//////////////////////////////////////////////////////////////////////////////
1155t_ephSBAS::t_ephSBAS(float rnxVersion, const QStringList& lines) {
1156
1157 const int nLines = 4;
1158
1159 if (lines.size() != nLines) {
1160 _checkState = bad;
1161 return;
1162 }
1163
1164 // RINEX Format
1165 // ------------
1166 int fieldLen = 19;
1167
1168 int pos[4];
1169 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1170 pos[1] = pos[0] + fieldLen;
1171 pos[2] = pos[1] + fieldLen;
1172 pos[3] = pos[2] + fieldLen;
1173
1174 // Read four lines
1175 // ---------------
1176 for (int iLine = 0; iLine < nLines; iLine++) {
1177 QString line = lines[iLine];
1178
1179 if ( iLine == 0 ) {
1180 QTextStream in(line.left(pos[1]).toLatin1());
1181
1182 int year, month, day, hour, min;
1183 double sec;
1184
1185 QString prnStr, n;
1186 in >> prnStr;
1187 if (prnStr.size() == 1 && prnStr[0] == 'S') {
1188 in >> n;
1189 prnStr.append(n);
1190 }
1191 in >> year >> month >> day >> hour >> min >> sec;
1192 if (prnStr.at(0) == 'S') {
1193 _prn.set('S', prnStr.mid(1).toInt());
1194 }
1195 else {
1196 _prn.set('S', prnStr.toInt());
1197 }
1198
1199 if (year < 80) {
1200 year += 2000;
1201 }
1202 else if (year < 100) {
1203 year += 1900;
1204 }
1205
1206 _TOC.set(year, month, day, hour, min, sec);
1207
1208 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1209 readDbl(line, pos[2], fieldLen, _agf1 ) ||
1210 readDbl(line, pos[3], fieldLen, _TOT ) ) {
1211 _checkState = bad;
1212 return;
1213 }
1214 }
1215
1216 else if ( iLine == 1 ) {
1217 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1218 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1219 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1220 readDbl(line, pos[3], fieldLen, _health ) ) {
1221 _checkState = bad;
1222 return;
1223 }
1224 }
1225
1226 else if ( iLine == 2 ) {
1227 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1228 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1229 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1230 readDbl(line, pos[3], fieldLen, _ura ) ) {
1231 _checkState = bad;
1232 return;
1233 }
1234 }
1235
1236 else if ( iLine == 3 ) {
1237 double iodn;
1238 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1239 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1240 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
1241 readDbl(line, pos[3], fieldLen, iodn ) ) {
1242 _checkState = bad;
1243 return;
1244 } else {
1245 _IODN = int(iodn);
1246 }
1247 }
1248 }
1249
1250 _x_pos *= 1.e3;
1251 _y_pos *= 1.e3;
1252 _z_pos *= 1.e3;
1253 _x_velocity *= 1.e3;
1254 _y_velocity *= 1.e3;
1255 _z_velocity *= 1.e3;
1256 _x_acceleration *= 1.e3;
1257 _y_acceleration *= 1.e3;
1258 _z_acceleration *= 1.e3;
1259}
1260
1261// IOD of SBAS Ephemeris (virtual)
1262////////////////////////////////////////////////////////////////////////////
1263
1264unsigned int t_ephSBAS::IOD() const {
1265 unsigned char buffer[80];
1266 int size = 0;
1267 int numbits = 0;
1268 long long bitbuffer = 0;
1269 unsigned char *startbuffer = buffer;
1270
1271 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1272 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1273 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1274 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1275 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1276 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1277 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1278 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1279 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1280 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1281 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1282 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1283
1284 return CRC24(size, startbuffer);
1285}
1286
1287// Compute SBAS Satellite Position (virtual)
1288////////////////////////////////////////////////////////////////////////////
1289t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1290
1291 if (_checkState == bad ||
1292 _checkState == unhealthy) {
1293 return failure;
1294 }
1295
1296 bncTime tt(GPSweek, GPSweeks);
1297 double dt = tt - _TOC;
1298
1299 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1300 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1301 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
1302
1303 vv[0] = _x_velocity + _x_acceleration * dt;
1304 vv[1] = _y_velocity + _y_acceleration * dt;
1305 vv[2] = _z_velocity + _z_acceleration * dt;
1306
1307 xc[3] = _agf0 + _agf1 * dt;
1308
1309 return success;
1310}
1311
1312// RINEX Format String
1313//////////////////////////////////////////////////////////////////////////////
1314QString t_ephSBAS::toString(double version) const {
1315
1316 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1317
1318 QTextStream out(&rnxStr);
1319
1320 out << QString("%1%2%3\n")
1321 .arg(_agf0, 19, 'e', 12)
1322 .arg(_agf1, 19, 'e', 12)
1323 .arg(_TOT, 19, 'e', 12);
1324
1325 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1326
1327 out << QString(fmt)
1328 .arg(1.e-3*_x_pos, 19, 'e', 12)
1329 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1330 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
1331 .arg(_health, 19, 'e', 12);
1332
1333 out << QString(fmt)
1334 .arg(1.e-3*_y_pos, 19, 'e', 12)
1335 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1336 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
1337 .arg(_ura, 19, 'e', 12);
1338
1339 out << QString(fmt)
1340 .arg(1.e-3*_z_pos, 19, 'e', 12)
1341 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1342 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
1343 .arg(double(_IODN), 19, 'e', 12);
1344
1345 return rnxStr;
1346}
1347
1348// Constructor
1349//////////////////////////////////////////////////////////////////////////////
1350t_ephBDS::t_ephBDS(float rnxVersion, const QStringList& lines) {
1351
1352 const int nLines = 8;
1353
1354 if (lines.size() != nLines) {
1355 _checkState = bad;
1356 return;
1357 }
1358
1359 // RINEX Format
1360 // ------------
1361 int fieldLen = 19;
1362
1363 int pos[4];
1364 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1365 pos[1] = pos[0] + fieldLen;
1366 pos[2] = pos[1] + fieldLen;
1367 pos[3] = pos[2] + fieldLen;
1368
1369 // Read eight lines
1370 // ----------------
1371 for (int iLine = 0; iLine < nLines; iLine++) {
1372 QString line = lines[iLine];
1373
1374 if ( iLine == 0 ) {
1375 QTextStream in(line.left(pos[1]).toLatin1());
1376
1377 int year, month, day, hour, min;
1378 double sec;
1379
1380 QString prnStr, n;
1381 in >> prnStr;
1382 if (prnStr.size() == 1 && prnStr[0] == 'C') {
1383 in >> n;
1384 prnStr.append(n);
1385 }
1386 in >> year >> month >> day >> hour >> min >> sec;
1387 if (prnStr.at(0) == 'C') {
1388 _prn.set('C', prnStr.mid(1).toInt());
1389 }
1390 else {
1391 _prn.set('C', prnStr.toInt());
1392 }
1393
1394 if (year < 80) {
1395 year += 2000;
1396 }
1397 else if (year < 100) {
1398 year += 1900;
1399 }
1400
1401 _TOC.setBDS(year, month, day, hour, min, sec);
1402
1403 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1404 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1405 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1406 _checkState = bad;
1407 return;
1408 }
1409 }
1410
1411 else if ( iLine == 1 ) {
1412 double aode;
1413 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1414 readDbl(line, pos[1], fieldLen, _Crs ) ||
1415 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1416 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1417 _checkState = bad;
1418 return;
1419 }
1420 _AODE = int(aode);
1421 }
1422
1423 else if ( iLine == 2 ) {
1424 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1425 readDbl(line, pos[1], fieldLen, _e ) ||
1426 readDbl(line, pos[2], fieldLen, _Cus ) ||
1427 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1428 _checkState = bad;
1429 return;
1430 }
1431 }
1432
1433 else if ( iLine == 3 ) {
1434 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
1435 readDbl(line, pos[1], fieldLen, _Cic ) ||
1436 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1437 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1438 _checkState = bad;
1439 return;
1440 }
1441 }
1442
1443 else if ( iLine == 4 ) {
1444 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1445 readDbl(line, pos[1], fieldLen, _Crc ) ||
1446 readDbl(line, pos[2], fieldLen, _omega ) ||
1447 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1448 _checkState = bad;
1449 return;
1450 }
1451 }
1452
1453 else if ( iLine == 5 ) {
1454 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
1455 readDbl(line, pos[2], fieldLen, _TOEweek)) {
1456 _checkState = bad;
1457 return;
1458 }
1459 }
1460
1461 else if ( iLine == 6 ) {
1462 double SatH1;
1463 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
1464 readDbl(line, pos[1], fieldLen, SatH1) ||
1465 readDbl(line, pos[2], fieldLen, _TGD1) ||
1466 readDbl(line, pos[3], fieldLen, _TGD2) ) {
1467 _checkState = bad;
1468 return;
1469 }
1470 _SatH1 = int(SatH1);
1471 }
1472
1473 else if ( iLine == 7 ) {
1474 double aodc;
1475 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
1476 readDbl(line, pos[1], fieldLen, aodc) ) {
1477 _checkState = bad;
1478 return;
1479 }
1480 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
1481 _TOT = _TOEsec;
1482 }
1483 _AODC = int(aodc);
1484 }
1485 }
1486
1487 _TOE.setBDS(int(_TOEweek), _TOEsec);
1488
1489 // remark: actually should be computed from second_tot
1490 // but it seems to be unreliable in RINEX files
1491 //_TOT = _TOC.bdssec();
1492}
1493
1494// IOD of BDS Ephemeris (virtual)
1495////////////////////////////////////////////////////////////////////////////
1496unsigned int t_ephBDS::IOD() const {
1497 return (int(_TOEsec)/720) % 240;
1498}
1499
1500// Compute BDS Satellite Position (virtual)
1501//////////////////////////////////////////////////////////////////////////////
1502t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1503
1504 if (_checkState == bad ||
1505 _checkState == unhealthy) {
1506 return failure;
1507 }
1508
1509 static const double gmBDS = 398.6004418e12;
1510 static const double omegaBDS = 7292115.0000e-11;
1511
1512 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
1513 vv[0] = vv[1] = vv[2] = 0.0;
1514
1515 bncTime tt(GPSweek, GPSweeks);
1516
1517 if (_sqrt_A == 0) {
1518 return failure;
1519 }
1520 double a0 = _sqrt_A * _sqrt_A;
1521
1522 double n0 = sqrt(gmBDS/(a0*a0*a0));
1523 double tk = tt - _TOE;
1524 double n = n0 + _Delta_n;
1525 double M = _M0 + n*tk;
1526 double E = M;
1527 double E_last;
1528 int nLoop = 0;
1529 do {
1530 E_last = E;
1531 E = M + _e*sin(E);
1532
1533 if (++nLoop == 100) {
1534 return failure;
1535 }
1536 } while ( fabs(E-E_last)*a0 > 0.001 );
1537
1538 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
1539 double u0 = v + _omega;
1540 double sin2u0 = sin(2*u0);
1541 double cos2u0 = cos(2*u0);
1542 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1543 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1544 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1545 double xp = r*cos(u);
1546 double yp = r*sin(u);
1547 double toesec = (_TOE.gpssec() - 14.0);
1548 double sinom = 0;
1549 double cosom = 0;
1550 double sini = 0;
1551 double cosi = 0;
1552
1553 // Velocity
1554 // --------
1555 double tanv2 = tan(v/2);
1556 double dEdM = 1 / (1 - _e*cos(E));
1557 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
1558 / (1 + tanv2*tanv2) * dEdM * n;
1559 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1560 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1561 double dotr = a0 * _e*sin(E) * dEdM * n
1562 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1563
1564 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1565 double doty = dotr*sin(u) + r*cos(u)*dotu;
1566
1567 const double iMaxGEO = 10.0 / 180.0 * M_PI;
1568
1569 // MEO/IGSO satellite
1570 // ------------------
1571 if (_i0 > iMaxGEO) {
1572 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
1573
1574 sinom = sin(OM);
1575 cosom = cos(OM);
1576 sini = sin(i);
1577 cosi = cos(i);
1578
1579 xc[0] = xp*cosom - yp*cosi*sinom;
1580 xc[1] = xp*sinom + yp*cosi*cosom;
1581 xc[2] = yp*sini;
1582
1583 // Velocity
1584 // --------
1585
1586 double dotom = _OMEGADOT - t_CST::omega;
1587
1588 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1589 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1590 + yp*sini*sinom*doti; // dX / di
1591
1592 vv[1] = sinom *dotx + cosi*cosom *doty
1593 + xp*cosom*dotom - yp*cosi*sinom*dotom
1594 - yp*sini*cosom*doti;
1595
1596 vv[2] = sini *doty + yp*cosi *doti;
1597
1598 }
1599
1600 // GEO satellite
1601 // -------------
1602 else {
1603 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
1604 double ll = omegaBDS*tk;
1605
1606 sinom = sin(OM);
1607 cosom = cos(OM);
1608 sini = sin(i);
1609 cosi = cos(i);
1610
1611 double xx = xp*cosom - yp*cosi*sinom;
1612 double yy = xp*sinom + yp*cosi*cosom;
1613 double zz = yp*sini;
1614
1615 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
1616 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
1617
1618 ColumnVector X1(3); X1 << xx << yy << zz;
1619 ColumnVector X2 = RZ*RX*X1;
1620
1621 xc[0] = X2(1);
1622 xc[1] = X2(2);
1623 xc[2] = X2(3);
1624
1625 double dotom = _OMEGADOT;
1626
1627 double vx = cosom *dotx - cosi*sinom *doty
1628 - xp*sinom*dotom - yp*cosi*cosom*dotom
1629 + yp*sini*sinom*doti;
1630
1631 double vy = sinom *dotx + cosi*cosom *doty
1632 + xp*cosom*dotom - yp*cosi*sinom*dotom
1633 - yp*sini*cosom*doti;
1634
1635 double vz = sini *doty + yp*cosi *doti;
1636
1637 ColumnVector V(3); V << vx << vy << vz;
1638
1639 Matrix RdotZ(3,3);
1640 double C = cos(ll);
1641 double S = sin(ll);
1642 Matrix UU(3,3);
1643 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
1644 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
1645 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
1646 RdotZ = omegaBDS * UU;
1647
1648 ColumnVector VV(3);
1649 VV = RZ*RX*V + RdotZ*RX*X1;
1650
1651 vv[0] = VV(1);
1652 vv[1] = VV(2);
1653 vv[2] = VV(3);
1654 }
1655
1656 double tc = tt - _TOC;
1657 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1658
1659 // dotC = _clock_drift + _clock_driftrate*tc
1660 // - 4.442807633e-10*_e*sqrt(a0)*cos(E) * dEdM * n;
1661
1662 // Relativistic Correction
1663 // -----------------------
1664 // correspondent to BDS ICD and to SSR standard
1665 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1666 // correspondent to IGS convention
1667 // xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
1668
1669 return success;
1670}
1671
1672// RINEX Format String
1673//////////////////////////////////////////////////////////////////////////////
1674QString t_ephBDS::toString(double version) const {
1675
1676 QString rnxStr = rinexDateStr(_TOC-14.0, _prn, version);
1677
1678 QTextStream out(&rnxStr);
1679
1680 out << QString("%1%2%3\n")
1681 .arg(_clock_bias, 19, 'e', 12)
1682 .arg(_clock_drift, 19, 'e', 12)
1683 .arg(_clock_driftrate, 19, 'e', 12);
1684
1685 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1686
1687 out << QString(fmt)
1688 .arg(double(_AODE), 19, 'e', 12)
1689 .arg(_Crs, 19, 'e', 12)
1690 .arg(_Delta_n, 19, 'e', 12)
1691 .arg(_M0, 19, 'e', 12);
1692
1693 out << QString(fmt)
1694 .arg(_Cuc, 19, 'e', 12)
1695 .arg(_e, 19, 'e', 12)
1696 .arg(_Cus, 19, 'e', 12)
1697 .arg(_sqrt_A, 19, 'e', 12);
1698
1699 double toes = 0.0;
1700 if (_TOEweek > -1.0) {// RINEX input
1701 toes = _TOEsec;
1702 }
1703 else {// RTCM stream input
1704 toes = _TOE.bdssec();
1705 }
1706 out << QString(fmt)
1707 .arg(toes, 19, 'e', 12)
1708 .arg(_Cic, 19, 'e', 12)
1709 .arg(_OMEGA0, 19, 'e', 12)
1710 .arg(_Cis, 19, 'e', 12);
1711
1712 out << QString(fmt)
1713 .arg(_i0, 19, 'e', 12)
1714 .arg(_Crc, 19, 'e', 12)
1715 .arg(_omega, 19, 'e', 12)
1716 .arg(_OMEGADOT, 19, 'e', 12);
1717
1718 double toew = 0.0;
1719 if (_TOEweek > -1.0) {// RINEX input
1720 toew = _TOEweek;
1721 }
1722 else {// RTCM stream input
1723 toew = double(_TOE.bdsw());
1724 }
1725 out << QString(fmt)
1726 .arg(_IDOT, 19, 'e', 12)
1727 .arg(0.0, 19, 'e', 12)
1728 .arg(toew, 19, 'e', 12)
1729 .arg(0.0, 19, 'e', 12);
1730
1731 out << QString(fmt)
1732 .arg(_URA, 19, 'e', 12)
1733 .arg(double(_SatH1), 19, 'e', 12)
1734 .arg(_TGD1, 19, 'e', 12)
1735 .arg(_TGD2, 19, 'e', 12);
1736
1737 double tots = 0.0;
1738 if (_TOEweek > -1.0) {// RINEX input
1739 tots = _TOT;
1740 }
1741 else {// RTCM stream input
1742 tots = _TOE.bdssec();
1743 }
1744 out << QString(fmt)
1745 .arg(tots, 19, 'e', 12)
1746 .arg(double(_AODC), 19, 'e', 12)
1747 .arg("", 19, QChar(' '))
1748 .arg("", 19, QChar(' '));
1749 return rnxStr;
1750}
Note: See TracBrowser for help on using the repository browser.