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

Last change on this file since 8488 was 8488, checked in by stuerze, 6 years ago

minor changes

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