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

Last change on this file since 9127 was 9127, checked in by stuerze, 20 months ago

minor changes regarding ssr, long mountpoint names and latency

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