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

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

small bug fixes in 'reqc' ephemeris check

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