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

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