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

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

bug fixed: RINEX 3.04 QZSS fit interval is specified as flag

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