source: ntrip/trunk/BNC/src/ephemeris.cpp@ 10315

Last change on this file since 10315 was 10315, checked in by stuerze, 3 months ago

health status of the Galileo satellites is now defined by the combination of HS, DVS and SISA

File size: 70.7 KB
Line 
1#include <sstream>
2#include <iostream>
3#include <iomanip>
4#include <cstring>
5
6#include <newmatio.h>
7
8#include "ephemeris.h"
9#include "bncutils.h"
10#include "bnctime.h"
11#include "bnccore.h"
12#include "bncutils.h"
13#include "satObs.h"
14#include "pppInclude.h"
15#include "pppModel.h"
16
17using namespace std;
18
19// Constructor
20////////////////////////////////////////////////////////////////////////////
21t_eph::t_eph() {
22 _checkState = unchecked;
23 _navType = undefined;
24 _orbCorr = 0;
25 _clkCorr = 0;
26}
27// Destructor
28////////////////////////////////////////////////////////////////////////////
29t_eph::~t_eph() {
30 if (_orbCorr)
31 delete _orbCorr;
32 if (_clkCorr)
33 delete _clkCorr;
34}
35
36//
37////////////////////////////////////////////////////////////////////////////
38void t_eph::setOrbCorr(const t_orbCorr* orbCorr) {
39 if (_orbCorr) {
40 delete _orbCorr;
41 _orbCorr = 0;
42 }
43 _orbCorr = new t_orbCorr(*orbCorr);
44}
45
46//
47////////////////////////////////////////////////////////////////////////////
48void t_eph::setClkCorr(const t_clkCorr* clkCorr) {
49 if (_clkCorr) {
50 delete _clkCorr;
51 _clkCorr = 0;
52 }
53 _clkCorr = new t_clkCorr(*clkCorr);
54}
55
56//
57////////////////////////////////////////////////////////////////////////////
58t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
59
60 if (_checkState == bad ||
61 _checkState == unhealthy ||
62 _checkState == outdated) {
63 return failure;
64 }
65
66 xc.ReSize(6);
67 vv.ReSize(3);
68 if (position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data()) != success) {
69 return failure;
70 }
71 if (useCorr) {
72 if (_orbCorr && _clkCorr) {
73 double dtO = tt - _orbCorr->_time;
74 if (_orbCorr->_updateInt) {
75 dtO -= (0.5 * ssrUpdateInt[_orbCorr->_updateInt]);
76 }
77 ColumnVector dx(3);
78 dx[0] = _orbCorr->_xr[0] + _orbCorr->_dotXr[0] * dtO;
79 dx[1] = _orbCorr->_xr[1] + _orbCorr->_dotXr[1] * dtO;
80 dx[2] = _orbCorr->_xr[2] + _orbCorr->_dotXr[2] * dtO;
81
82 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), dx, dx);
83
84 xc[0] -= dx[0];
85 xc[1] -= dx[1];
86 xc[2] -= dx[2];
87
88 ColumnVector dv(3);
89 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), _orbCorr->_dotXr, dv);
90
91 vv[0] -= dv[0];
92 vv[1] -= dv[1];
93 vv[2] -= dv[2];
94
95 double dtC = tt - _clkCorr->_time;
96 if (_clkCorr->_updateInt) {
97 dtC -= (0.5 * ssrUpdateInt[_clkCorr->_updateInt]);
98 }
99 xc[3] += _clkCorr->_dClk + _clkCorr->_dotDClk * dtC + _clkCorr->_dotDotDClk * dtC * dtC;
100 }
101 else {
102 return failure;
103 }
104 }
105 return success;
106}
107
108
109//
110//////////////////////////////////////////////////////////////////////////////
111t_irc t_eph::setNavType(QString navTypeStr) {
112 if (navTypeStr == "LNAV") {_navType = t_eph::LNAV;}
113 else if (navTypeStr == "FDMA") {_navType = t_eph::FDMA;}
114 else if (navTypeStr == "FNAV") {_navType = t_eph::FNAV;}
115 else if (navTypeStr == "INAF") {_navType = t_eph::INAF;}
116 else if (navTypeStr == "D1") {_navType = t_eph::D1;}
117 else if (navTypeStr == "D2") {_navType = t_eph::D2;}
118 else if (navTypeStr == "SBAS") {_navType = t_eph::SBASL1;}
119 else if (navTypeStr == "CNAV") {_navType = t_eph::CNAV;}
120 else if (navTypeStr == "CNV1") {_navType = t_eph::CNV1;}
121 else if (navTypeStr == "CNV2") {_navType = t_eph::CNV2;}
122 else if (navTypeStr == "CNV3") {_navType = t_eph::CNV3;}
123 else {_navType = t_eph::undefined; return failure;}
124
125 return success;
126}
127
128//
129//////////////////////////////////////////////////////////////////////////////
130QString t_eph::navTypeString(e_navType navType, const t_prn& prn, double version) {
131 QString navTypeString = "";
132 QString epochStart;
133 QString eolStr;
134
135 if (version < 4.0) {
136 return navTypeString;
137 }
138
139 if (version == 99.0) {
140 epochStart = "";
141 eolStr = "";
142 }
143 else {
144 epochStart = "> ";
145 eolStr = "\n";
146 }
147
148 QString ephStr = QString("EPH %1 ").arg(prn.toString().c_str());
149 switch (navType) {
150 case undefined:
151 navTypeString = epochStart + ephStr + "unknown" + eolStr;
152 break;
153 case LNAV:
154 navTypeString = epochStart + ephStr + "LNAV" + eolStr;
155 break;
156 case FDMA:
157 navTypeString = epochStart + ephStr + "FDMA" + eolStr;
158 break;
159 case FNAV:
160 navTypeString = epochStart + ephStr + "FNAV" + eolStr;
161 break;
162 case INAF:
163 navTypeString = epochStart + ephStr + "INAV" + eolStr;
164 break;
165 case D1:
166 navTypeString = epochStart + ephStr + "D1 " + eolStr;
167 break;
168 case D2:
169 navTypeString = epochStart + ephStr + "D2 " + eolStr;
170 break;
171 case SBASL1:
172 navTypeString = epochStart + ephStr + "SBAS" + eolStr;
173 break;
174 case CNAV:
175 navTypeString = epochStart + ephStr + "CNAV" + eolStr;
176 break;
177 case CNV1:
178 navTypeString = epochStart + ephStr + "CNV1" + eolStr;
179 break;
180 case CNV2:
181 navTypeString = epochStart + ephStr + "CNV2" + eolStr;
182 break;
183 case CNV3:
184 navTypeString = epochStart + ephStr + "CNV3" + eolStr;
185 break;
186 }
187 return navTypeString;
188 }
189
190//
191//////////////////////////////////////////////////////////////////////////////
192QString t_eph::rinexDateStr(const bncTime& tt, const t_prn& prn, double version) {
193 QString prnStr(prn.toString().c_str());
194 return rinexDateStr(tt, prnStr, version);
195}
196
197//
198//////////////////////////////////////////////////////////////////////////////
199QString t_eph::rinexDateStr(const bncTime& tt, const QString& prnStr, double version) {
200
201 QString datStr;
202
203 unsigned year, month, day, hour, min;
204 double sec;
205 tt.civil_date(year, month, day);
206 tt.civil_time(hour, min, sec);
207
208 QTextStream out(&datStr);
209
210 if (version < 3.0) {
211 QString prnHlp = prnStr.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
212 out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
213 .arg(year % 100, 2, 10, QChar('0'))
214 .arg(month, 2)
215 .arg(day, 2)
216 .arg(hour, 2)
217 .arg(min, 2)
218 .arg(sec, 5, 'f',1);
219 }
220 else if (version == 99) {
221 out << QString(" %1 %2 %3 %4 %5 %6")
222 .arg(year, 4)
223 .arg(month, 2, 10, QChar('0'))
224 .arg(day, 2, 10, QChar('0'))
225 .arg(hour, 2, 10, QChar('0'))
226 .arg(min, 2, 10, QChar('0'))
227 .arg(int(sec), 2, 10, QChar('0'));
228 }
229 else {
230 out << prnStr << QString(" %1 %2 %3 %4 %5 %6")
231 .arg(year, 4)
232 .arg(month, 2, 10, QChar('0'))
233 .arg(day, 2, 10, QChar('0'))
234 .arg(hour, 2, 10, QChar('0'))
235 .arg(min, 2, 10, QChar('0'))
236 .arg(int(sec), 2, 10, QChar('0'));
237 }
238
239 return datStr;
240}
241
242// Constructor
243//////////////////////////////////////////////////////////////////////////////
244t_ephGPS::t_ephGPS(double rnxVersion, const QStringList& lines) {
245
246 int nLines = 8;
247
248 if (navType() == t_eph::CNAV) {
249 nLines += 1;
250 }
251 if (navType() == t_eph::CNV2) {
252 nLines += 2;
253 }
254
255 if (lines.size() != nLines) {
256 _checkState = bad;
257 return;
258 }
259
260 // RINEX Format
261 // ------------
262 int fieldLen = 19;
263
264 int pos[4];
265 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
266 pos[1] = pos[0] + fieldLen;
267 pos[2] = pos[1] + fieldLen;
268 pos[3] = pos[2] + fieldLen;
269
270 // Read eight lines
271 // ----------------
272 for (int iLine = 0; iLine < nLines; iLine++) {
273 QString line = lines[iLine];
274
275 if ( iLine == 0 ) {
276 QTextStream in(line.left(pos[1]).toLatin1());
277 int year, month, day, hour, min;
278 double sec;
279
280 QString prnStr, n;
281 in >> prnStr;
282
283 if (prnStr.size() == 1 &&
284 (prnStr[0] == 'G' ||
285 prnStr[0] == 'J' ||
286 prnStr[0] == 'I')) {
287 in >> n;
288 prnStr.append(n);
289 }
290
291 in >> year >> month >> day >> hour >> min >> sec;
292 if (prnStr.at(0) == 'G') {
293 _prn.set('G', prnStr.mid(1).toInt());
294 }
295 else if (prnStr.at(0) == 'J') {
296 _prn.set('J', prnStr.mid(1).toInt());
297 }
298 else if (prnStr.at(0) == 'I') {
299 _prn.set('I', prnStr.mid(1).toInt());
300 }
301 else {
302 _prn.set('G', prnStr.toInt());
303 }
304
305 if (year < 80) {
306 year += 2000;
307 }
308 else if (year < 100) {
309 year += 1900;
310 }
311
312 _TOC.set(year, month, day, hour, min, sec);
313
314 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
315 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
316 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
317 _checkState = bad;
318 return;
319 }
320 }
321 // =====================
322 // BROADCAST ORBIT - 1
323 // =====================
324 else if ( iLine == 1) {
325
326 if (navType() == t_eph::CNAV ||
327 navType() == t_eph::CNV2) {
328 if ( readDbl(line, pos[0], fieldLen, _ADOT ) ||
329 readDbl(line, pos[1], fieldLen, _Crs ) ||
330 readDbl(line, pos[2], fieldLen, _Delta_n) ||
331 readDbl(line, pos[3], fieldLen, _M0 ) ) {
332 _checkState = bad;
333 return;
334 }
335 }
336 else { // LNAV, undefined
337 if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
338 readDbl(line, pos[1], fieldLen, _Crs ) ||
339 readDbl(line, pos[2], fieldLen, _Delta_n) ||
340 readDbl(line, pos[3], fieldLen, _M0 ) ) {
341 _checkState = bad;
342 return;
343 }
344 }
345 }
346 // =====================
347 // BROADCAST ORBIT - 2
348 // =====================
349 else if ( iLine == 2 ) {
350 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
351 readDbl(line, pos[1], fieldLen, _e ) ||
352 readDbl(line, pos[2], fieldLen, _Cus ) ||
353 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
354 _checkState = bad;
355 return;
356 }
357 }
358 // =====================
359 // BROADCAST ORBIT - 3
360 // =====================
361 else if ( iLine == 3 ) {
362
363 if (navType() == t_eph::CNAV ||
364 navType() == t_eph::CNV2) {
365 if ( readDbl(line, pos[0], fieldLen, _top) ||
366 readDbl(line, pos[1], fieldLen, _Cic ) ||
367 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
368 readDbl(line, pos[3], fieldLen, _Cis ) ) {
369 _checkState = bad;
370 return;
371 }
372 }
373 else { // LNAV, undefined
374 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
375 readDbl(line, pos[1], fieldLen, _Cic ) ||
376 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
377 readDbl(line, pos[3], fieldLen, _Cis ) ) {
378 _checkState = bad;
379 return;
380 }
381 }
382 }
383 // =====================
384 // BROADCAST ORBIT - 4
385 // =====================
386 else if ( iLine == 4 ) {
387 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
388 readDbl(line, pos[1], fieldLen, _Crc ) ||
389 readDbl(line, pos[2], fieldLen, _omega ) ||
390 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
391 _checkState = bad;
392 return;
393 }
394 }
395 // =====================
396 // BROADCAST ORBIT - 5
397 // =====================
398 else if ( iLine == 5 && type() != t_eph::IRNSS) {
399
400 if (navType() == t_eph::CNAV ||
401 navType() == t_eph::CNV2) {
402 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
403 readDbl(line, pos[1], fieldLen, _Delta_n_dot) ||
404 readDbl(line, pos[2], fieldLen, _URAI_NED0 ) ||
405 readDbl(line, pos[3], fieldLen, _URAI_NED1) ) {
406 _checkState = bad;
407 return;
408 }
409 }
410 else { // LNAV, undefined
411 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
412 readDbl(line, pos[1], fieldLen, _L2Codes) ||
413 readDbl(line, pos[2], fieldLen, _TOEweek) ||
414 readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
415 _checkState = bad;
416 return;
417 }
418 }
419 }
420 else if ( iLine == 5 && type() == t_eph::IRNSS) {
421 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
422 readDbl(line, pos[2], fieldLen, _TOEweek) ) {
423 _checkState = bad;
424 return;
425 }
426 }
427 // =====================
428 // BROADCAST ORBIT - 6
429 // =====================
430 else if ( iLine == 6 && type() != t_eph::IRNSS) {
431
432 if (navType() == t_eph::CNAV ||
433 navType() == t_eph::CNV2 ) {
434 if ( readDbl(line, pos[0], fieldLen, _URAI_ED) ||
435 readDbl(line, pos[1], fieldLen, _health ) ||
436 readDbl(line, pos[2], fieldLen, _TGD ) ||
437 readDbl(line, pos[3], fieldLen, _URAI_NED2) ) {
438 _checkState = bad;
439 return;
440 }
441 }
442 else { // LNAV, undefined
443 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
444 readDbl(line, pos[1], fieldLen, _health) ||
445 readDbl(line, pos[2], fieldLen, _TGD ) ||
446 readDbl(line, pos[3], fieldLen, _IODC ) ) {
447 _checkState = bad;
448 return;
449 }
450 }
451 }
452 else if ( iLine == 6 && type() == t_eph::IRNSS) {
453 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
454 readDbl(line, pos[1], fieldLen, _health) ||
455 readDbl(line, pos[2], fieldLen, _TGD ) ) {
456 _checkState = bad;
457 return;
458 }
459 }
460 // =====================
461 // BROADCAST ORBIT - 7
462 // =====================
463 else if ( iLine == 7 ) {
464 if (navType() == t_eph::LNAV ||
465 navType() == t_eph::undefined) {
466
467 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
468 _checkState = bad;
469 return;
470 }
471
472 if (type() != t_eph::IRNSS) {
473 double fitIntervalRnx;
474 if ( readDbl(line, pos[1], fieldLen, fitIntervalRnx) ) {
475 _checkState = bad;
476 return;
477 }
478 if (type() == t_eph::GPS) { // in RINEX specified always as time period for GPS
479 _fitInterval = fitIntervalRnx;
480 } else if (type() == t_eph::QZSS) { // specified as flag for QZSS
481 if (rnxVersion == 3.02) {
482 _fitInterval = fitIntervalRnx; // specified as time period
483 }
484 else {
485 _fitInterval = fitIntervalFromFlag(fitIntervalRnx, _IODC, t_eph::QZSS);
486 }
487 }
488 }
489 }
490
491 else if (navType() == t_eph::CNAV ||
492 navType() == t_eph::CNV2) {
493 if ( readDbl(line, pos[0], fieldLen, _ISC_L1CA) ||
494 readDbl(line, pos[1], fieldLen, _ISC_L2C ) ||
495 readDbl(line, pos[2], fieldLen, _ISC_L5I5) ||
496 readDbl(line, pos[3], fieldLen, _ISC_L5Q5) ) {
497 _checkState = bad;
498 return;
499 }
500 }
501
502 }
503 // =====================
504 // BROADCAST ORBIT - 8
505 // =====================
506 else if ( iLine == 8 ) {
507 if (navType() == t_eph::CNAV) {
508 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
509 readDbl(line, pos[1], fieldLen, _wnop) ) {
510 _checkState = bad;
511 return;
512 }
513 }
514 else if (navType() == t_eph::CNV2) {
515 if ( readDbl(line, pos[0], fieldLen, _ISC_L1Cd) ||
516 readDbl(line, pos[1], fieldLen, _ISC_L1Cp)) {
517 _checkState = bad;
518 return;
519 }
520 }
521 }
522 // =====================
523 // BROADCAST ORBIT - 9
524 // =====================
525 else if ( iLine == 9 ) {
526 if (navType() == t_eph::CNV2) {
527 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
528 readDbl(line, pos[1], fieldLen, _wnop) ) {
529 _checkState = bad;
530 return;
531 }
532 }
533 }
534 }
535}
536
537// Compute GPS Satellite Position (virtual)
538////////////////////////////////////////////////////////////////////////////
539t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
540
541 static const double omegaEarth = 7292115.1467e-11;
542 static const double gmGRS = 398.6005e12;
543
544 memset(xc, 0, 6*sizeof(double));
545 memset(vv, 0, 3*sizeof(double));
546
547 double a0 = _sqrt_A * _sqrt_A;
548 if (a0 == 0) {
549 return failure;
550 }
551
552 double n0 = sqrt(gmGRS/(a0*a0*a0));
553
554 bncTime tt(GPSweek, GPSweeks);
555 double tk = tt - bncTime(int(_TOEweek), _TOEsec);
556
557 double n = n0 + _Delta_n;
558 double M = _M0 + n*tk;
559 double E = M;
560 double E_last;
561 int nLoop = 0;
562 do {
563 E_last = E;
564 E = M + _e*sin(E);
565
566 if (++nLoop == 100) {
567 return failure;
568 }
569 } while ( fabs(E-E_last)*a0 > 0.001);
570 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
571 double u0 = v + _omega;
572 double sin2u0 = sin(2*u0);
573 double cos2u0 = cos(2*u0);
574 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
575 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
576 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
577 double xp = r*cos(u);
578 double yp = r*sin(u);
579 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
580 omegaEarth*_TOEsec;
581
582 double sinom = sin(OM);
583 double cosom = cos(OM);
584 double sini = sin(i);
585 double cosi = cos(i);
586 xc[0] = xp*cosom - yp*cosi*sinom;
587 xc[1] = xp*sinom + yp*cosi*cosom;
588 xc[2] = yp*sini;
589
590 double tc = tt - _TOC;
591 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
592
593 // Velocity
594 // --------
595 double tanv2 = tan(v/2);
596 double dEdM = 1 / (1 - _e*cos(E));
597 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
598 * dEdM * n;
599 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
600 double dotom = _OMEGADOT - omegaEarth;
601 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
602 double dotr = a0 * _e*sin(E) * dEdM * n
603 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
604 double dotx = dotr*cos(u) - r*sin(u)*dotu;
605 double doty = dotr*sin(u) + r*cos(u)*dotu;
606
607 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
608 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
609 + yp*sini*sinom*doti; // dX / di
610
611 vv[1] = sinom *dotx + cosi*cosom *doty
612 + xp*cosom*dotom - yp*cosi*sinom*dotom
613 - yp*sini*cosom*doti;
614
615 vv[2] = sini *doty + yp*cosi *doti;
616
617 // Relativistic Correction
618 // -----------------------
619 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
620
621 xc[4] = _clock_drift + _clock_driftrate*tc;
622 xc[5] = _clock_driftrate;
623
624 return success;
625}
626
627// RINEX Format String
628//////////////////////////////////////////////////////////////////////////////
629QString t_ephGPS::toString(double version) const {
630
631 QString navStr = navTypeString(_navType, _prn, version);
632 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
633
634 QTextStream out(&rnxStr);
635
636 out << QString("%1%2%3\n")
637 .arg(_clock_bias, 19, 'e', 12)
638 .arg(_clock_drift, 19, 'e', 12)
639 .arg(_clock_driftrate, 19, 'e', 12);
640
641 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
642
643
644 // =====================
645 // BROADCAST ORBIT - 1
646 // =====================
647 if (navType() == t_eph::CNAV ||
648 navType() == t_eph::CNV2) {
649 out << QString(fmt)
650 .arg(_ADOT, 19, 'e', 12)
651 .arg(_Crs, 19, 'e', 12)
652 .arg(_Delta_n, 19, 'e', 12)
653 .arg(_M0, 19, 'e', 12);
654 }
655 else { // LNAV, undefinded
656 out << QString(fmt)
657 .arg(_IODE, 19, 'e', 12)
658 .arg(_Crs, 19, 'e', 12)
659 .arg(_Delta_n, 19, 'e', 12)
660 .arg(_M0, 19, 'e', 12);
661 }
662 // =====================
663 // BROADCAST ORBIT - 2
664 // =====================
665 out << QString(fmt)
666 .arg(_Cuc, 19, 'e', 12)
667 .arg(_e, 19, 'e', 12)
668 .arg(_Cus, 19, 'e', 12)
669 .arg(_sqrt_A, 19, 'e', 12);
670 // =====================
671 // BROADCAST ORBIT - 3
672 // =====================
673 if (navType() == t_eph::CNAV ||
674 navType() == t_eph::CNV2) {
675 out << QString(fmt)
676 .arg(_top, 19, 'e', 12)
677 .arg(_Cic, 19, 'e', 12)
678 .arg(_OMEGA0, 19, 'e', 12)
679 .arg(_Cis, 19, 'e', 12);
680 }
681 else {
682 out << QString(fmt)
683 .arg(_TOEsec, 19, 'e', 12)
684 .arg(_Cic, 19, 'e', 12)
685 .arg(_OMEGA0, 19, 'e', 12)
686 .arg(_Cis, 19, 'e', 12);
687 }
688 // =====================
689 // BROADCAST ORBIT - 4
690 // =====================
691 out << QString(fmt)
692 .arg(_i0, 19, 'e', 12)
693 .arg(_Crc, 19, 'e', 12)
694 .arg(_omega, 19, 'e', 12)
695 .arg(_OMEGADOT, 19, 'e', 12);
696 // =====================
697 // BROADCAST ORBIT - 5
698 // =====================
699 if (type() == t_eph::IRNSS) {
700 out << QString(fmt)
701 .arg(_IDOT, 19, 'e', 12)
702 .arg(0.0, 19, 'e', 12)
703 .arg(_TOEweek, 19, 'e', 12)
704 .arg(0.0, 19, 'e', 12);
705 }
706 else {
707 if (navType() == t_eph::CNAV ||
708 navType() == t_eph::CNV2) {
709 out << QString(fmt)
710 .arg(_IDOT, 19, 'e', 12)
711 .arg(_Delta_n_dot, 19, 'e', 12)
712 .arg(_URAI_NED0, 19, 'e', 12)
713 .arg(_URAI_NED1, 19, 'e', 12);
714
715 }
716 else { // LNAV, undefined
717 out << QString(fmt)
718 .arg(_IDOT, 19, 'e', 12)
719 .arg(_L2Codes, 19, 'e', 12)
720 .arg(_TOEweek, 19, 'e', 12)
721 .arg(_L2PFlag, 19, 'e', 12);
722
723 }
724 }
725 // =====================
726 // BROADCAST ORBIT - 6
727 // =====================
728 if (type() == t_eph::IRNSS) {
729 out << QString(fmt)
730 .arg(_ura, 19, 'e', 12)
731 .arg(_health, 19, 'e', 12)
732 .arg(_TGD, 19, 'e', 12)
733 .arg(0.0, 19, 'e', 12);
734 }
735 else {
736 if (navType() == t_eph::CNAV ||
737 navType() == t_eph::CNV2) {
738 out << QString(fmt)
739 .arg(_URAI_ED, 19, 'e', 12)
740 .arg(_health, 19, 'e', 12)
741 .arg(_TGD, 19, 'e', 12)
742 .arg(_URAI_NED2,19, 'e', 12);
743
744 }
745 else { // LNAV, undefined
746 out << QString(fmt)
747 .arg(_ura, 19, 'e', 12)
748 .arg(_health, 19, 'e', 12)
749 .arg(_TGD, 19, 'e', 12)
750 .arg(_IODC, 19, 'e', 12);
751 }
752 }
753 // =====================
754 // BROADCAST ORBIT - 7
755 // =====================
756 if (navType() == t_eph::LNAV ||
757 navType() == t_eph::undefined) {
758
759 double tot = _TOT;
760 if (tot == 0.9999e9 && version < 3.0) {
761 tot = 0.0;
762 }
763 // fitInterval
764 if (type() == t_eph::IRNSS) {// not valid for IRNSS
765 out << QString(fmt)
766 .arg(tot, 19, 'e', 12)
767 .arg(0.0, 19, 'e', 12)
768 .arg("", 19, QChar(' '))
769 .arg("", 19, QChar(' '));
770 }
771 else {
772 // for GPS and QZSS in version 3.02 specified in hours
773 double fitIntervalRnx = _fitInterval;
774 // otherwise specified as flag
775 if (type() == t_eph::QZSS && version != 3.02) {
776 (_fitInterval == 2.0) ? fitIntervalRnx = 0.0 : fitIntervalRnx = 1.0;
777 }
778 out << QString(fmt)
779 .arg(tot, 19, 'e', 12)
780 .arg(fitIntervalRnx, 19, 'e', 12)
781 .arg("", 19, QChar(' '))
782 .arg("", 19, QChar(' '));
783 }
784 }
785 else if (navType() == t_eph::CNAV ||
786 navType() == t_eph::CNV2) {
787 out << QString(fmt)
788 .arg(_ISC_L1CA, 19, 'e', 12)
789 .arg(_ISC_L2C, 19, 'e', 12)
790 .arg(_ISC_L5I5, 19, 'e', 12)
791 .arg(_ISC_L5Q5, 19, 'e', 12);
792 }
793 // =====================
794 // BROADCAST ORBIT - 8
795 // =====================
796 if (navType() == t_eph::CNAV) {
797 out << QString(fmt)
798 .arg(_TOT, 19, 'e', 12)
799 .arg(_wnop, 19, 'e', 12)
800 .arg("", 19, QChar(' '))
801 .arg("", 19, QChar(' '));
802 }
803 else if (navType() == t_eph::CNV2) {
804 out << QString(fmt)
805 .arg(_ISC_L1Cd, 19, 'e', 12)
806 .arg(_ISC_L1Cp, 19, 'e', 12)
807 .arg("", 19, QChar(' '))
808 .arg("", 19, QChar(' '));
809 }
810
811 // =====================
812 // BROADCAST ORBIT - 9
813 // =====================
814 if (navType() == t_eph::CNV2) {
815 out << QString(fmt)
816 .arg(_TOT, 19, 'e', 12)
817 .arg(_wnop, 19, 'e', 12)
818 .arg("", 19, QChar(' '))
819 .arg("", 19, QChar(' '));
820 }
821
822 return rnxStr;
823}
824
825// Constructor
826//////////////////////////////////////////////////////////////////////////////
827t_ephGlo::t_ephGlo(double rnxVersion, const QStringList& lines) {
828
829 int nLines = 4;
830 if (rnxVersion >= 3.05) {
831 nLines += 1;
832 }
833 else {
834 _M_delta_tau = 0.9999e9; // unknown
835 _M_FT = 1.5e1; // unknown
836 }
837
838 if (lines.size() != nLines) {
839 _checkState = bad;
840 return;
841 }
842
843 // RINEX Format
844 // ------------
845 int fieldLen = 19;
846 double statusflags = 0.0;
847 double healthflags = 0.0;
848
849 int pos[4];
850 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
851 pos[1] = pos[0] + fieldLen;
852 pos[2] = pos[1] + fieldLen;
853 pos[3] = pos[2] + fieldLen;
854
855 // Read four lines
856 // ---------------
857 for (int iLine = 0; iLine < nLines; iLine++) {
858 QString line = lines[iLine];
859
860 if ( iLine == 0 ) {
861 QTextStream in(line.left(pos[1]).toLatin1());
862
863 int year, month, day, hour, min;
864 double sec;
865
866 QString prnStr, n;
867 in >> prnStr;
868 if (prnStr.size() == 1 && prnStr[0] == 'R') {
869 in >> n;
870 prnStr.append(n);
871 }
872 in >> year >> month >> day >> hour >> min >> sec;
873 if (prnStr.at(0) == 'R') {
874 _prn.set('R', prnStr.mid(1).toInt());
875 }
876 else {
877 _prn.set('R', prnStr.toInt());
878 }
879
880 if (year < 80) {
881 year += 2000;
882 }
883 else if (year < 100) {
884 year += 1900;
885 }
886
887 _gps_utc = gnumleap(year, month, day);
888
889 _TOC.set(year, month, day, hour, min, sec);
890 _TOC = _TOC + _gps_utc;
891 int nd = int((_TOC.gpssec())) / (24.0*60.0*60.0);
892 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
893 readDbl(line, pos[2], fieldLen, _gamma) ||
894 readDbl(line, pos[3], fieldLen, _tki ) ) {
895 _checkState = bad;
896 return;
897 }
898 _tki -= nd * 86400.0;
899 _tau = -_tau;
900 }
901 // =====================
902 // BROADCAST ORBIT - 1
903 // =====================
904 else if ( iLine == 1 ) {
905 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
906 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
907 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
908 readDbl(line, pos[3], fieldLen, _health ) ) {
909 _checkState = bad;
910 return;
911 }
912 }
913 // =====================
914 // BROADCAST ORBIT - 2
915 // =====================
916 else if ( iLine == 2 ) {
917 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
918 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
919 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
920 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
921 _checkState = bad;
922 return;
923 }
924 }
925 // =====================
926 // BROADCAST ORBIT - 3
927 // =====================
928 else if ( iLine == 3 ) {
929 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
930 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
931 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
932 readDbl(line, pos[3], fieldLen, _E ) ) {
933 _checkState = bad;
934 return;
935 }
936 }
937 // =====================
938 // BROADCAST ORBIT - 4
939 // =====================
940 else if ( iLine == 4 ) {
941 if (readDbl(line, pos[0], fieldLen, statusflags ) ) {
942 //statusflags BLK, do nothing
943 _flags_unknown = true;
944 }
945 else {
946 _flags_unknown = false;
947 // status flags
948 // ============
949 // bit 0-1
950 _M_P = double(bitExtracted(statusflags, 2, 0));
951 // bit 2-3
952 _P1 = double(bitExtracted(statusflags, 2, 2));
953 // bit 4
954 _P2 = double(bitExtracted(statusflags, 1, 4));
955 // bit 5
956 _P3 = double(bitExtracted(statusflags, 1, 5));
957 // bit 6
958 _M_P4 = double(bitExtracted(statusflags, 1, 6));
959 // bit 7-8
960 _M_M = double(bitExtracted(statusflags, 2, 7));
961 /// GLO M/K exclusive flags/values only valid if flag M is set to '01'
962 if (!_M_M) {
963 _M_P4 = 0.0;
964 _M_P = 0.0;
965 }
966 }
967 if ( readDbl(line, pos[1], fieldLen, _M_delta_tau ) ||
968 readDbl(line, pos[2], fieldLen, _M_FT ) ) {
969 _checkState = bad;
970 return;
971 }
972 if (readDbl(line, pos[3], fieldLen, healthflags ) ) {
973 // healthflags BLK
974 _flags_unknown = true;
975 }
976 else {
977 _flags_unknown = false;
978 // health flags
979 // ============
980 // bit 0 (is to be ignored, if bit 1 is zero)
981 _almanac_health = double(bitExtracted(healthflags, 1, 0));
982 // bit 1
983 _almanac_health_availablility_indicator = double(bitExtracted(healthflags, 1, 1));
984 // bit 2
985 _M_l3 = double(bitExtracted(healthflags, 1, 2));
986 }
987 }
988 }
989
990 // Initialize status vector
991 // ------------------------
992 _tt = _TOC;
993 _xv.ReSize(6); _xv = 0.0;
994 _xv(1) = _x_pos * 1.e3;
995 _xv(2) = _y_pos * 1.e3;
996 _xv(3) = _z_pos * 1.e3;
997 _xv(4) = _x_velocity * 1.e3;
998 _xv(5) = _y_velocity * 1.e3;
999 _xv(6) = _z_velocity * 1.e3;
1000}
1001
1002// Compute Glonass Satellite Position (virtual)
1003////////////////////////////////////////////////////////////////////////////
1004t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1005
1006 static const double nominalStep = 10.0;
1007
1008 memset(xc, 0, 6*sizeof(double));
1009 memset(vv, 0, 3*sizeof(double));
1010
1011 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
1012
1013 if (fabs(dtPos) > 24 * 3600.0) {
1014 return failure;
1015 }
1016
1017 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
1018 double step = dtPos / nSteps;
1019
1020 double acc[3];
1021 acc[0] = _x_acceleration * 1.e3;
1022 acc[1] = _y_acceleration * 1.e3;
1023 acc[2] = _z_acceleration * 1.e3;
1024
1025 for (int ii = 1; ii <= nSteps; ii++) {
1026 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
1027 _tt = _tt + step;
1028 }
1029
1030 // Position and Velocity
1031 // ---------------------
1032 xc[0] = _xv(1);
1033 xc[1] = _xv(2);
1034 xc[2] = _xv(3);
1035
1036 vv[0] = _xv(4);
1037 vv[1] = _xv(5);
1038 vv[2] = _xv(6);
1039
1040 // Clock Correction
1041 // ----------------
1042 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
1043 xc[3] = -_tau + _gamma * dtClk;
1044
1045 xc[4] = _gamma;
1046 xc[5] = 0.0;
1047
1048 return success;
1049}
1050
1051// RINEX Format String
1052//////////////////////////////////////////////////////////////////////////////
1053QString t_ephGlo::toString(double version) const {
1054
1055 QString navStr = navTypeString(_navType, _prn, version);
1056 QString rnxStr = navStr + rinexDateStr(_TOC -_gps_utc, _prn, version);
1057 int nd = int((_TOC - _gps_utc).gpssec()) / (24.0*60.0*60.0);
1058 QTextStream out(&rnxStr);
1059
1060 out << QString("%1%2%3\n")
1061 .arg(-_tau, 19, 'e', 12)
1062 .arg(_gamma, 19, 'e', 12)
1063 .arg(_tki+nd*86400.0, 19, 'e', 12);
1064
1065 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1066 // =====================
1067 // BROADCAST ORBIT - 1
1068 // =====================
1069 out << QString(fmt)
1070 .arg(_x_pos, 19, 'e', 12)
1071 .arg(_x_velocity, 19, 'e', 12)
1072 .arg(_x_acceleration, 19, 'e', 12)
1073 .arg(_health, 19, 'e', 12);
1074 // =====================
1075 // BROADCAST ORBIT - 2
1076 // =====================
1077 out << QString(fmt)
1078 .arg(_y_pos, 19, 'e', 12)
1079 .arg(_y_velocity, 19, 'e', 12)
1080 .arg(_y_acceleration, 19, 'e', 12)
1081 .arg(_frequency_number, 19, 'e', 12);
1082 // =====================
1083 // BROADCAST ORBIT - 3
1084 // =====================
1085 out << QString(fmt)
1086 .arg(_z_pos, 19, 'e', 12)
1087 .arg(_z_velocity, 19, 'e', 12)
1088 .arg(_z_acceleration, 19, 'e', 12)
1089 .arg(_E, 19, 'e', 12);
1090 // =====================
1091 // BROADCAST ORBIT - 4
1092 // =====================
1093 if (version >= 3.05) {
1094 // unknown (RINEX version < 3.05)
1095 if (_flags_unknown) {
1096 out << QString(fmt)
1097 .arg("", 19, QChar(' ')) // statusflags blank if unknown
1098 .arg(_M_delta_tau, 19, 'e', 12)
1099 .arg(_M_FT, 19, 'e', 12)
1100 .arg("", 19, QChar(' ')); // healthflags blank if unknown
1101 }
1102 else {
1103 int statusflags = 0;
1104 // bit 7-8
1105 if (_M_M == 2.0) {
1106 statusflags |= (1<<7);
1107 }
1108 // bit 6
1109 if (_M_P4) {
1110 statusflags |= (1<<6);
1111 }
1112 // bit 5
1113 if (_P3) {
1114 statusflags |= (1<<5);
1115 }
1116 // bit 4
1117 if (_P2) {
1118 statusflags |= (1<<4);
1119 }
1120 // bit 2-3
1121 if (_P1 == 2.0) {
1122 statusflags |= (1<<2);
1123 }
1124 else if (_P1 == 1.0) {
1125 statusflags |= (1<<3);
1126 }
1127 else if (_P1 == 3.0) {
1128 statusflags |= (1<<2);
1129 statusflags |= (1<<3);
1130 }
1131 // bit 0-1
1132 if (_M_P == 2.0) {
1133 statusflags |= (1<<0);
1134 }
1135 else if (_M_P == 1.0) {
1136 statusflags |= (1<<1);
1137 }
1138 else if (_M_P == 3.0) {
1139 statusflags |= (1<<0);
1140 statusflags |= (1<<1);
1141 }
1142 // health flags
1143 // ============
1144 int healthflags = 0;
1145 // bit 0 (is to be ignored, if bit 1 is zero)
1146 if (_almanac_health) {
1147 healthflags |= (1<<0);
1148 }
1149 // bit 1
1150 if (_almanac_health_availablility_indicator) {
1151 healthflags |= (1<<1);
1152 }
1153 // bit 2
1154 if (_M_l3) {
1155 healthflags |= (1<<2);
1156 }
1157 out << QString(fmt)
1158 .arg(double(statusflags), 19, 'e', 12)
1159 .arg(_M_delta_tau, 19, 'e', 12)
1160 .arg(_M_FT, 19, 'e', 12)
1161 .arg(double(healthflags), 19, 'e', 12);
1162 }
1163 }
1164
1165 return rnxStr;
1166}
1167
1168// Derivative of the state vector using a simple force model (static)
1169////////////////////////////////////////////////////////////////////////////
1170ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
1171 double* acc) {
1172
1173 // State vector components
1174 // -----------------------
1175 ColumnVector rr = xv.rows(1,3);
1176 ColumnVector vv = xv.rows(4,6);
1177
1178 // Acceleration
1179 // ------------
1180 static const double gmWGS = 398.60044e12;
1181 static const double AE = 6378136.0;
1182 static const double OMEGA = 7292115.e-11;
1183 static const double C20 = -1082.6257e-6;
1184
1185 double rho = rr.NormFrobenius();
1186 double t1 = -gmWGS/(rho*rho*rho);
1187 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
1188 double t3 = OMEGA * OMEGA;
1189 double t4 = 2.0 * OMEGA;
1190 double z2 = rr(3) * rr(3);
1191
1192 // Vector of derivatives
1193 // ---------------------
1194 ColumnVector va(6);
1195 va(1) = vv(1);
1196 va(2) = vv(2);
1197 va(3) = vv(3);
1198 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
1199 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
1200 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
1201
1202 return va;
1203}
1204
1205// IOD of Glonass Ephemeris (virtual)
1206////////////////////////////////////////////////////////////////////////////
1207unsigned int t_ephGlo::IOD() const {
1208 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
1209 return (unsigned long)tMoscow.daysec() / 900;
1210}
1211
1212// Health status of Glonass Ephemeris (virtual)
1213////////////////////////////////////////////////////////////////////////////
1214unsigned int t_ephGlo::isUnhealthy() const {
1215
1216 if (_almanac_health_availablility_indicator) {
1217 if ((_health == 0 && _almanac_health == 0) ||
1218 (_health == 1 && _almanac_health == 0) ||
1219 (_health == 1 && _almanac_health == 1)) {
1220 return 1;
1221 }
1222 }
1223 else if (!_almanac_health_availablility_indicator) {
1224 if (_health) {
1225 return 1;
1226 }
1227 }
1228 return 0; /* (_health == 0 && _almanac_health == 1) or (_health == 0) */
1229}
1230
1231// Constructor
1232//////////////////////////////////////////////////////////////////////////////
1233t_ephGal::t_ephGal(double rnxVersion, const QStringList& lines) {
1234 int year, month, day, hour, min;
1235 double sec;
1236 QString prnStr;
1237 const int nLines = 8;
1238 if (lines.size() != nLines) {
1239 _checkState = bad;
1240 return;
1241 }
1242
1243 // RINEX Format
1244 // ------------
1245 int fieldLen = 19;
1246 double SVhealth = 0.0;
1247 double datasource = 0.0;
1248
1249 int pos[4];
1250 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1251 pos[1] = pos[0] + fieldLen;
1252 pos[2] = pos[1] + fieldLen;
1253 pos[3] = pos[2] + fieldLen;
1254
1255 // Read eight lines
1256 // ----------------
1257 for (int iLine = 0; iLine < nLines; iLine++) {
1258 QString line = lines[iLine];
1259
1260 if ( iLine == 0 ) {
1261 QTextStream in(line.left(pos[1]).toLatin1());
1262 QString n;
1263 in >> prnStr;
1264 if (prnStr.size() == 1 && prnStr[0] == 'E') {
1265 in >> n;
1266 prnStr.append(n);
1267 }
1268 in >> year >> month >> day >> hour >> min >> sec;
1269 if (year < 80) {
1270 year += 2000;
1271 }
1272 else if (year < 100) {
1273 year += 1900;
1274 }
1275
1276 _TOC.set(year, month, day, hour, min, sec);
1277
1278 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1279 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1280 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1281 _checkState = bad;
1282 return;
1283 }
1284 }
1285 // =====================
1286 // BROADCAST ORBIT - 1
1287 // =====================
1288 else if ( iLine == 1 ) {
1289 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
1290 readDbl(line, pos[1], fieldLen, _Crs ) ||
1291 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1292 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1293 _checkState = bad;
1294 return;
1295 }
1296 }
1297 // =====================
1298 // BROADCAST ORBIT - 2
1299 // =====================
1300 else if ( iLine == 2 ) {
1301 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1302 readDbl(line, pos[1], fieldLen, _e ) ||
1303 readDbl(line, pos[2], fieldLen, _Cus ) ||
1304 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1305 _checkState = bad;
1306 return;
1307 }
1308 }
1309 // =====================
1310 // BROADCAST ORBIT - 3
1311 // =====================
1312 else if ( iLine == 3 ) {
1313 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
1314 readDbl(line, pos[1], fieldLen, _Cic ) ||
1315 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1316 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1317 _checkState = bad;
1318 return;
1319 }
1320 }
1321 // =====================
1322 // BROADCAST ORBIT - 4
1323 // =====================
1324 else if ( iLine == 4 ) {
1325 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1326 readDbl(line, pos[1], fieldLen, _Crc ) ||
1327 readDbl(line, pos[2], fieldLen, _omega ) ||
1328 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1329 _checkState = bad;
1330 return;
1331 }
1332 }
1333 // =====================
1334 // BROADCAST ORBIT - 5
1335 // =====================
1336 else if ( iLine == 5 ) {
1337 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
1338 readDbl(line, pos[1], fieldLen, datasource) ||
1339 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
1340 _checkState = bad;
1341 return;
1342 } else {
1343 if (int(datasource) & (1<<8)) {
1344 _fnav = true;
1345 _inav = false;
1346 } else if (int(datasource) & (1<<9)) {
1347 _fnav = false;
1348 _inav = true;
1349 }
1350 _TOEweek -= 1024.0;
1351 }
1352 }
1353 // =====================
1354 // BROADCAST ORBIT - 6
1355 // =====================
1356 else if ( iLine == 6 ) {
1357 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
1358 readDbl(line, pos[1], fieldLen, SVhealth) ||
1359 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
1360 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
1361 _checkState = bad;
1362 return;
1363 } else {
1364 // Bit 0
1365 _e1DataInValid = (int(SVhealth) & (1<<0));
1366 // Bit 1-2
1367 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
1368 // Bit 3
1369 _e5aDataInValid = (int(SVhealth) & (1<<3));
1370 // Bit 4-5
1371 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
1372 // Bit 6
1373 _e5bDataInValid = (int(SVhealth) & (1<<6));
1374 // Bit 7-8
1375 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
1376
1377 if (prnStr.at(0) == 'E') {
1378 _prn.set('E', prnStr.mid(1).toInt(), _inav ? 1 : 0);
1379 }
1380 }
1381 }
1382 // =====================
1383 // BROADCAST ORBIT - 7
1384 // =====================
1385 else if ( iLine == 7 ) {
1386 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
1387 _checkState = bad;
1388 return;
1389 }
1390 }
1391 }
1392}
1393
1394// Compute Galileo Satellite Position (virtual)
1395////////////////////////////////////////////////////////////////////////////
1396t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1397
1398 static const double omegaEarth = 7292115.1467e-11;
1399 static const double gmWGS = 398.6004418e12;
1400
1401 memset(xc, 0, 6*sizeof(double));
1402 memset(vv, 0, 3*sizeof(double));
1403
1404 double a0 = _sqrt_A * _sqrt_A;
1405 if (a0 == 0) {
1406 return failure;
1407 }
1408
1409 double n0 = sqrt(gmWGS/(a0*a0*a0));
1410
1411 bncTime tt(GPSweek, GPSweeks);
1412 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
1413
1414 double n = n0 + _Delta_n;
1415 double M = _M0 + n*tk;
1416 double E = M;
1417 double E_last;
1418 int nLoop = 0;
1419 do {
1420 E_last = E;
1421 E = M + _e*sin(E);
1422
1423 if (++nLoop == 100) {
1424 return failure;
1425 }
1426 } while ( fabs(E-E_last)*a0 > 0.001 );
1427 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
1428 double u0 = v + _omega;
1429 double sin2u0 = sin(2*u0);
1430 double cos2u0 = cos(2*u0);
1431 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1432 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1433 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1434 double xp = r*cos(u);
1435 double yp = r*sin(u);
1436 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
1437 omegaEarth*_TOEsec;
1438
1439 double sinom = sin(OM);
1440 double cosom = cos(OM);
1441 double sini = sin(i);
1442 double cosi = cos(i);
1443 xc[0] = xp*cosom - yp*cosi*sinom;
1444 xc[1] = xp*sinom + yp*cosi*cosom;
1445 xc[2] = yp*sini;
1446
1447 double tc = tt - _TOC;
1448 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1449
1450 // Velocity
1451 // --------
1452 double tanv2 = tan(v/2);
1453 double dEdM = 1 / (1 - _e*cos(E));
1454 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
1455 * dEdM * n;
1456 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1457 double dotom = _OMEGADOT - omegaEarth;
1458 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1459 double dotr = a0 * _e*sin(E) * dEdM * n
1460 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1461 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1462 double doty = dotr*sin(u) + r*cos(u)*dotu;
1463
1464 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1465 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1466 + yp*sini*sinom*doti; // dX / di
1467
1468 vv[1] = sinom *dotx + cosi*cosom *doty
1469 + xp*cosom*dotom - yp*cosi*sinom*dotom
1470 - yp*sini*cosom*doti;
1471
1472 vv[2] = sini *doty + yp*cosi *doti;
1473
1474 // Relativistic Correction
1475 // -----------------------
1476 xc[3] -= 4.442807309e-10 * _e * sqrt(a0) *sin(E);
1477
1478 xc[4] = _clock_drift + _clock_driftrate*tc;
1479 xc[5] = _clock_driftrate;
1480
1481 return success;
1482}
1483
1484// Health status of Galileo Ephemeris (virtual)
1485////////////////////////////////////////////////////////////////////////////
1486unsigned int t_ephGal::isUnhealthy() const {
1487 if (_E5aHS || _E5bHS || _E1_bHS) {
1488 return 1;
1489 }
1490 if (_SISA == 255.0) {
1491 return 1;
1492 }
1493 if (_e5aDataInValid || _e5bDataInValid || _e1DataInValid) {
1494 return 1;
1495 }
1496 return 0;
1497}
1498
1499// RINEX Format String
1500//////////////////////////////////////////////////////////////////////////////
1501QString t_ephGal::toString(double version) const {
1502
1503 QString navStr = navTypeString(_navType, _prn, version);
1504 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
1505
1506 QTextStream out(&rnxStr);
1507
1508 out << QString("%1%2%3\n")
1509 .arg(_clock_bias, 19, 'e', 12)
1510 .arg(_clock_drift, 19, 'e', 12)
1511 .arg(_clock_driftrate, 19, 'e', 12);
1512
1513 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1514 // =====================
1515 // BROADCAST ORBIT - 1
1516 // =====================
1517 out << QString(fmt)
1518 .arg(_IODnav, 19, 'e', 12)
1519 .arg(_Crs, 19, 'e', 12)
1520 .arg(_Delta_n, 19, 'e', 12)
1521 .arg(_M0, 19, 'e', 12);
1522 // =====================
1523 // BROADCAST ORBIT - 2
1524 // =====================
1525 out << QString(fmt)
1526 .arg(_Cuc, 19, 'e', 12)
1527 .arg(_e, 19, 'e', 12)
1528 .arg(_Cus, 19, 'e', 12)
1529 .arg(_sqrt_A, 19, 'e', 12);
1530 // =====================
1531 // BROADCAST ORBIT - 3
1532 // =====================
1533 out << QString(fmt)
1534 .arg(_TOEsec, 19, 'e', 12)
1535 .arg(_Cic, 19, 'e', 12)
1536 .arg(_OMEGA0, 19, 'e', 12)
1537 .arg(_Cis, 19, 'e', 12);
1538 // =====================
1539 // BROADCAST ORBIT - 4
1540 // =====================
1541 out << QString(fmt)
1542 .arg(_i0, 19, 'e', 12)
1543 .arg(_Crc, 19, 'e', 12)
1544 .arg(_omega, 19, 'e', 12)
1545 .arg(_OMEGADOT, 19, 'e', 12);
1546 // =====================
1547 // BROADCAST ORBIT - 5
1548 // =====================
1549 int dataSource = 0;
1550 int SVhealth = 0;
1551 double BGD_1_5A = _BGD_1_5A;
1552 double BGD_1_5B = _BGD_1_5B;
1553 if (_fnav) {
1554 dataSource |= (1<<1);
1555 dataSource |= (1<<8);
1556 BGD_1_5B = 0.0;
1557 // SVhealth
1558 // Bit 3 : E5a DVS
1559 if (_e5aDataInValid) {
1560 SVhealth |= (1<<3);
1561 }
1562 // Bit 4-5: E5a HS
1563 if (_E5aHS == 1.0) {
1564 SVhealth |= (1<<4);
1565 }
1566 else if (_E5aHS == 2.0) {
1567 SVhealth |= (1<<5);
1568 }
1569 else if (_E5aHS == 3.0) {
1570 SVhealth |= (1<<4);
1571 SVhealth |= (1<<5);
1572 }
1573 }
1574 else if(_inav) {
1575 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1576 // and RNXv3.03 says both can be set if the navigation messages were merged
1577 dataSource |= (1<<0);
1578 dataSource |= (1<<2);
1579 dataSource |= (1<<9);
1580 // SVhealth
1581 // Bit 0 : E1-B DVS
1582 if (_e1DataInValid) {
1583 SVhealth |= (1<<0);
1584 }
1585 // Bit 1-2: E1-B HS
1586 if (_E1_bHS == 1.0) {
1587 SVhealth |= (1<<1);
1588 }
1589 else if (_E1_bHS == 2.0) {
1590 SVhealth |= (1<<2);
1591 }
1592 else if (_E1_bHS == 3.0) {
1593 SVhealth |= (1<<1);
1594 SVhealth |= (1<<2);
1595 }
1596 // Bit 3 : E5a DVS
1597 if (_e5aDataInValid) {
1598 SVhealth |= (1<<3);
1599 }
1600 // Bit 4-5: E5a HS
1601 if (_E5aHS == 1.0) {
1602 SVhealth |= (1<<4);
1603 }
1604 else if (_E5aHS == 2.0) {
1605 SVhealth |= (1<<5);
1606 }
1607 else if (_E5aHS == 3.0) {
1608 SVhealth |= (1<<4);
1609 SVhealth |= (1<<5);
1610 }
1611 // Bit 6 : E5b DVS
1612 if (_e5bDataInValid) {
1613 SVhealth |= (1<<6);
1614 }
1615 // Bit 7-8: E5b HS
1616 if (_E5bHS == 1.0) {
1617 SVhealth |= (1<<7);
1618 }
1619 else if (_E5bHS == 2.0) {
1620 SVhealth |= (1<<8);
1621 }
1622 else if (_E5bHS == 3.0) {
1623 SVhealth |= (1<<7);
1624 SVhealth |= (1<<8);
1625 }
1626 }
1627
1628 out << QString(fmt)
1629 .arg(_IDOT, 19, 'e', 12)
1630 .arg(double(dataSource), 19, 'e', 12)
1631 .arg(_TOEweek + 1024.0, 19, 'e', 12)
1632 .arg(0.0, 19, 'e', 12);
1633 // =====================
1634 // BROADCAST ORBIT - 6
1635 // =====================
1636 out << QString(fmt)
1637 .arg(_SISA, 19, 'e', 12)
1638 .arg(double(SVhealth), 19, 'e', 12)
1639 .arg(BGD_1_5A, 19, 'e', 12)
1640 .arg(BGD_1_5B, 19, 'e', 12);
1641 // =====================
1642 // BROADCAST ORBIT - 7
1643 // =====================
1644 double tot = _TOT;
1645 if (tot == 0.9999e9 && version < 3.0) {
1646 tot = 0.0;
1647 }
1648 out << QString(fmt)
1649 .arg(tot, 19, 'e', 12)
1650 .arg("", 19, QChar(' '))
1651 .arg("", 19, QChar(' '))
1652 .arg("", 19, QChar(' '));
1653
1654 return rnxStr;
1655}
1656
1657// Constructor
1658//////////////////////////////////////////////////////////////////////////////
1659t_ephSBAS::t_ephSBAS(double rnxVersion, const QStringList& lines) {
1660
1661 const int nLines = 4;
1662
1663 if (lines.size() != nLines) {
1664 _checkState = bad;
1665 return;
1666 }
1667
1668 // RINEX Format
1669 // ------------
1670 int fieldLen = 19;
1671
1672 int pos[4];
1673 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1674 pos[1] = pos[0] + fieldLen;
1675 pos[2] = pos[1] + fieldLen;
1676 pos[3] = pos[2] + fieldLen;
1677
1678 // Read four lines
1679 // ---------------
1680 for (int iLine = 0; iLine < nLines; iLine++) {
1681 QString line = lines[iLine];
1682
1683 if ( iLine == 0 ) {
1684 QTextStream in(line.left(pos[1]).toLatin1());
1685
1686 int year, month, day, hour, min;
1687 double sec;
1688
1689 QString prnStr, n;
1690 in >> prnStr;
1691 if (prnStr.size() == 1 && prnStr[0] == 'S') {
1692 in >> n;
1693 prnStr.append(n);
1694 }
1695 in >> year >> month >> day >> hour >> min >> sec;
1696 if (prnStr.at(0) == 'S') {
1697 _prn.set('S', prnStr.mid(1).toInt());
1698 }
1699 else {
1700 _prn.set('S', prnStr.toInt());
1701 }
1702
1703 if (year < 80) {
1704 year += 2000;
1705 }
1706 else if (year < 100) {
1707 year += 1900;
1708 }
1709
1710 _TOC.set(year, month, day, hour, min, sec);
1711
1712 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1713 readDbl(line, pos[2], fieldLen, _agf1 ) ||
1714 readDbl(line, pos[3], fieldLen, _TOT ) ) {
1715 _checkState = bad;
1716 return;
1717 }
1718 }
1719 // =====================
1720 // BROADCAST ORBIT - 1
1721 // =====================
1722 else if ( iLine == 1 ) {
1723 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1724 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1725 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1726 readDbl(line, pos[3], fieldLen, _health ) ) {
1727 _checkState = bad;
1728 return;
1729 }
1730 }
1731 // =====================
1732 // BROADCAST ORBIT - 2
1733 // =====================
1734 else if ( iLine == 2 ) {
1735 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1736 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1737 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1738 readDbl(line, pos[3], fieldLen, _ura ) ) {
1739 _checkState = bad;
1740 return;
1741 }
1742 }
1743 // =====================
1744 // BROADCAST ORBIT - 3
1745 // =====================
1746 else if ( iLine == 3 ) {
1747 double iodn;
1748 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1749 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1750 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
1751 readDbl(line, pos[3], fieldLen, iodn ) ) {
1752 _checkState = bad;
1753 return;
1754 } else {
1755 _IODN = int(iodn);
1756 }
1757 }
1758 }
1759
1760 _x_pos *= 1.e3;
1761 _y_pos *= 1.e3;
1762 _z_pos *= 1.e3;
1763 _x_velocity *= 1.e3;
1764 _y_velocity *= 1.e3;
1765 _z_velocity *= 1.e3;
1766 _x_acceleration *= 1.e3;
1767 _y_acceleration *= 1.e3;
1768 _z_acceleration *= 1.e3;
1769}
1770
1771// IOD of SBAS Ephemeris (virtual)
1772////////////////////////////////////////////////////////////////////////////
1773
1774unsigned int t_ephSBAS::IOD() const {
1775 unsigned char buffer[80];
1776 int size = 0;
1777 int numbits = 0;
1778 long long bitbuffer = 0;
1779 unsigned char *startbuffer = buffer;
1780
1781 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1782 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1783 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1784 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1785 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1786 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1787 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1788 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1789 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1790 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1791 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1792 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1793
1794 return CRC24(size, startbuffer);
1795}
1796
1797// Compute SBAS Satellite Position (virtual)
1798////////////////////////////////////////////////////////////////////////////
1799t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1800
1801 bncTime tt(GPSweek, GPSweeks);
1802 double dt = tt - _TOC;
1803
1804 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1805 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1806 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
1807
1808 vv[0] = _x_velocity + _x_acceleration * dt;
1809 vv[1] = _y_velocity + _y_acceleration * dt;
1810 vv[2] = _z_velocity + _z_acceleration * dt;
1811
1812 xc[3] = _agf0 + _agf1 * dt;
1813
1814 xc[4] = _agf1;
1815 xc[5] = 0.0;
1816
1817 return success;
1818}
1819
1820// Health status of SBAS Ephemeris (virtual)
1821////////////////////////////////////////////////////////////////////////////
1822unsigned int t_ephSBAS::isUnhealthy() const {
1823
1824 // Bit 5
1825 bool URAindexIs15 = (int(_health) & (1<<5));
1826 if (URAindexIs15) {
1827 // in this case it is recommended
1828 // to set the bits 0,1,2,3 to 1 (MT17health = 15)
1829 return 1;
1830 }
1831
1832 // Bit 0-3
1833 int MT17health = (int(_health)) & (0x0f);
1834 if (MT17health) {
1835 return 1;
1836 }
1837
1838 // Bit 4
1839 // bool MT17HealthIsUnavailable = (int(_health) & (1<<4));
1840 // is not used because the MT17health bits can be independently set if URA index is 15
1841
1842 return 0;
1843}
1844
1845
1846// RINEX Format String
1847//////////////////////////////////////////////////////////////////////////////
1848QString t_ephSBAS::toString(double version) const {
1849
1850 QString navStr = navTypeString(_navType, _prn, version);
1851 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
1852
1853 QTextStream out(&rnxStr);
1854
1855 out << QString("%1%2%3\n")
1856 .arg(_agf0, 19, 'e', 12)
1857 .arg(_agf1, 19, 'e', 12)
1858 .arg(_TOT, 19, 'e', 12);
1859
1860 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1861 // =====================
1862 // BROADCAST ORBIT - 1
1863 // =====================
1864 out << QString(fmt)
1865 .arg(1.e-3*_x_pos, 19, 'e', 12)
1866 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1867 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
1868 .arg(_health, 19, 'e', 12);
1869 // =====================
1870 // BROADCAST ORBIT - 2
1871 // =====================
1872 out << QString(fmt)
1873 .arg(1.e-3*_y_pos, 19, 'e', 12)
1874 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1875 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
1876 .arg(_ura, 19, 'e', 12);
1877 // =====================
1878 // BROADCAST ORBIT - 3
1879 // =====================
1880 out << QString(fmt)
1881 .arg(1.e-3*_z_pos, 19, 'e', 12)
1882 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1883 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
1884 .arg(double(_IODN), 19, 'e', 12);
1885
1886 return rnxStr;
1887}
1888
1889// Constructor
1890//////////////////////////////////////////////////////////////////////////////
1891t_ephBDS::t_ephBDS(double rnxVersion, const QStringList& lines) {
1892
1893 int nLines = 8;
1894
1895 if (navType() == t_eph::CNV1 ||
1896 navType() == t_eph::CNV2) {
1897 nLines += 2;
1898 }
1899 if (navType() == t_eph::CNV3) {
1900 nLines += 1;
1901 }
1902
1903 if (lines.size() != nLines) {
1904 _checkState = bad;
1905 return;
1906 }
1907
1908 // RINEX Format
1909 // ------------
1910 int fieldLen = 19;
1911
1912 int pos[4];
1913 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1914 pos[1] = pos[0] + fieldLen;
1915 pos[2] = pos[1] + fieldLen;
1916 pos[3] = pos[2] + fieldLen;
1917
1918 // Read eight lines
1919 // ----------------
1920 for (int iLine = 0; iLine < nLines; iLine++) {
1921 QString line = lines[iLine];
1922
1923 if ( iLine == 0 ) {
1924 QTextStream in(line.left(pos[1]).toLatin1());
1925
1926 int year, month, day, hour, min;
1927 double sec;
1928
1929 QString prnStr, n;
1930 in >> prnStr;
1931 if (prnStr.size() == 1 && prnStr[0] == 'C') {
1932 in >> n;
1933 prnStr.append(n);
1934 }
1935 in >> year >> month >> day >> hour >> min >> sec;
1936 if (prnStr.at(0) == 'C') {
1937 _prn.set('C', prnStr.mid(1).toInt());
1938 }
1939 else {
1940 _prn.set('C', prnStr.toInt());
1941 }
1942
1943 if (year < 80) {
1944 year += 2000;
1945 }
1946 else if (year < 100) {
1947 year += 1900;
1948 }
1949
1950 _TOC.setBDS(year, month, day, hour, min, sec);
1951
1952 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1953 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1954 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1955 _checkState = bad;
1956 return;
1957 }
1958 }
1959 // =====================
1960 // BROADCAST ORBIT - 1
1961 // =====================
1962 else if ( iLine == 1 ) {
1963 double aode;
1964 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1965 readDbl(line, pos[1], fieldLen, _Crs ) ||
1966 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1967 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1968 _checkState = bad;
1969 return;
1970 }
1971 _AODE = int(aode);
1972 }
1973 // =====================
1974 // BROADCAST ORBIT - 2
1975 // =====================
1976 else if ( iLine == 2 ) {
1977 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1978 readDbl(line, pos[1], fieldLen, _e ) ||
1979 readDbl(line, pos[2], fieldLen, _Cus ) ||
1980 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1981 _checkState = bad;
1982 return;
1983 }
1984 }
1985 // =====================
1986 // BROADCAST ORBIT - 3
1987 // =====================
1988 else if ( iLine == 3 ) {
1989 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
1990 readDbl(line, pos[1], fieldLen, _Cic ) ||
1991 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1992 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1993 _checkState = bad;
1994 return;
1995 }
1996 }
1997 // =====================
1998 // BROADCAST ORBIT - 4
1999 // =====================
2000 else if ( iLine == 4 ) {
2001 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
2002 readDbl(line, pos[1], fieldLen, _Crc ) ||
2003 readDbl(line, pos[2], fieldLen, _omega ) ||
2004 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
2005 _checkState = bad;
2006 return;
2007 }
2008 }
2009 // =====================
2010 // BROADCAST ORBIT - 5
2011 // =====================
2012 else if ( iLine == 5 ) {
2013
2014 if (navType() == t_eph::CNV1 ||
2015 navType() == t_eph::CNV2 ||
2016 navType() == t_eph::CNV3 ) {
2017 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
2018 readDbl(line, pos[1], fieldLen, _Delta_n_dot) ||
2019 readDbl(line, pos[2], fieldLen, _satType ) ||
2020 readDbl(line, pos[3], fieldLen, _top ) ) {
2021 _checkState = bad;
2022 return;
2023 }
2024 }
2025 else { // D1, D2, undefined
2026 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
2027 readDbl(line, pos[2], fieldLen, _BDTweek)) {
2028 _checkState = bad;
2029 return;
2030 }
2031 }
2032 }
2033 // =====================
2034 // BROADCAST ORBIT - 6
2035 // =====================
2036 else if ( iLine == 6 ) {
2037 if (navType() == t_eph::CNV1 ||
2038 navType() == t_eph::CNV2 ||
2039 navType() == t_eph::CNV3 ) {
2040 if ( readDbl(line, pos[0], fieldLen, _SISAI_oe ) ||
2041 readDbl(line, pos[1], fieldLen, _SISAI_ocb ) ||
2042 readDbl(line, pos[2], fieldLen, _SISAI_oc1 ) ||
2043 readDbl(line, pos[3], fieldLen, _SISAI_oc2 ) ) {
2044 _checkState = bad;
2045 return;
2046 }
2047 }
2048 else { // D1, D2, undefined
2049 double SatH1;
2050 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
2051 readDbl(line, pos[1], fieldLen, SatH1) ||
2052 readDbl(line, pos[2], fieldLen, _TGD1) ||
2053 readDbl(line, pos[3], fieldLen, _TGD2) ) {
2054 _checkState = bad;
2055 return;
2056 }
2057 _SatH1 = int(SatH1);
2058 }
2059 }
2060 // =====================
2061 // BROADCAST ORBIT - 7
2062 // =====================
2063 else if ( iLine == 7 ) {
2064 if (navType() == t_eph::CNV1) {
2065 if ( readDbl(line, pos[0], fieldLen, _ISC_B1Cd) ||
2066 readDbl(line, pos[2], fieldLen, _TGD_B1Cp) ||
2067 readDbl(line, pos[3], fieldLen, _TGD_B2ap) ) {
2068 _checkState = bad;
2069 return;
2070 }
2071 }
2072 else if (navType() == t_eph::CNV2) {
2073 if ( readDbl(line, pos[1], fieldLen, _ISC_B2ad) ||
2074 readDbl(line, pos[2], fieldLen, _TGD_B1Cp) ||
2075 readDbl(line, pos[3], fieldLen, _TGD_B2ap) ) {
2076 _checkState = bad;
2077 return;
2078 }
2079 }
2080 else if (navType() == t_eph::CNV3) {
2081 double health;
2082 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2083 readDbl(line, pos[1], fieldLen, health ) ||
2084 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B2b) ||
2085 readDbl(line, pos[3], fieldLen, _TGD_B2bI) ) {
2086 _checkState = bad;
2087 return;
2088 }
2089 _health = int(health);
2090 }
2091 else { // D1, D2 or undefined
2092 double aodc;
2093 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
2094 readDbl(line, pos[1], fieldLen, aodc) ) {
2095 _checkState = bad;
2096 return;
2097 }
2098 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
2099 _TOT = _TOEsec;
2100 }
2101 _AODC = int(aodc);
2102 }
2103 }
2104 // =====================
2105 // BROADCAST ORBIT - 8
2106 // =====================
2107 else if ( iLine == 8 ) {
2108 double health;
2109 if (navType() == t_eph::CNV1) {
2110 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2111 readDbl(line, pos[1], fieldLen, health ) ||
2112 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B1C) ||
2113 readDbl(line, pos[3], fieldLen, _IODC) ) {
2114 _checkState = bad;
2115 return;
2116 }
2117 _health = int(health);
2118 }
2119 else if (navType() == t_eph::CNV2) {
2120 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2121 readDbl(line, pos[1], fieldLen, health ) ||
2122 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B2aB1C) ||
2123 readDbl(line, pos[3], fieldLen, _IODC) ) {
2124 _checkState = bad;
2125 return;
2126 }
2127 _health = int(health);
2128 }
2129 else if (navType() == t_eph::CNV3) {
2130 if ( readDbl(line, pos[0], fieldLen, _TOT)) {
2131 _checkState = bad;
2132 return;
2133 }
2134 }
2135
2136 }
2137 // =====================
2138 // BROADCAST ORBIT - 9
2139 // =====================
2140 else if ( iLine == 9 ) {
2141
2142 if (navType() == t_eph::CNV1 ||
2143 navType() == t_eph::CNV2) {
2144 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
2145 readDbl(line, pos[3], fieldLen, _IODE) ) {
2146 _checkState = bad;
2147 return;
2148 }
2149 }
2150
2151 }
2152 }
2153
2154 _TOE.setBDS(int(_BDTweek), _TOEsec);
2155 // remark: actually should be computed from second_tot
2156 // but it seems to be unreliable in RINEX files
2157 //_TOT = _TOC.bdssec();
2158}
2159
2160// IOD of BDS Ephemeris (virtual)
2161////////////////////////////////////////////////////////////////////////////
2162unsigned int t_ephBDS::IOD() const {
2163 return (int(_TOC.gpssec())/720) % 240; //return (int(_TOEsec)/720) % 240;
2164}
2165
2166// Compute BDS Satellite Position (virtual)
2167//////////////////////////////////////////////////////////////////////////////
2168t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
2169
2170 static const double gmBDS = 398.6004418e12;
2171 static const double omegaBDS = 7292115.0000e-11;
2172
2173 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
2174 vv[0] = vv[1] = vv[2] = 0.0;
2175
2176 bncTime tt(GPSweek, GPSweeks);
2177
2178 if (_sqrt_A == 0) {
2179 return failure;
2180 }
2181 double a0 = _sqrt_A * _sqrt_A;
2182
2183 double n0 = sqrt(gmBDS/(a0*a0*a0));
2184 double tk = tt - _TOE;
2185 double n = n0 + _Delta_n;
2186 double M = _M0 + n*tk;
2187 double E = M;
2188 double E_last;
2189 int nLoop = 0;
2190 do {
2191 E_last = E;
2192 E = M + _e*sin(E);
2193
2194 if (++nLoop == 100) {
2195 return failure;
2196 }
2197 } while ( fabs(E-E_last)*a0 > 0.001 );
2198
2199 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
2200 double u0 = v + _omega;
2201 double sin2u0 = sin(2*u0);
2202 double cos2u0 = cos(2*u0);
2203 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
2204 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
2205 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
2206 double xp = r*cos(u);
2207 double yp = r*sin(u);
2208 double toesec = (_TOE.gpssec() - 14.0);
2209 double sinom = 0;
2210 double cosom = 0;
2211 double sini = 0;
2212 double cosi = 0;
2213
2214 // Velocity
2215 // --------
2216 double tanv2 = tan(v/2);
2217 double dEdM = 1 / (1 - _e*cos(E));
2218 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
2219 / (1 + tanv2*tanv2) * dEdM * n;
2220 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
2221 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
2222 double dotr = a0 * _e*sin(E) * dEdM * n
2223 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
2224
2225 double dotx = dotr*cos(u) - r*sin(u)*dotu;
2226 double doty = dotr*sin(u) + r*cos(u)*dotu;
2227
2228 const double iMaxGEO = 10.0 / 180.0 * M_PI;
2229
2230 // MEO/IGSO satellite
2231 // ------------------
2232 if (_i0 > iMaxGEO) {
2233 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
2234
2235 sinom = sin(OM);
2236 cosom = cos(OM);
2237 sini = sin(i);
2238 cosi = cos(i);
2239
2240 xc[0] = xp*cosom - yp*cosi*sinom;
2241 xc[1] = xp*sinom + yp*cosi*cosom;
2242 xc[2] = yp*sini;
2243
2244 // Velocity
2245 // --------
2246
2247 double dotom = _OMEGADOT - t_CST::omega;
2248
2249 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
2250 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
2251 + yp*sini*sinom*doti; // dX / di
2252
2253 vv[1] = sinom *dotx + cosi*cosom *doty
2254 + xp*cosom*dotom - yp*cosi*sinom*dotom
2255 - yp*sini*cosom*doti;
2256
2257 vv[2] = sini *doty + yp*cosi *doti;
2258
2259 }
2260
2261 // GEO satellite
2262 // -------------
2263 else {
2264 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
2265 double ll = omegaBDS*tk;
2266
2267 sinom = sin(OM);
2268 cosom = cos(OM);
2269 sini = sin(i);
2270 cosi = cos(i);
2271
2272 double xx = xp*cosom - yp*cosi*sinom;
2273 double yy = xp*sinom + yp*cosi*cosom;
2274 double zz = yp*sini;
2275
2276 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
2277 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
2278
2279 ColumnVector X1(3); X1 << xx << yy << zz;
2280 ColumnVector X2 = RZ*RX*X1;
2281
2282 xc[0] = X2(1);
2283 xc[1] = X2(2);
2284 xc[2] = X2(3);
2285
2286 double dotom = _OMEGADOT;
2287
2288 double vx = cosom *dotx - cosi*sinom *doty
2289 - xp*sinom*dotom - yp*cosi*cosom*dotom
2290 + yp*sini*sinom*doti;
2291
2292 double vy = sinom *dotx + cosi*cosom *doty
2293 + xp*cosom*dotom - yp*cosi*sinom*dotom
2294 - yp*sini*cosom*doti;
2295
2296 double vz = sini *doty + yp*cosi *doti;
2297
2298 ColumnVector V(3); V << vx << vy << vz;
2299
2300 Matrix RdotZ(3,3);
2301 double C = cos(ll);
2302 double S = sin(ll);
2303 Matrix UU(3,3);
2304 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
2305 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
2306 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
2307 RdotZ = omegaBDS * UU;
2308
2309 ColumnVector VV(3);
2310 VV = RZ*RX*V + RdotZ*RX*X1;
2311
2312 vv[0] = VV(1);
2313 vv[1] = VV(2);
2314 vv[2] = VV(3);
2315 }
2316
2317 double tc = tt - _TOC;
2318 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
2319
2320// dotC = _clock_drift + _clock_driftrate*tc
2321// - 4.442807309e-10*_e * sqrt(a0) * cos(E) * dEdM * n;
2322
2323 // Relativistic Correction
2324 // -----------------------
2325 xc[3] -= 4.442807309e-10 * _e * sqrt(a0) *sin(E);
2326
2327 xc[4] = _clock_drift + _clock_driftrate*tc;
2328 xc[5] = _clock_driftrate;
2329
2330 return success;
2331}
2332
2333
2334// Health status of SBAS Ephemeris (virtual)
2335////////////////////////////////////////////////////////////////////////////
2336unsigned int t_ephBDS::isUnhealthy() const {
2337
2338 if (navType() == t_eph::CNV1 ||
2339 navType() == t_eph::CNV2 ||
2340 navType() == t_eph::CNV3) {
2341 return static_cast<unsigned int>(_health);
2342 }
2343
2344 return static_cast<unsigned int>(_SatH1);
2345
2346}
2347
2348
2349// RINEX Format String
2350//////////////////////////////////////////////////////////////////////////////
2351QString t_ephBDS::toString(double version) const {
2352
2353 QString navStr = navTypeString(_navType, _prn, version);
2354 QString rnxStr = navStr + rinexDateStr(_TOC-14.0, _prn, version);
2355
2356 QTextStream out(&rnxStr);
2357
2358 out << QString("%1%2%3\n")
2359 .arg(_clock_bias, 19, 'e', 12)
2360 .arg(_clock_drift, 19, 'e', 12)
2361 .arg(_clock_driftrate, 19, 'e', 12);
2362
2363 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
2364 // =====================
2365 // BROADCAST ORBIT - 1
2366 // =====================
2367 out << QString(fmt)
2368 .arg(double(_AODE), 19, 'e', 12)
2369 .arg(_Crs, 19, 'e', 12)
2370 .arg(_Delta_n, 19, 'e', 12)
2371 .arg(_M0, 19, 'e', 12);
2372 // =====================
2373 // BROADCAST ORBIT - 2
2374 // =====================
2375 out << QString(fmt)
2376 .arg(_Cuc, 19, 'e', 12)
2377 .arg(_e, 19, 'e', 12)
2378 .arg(_Cus, 19, 'e', 12)
2379 .arg(_sqrt_A, 19, 'e', 12);
2380 // =====================
2381 // BROADCAST ORBIT - 3
2382 // =====================
2383 out << QString(fmt)
2384 .arg(_TOEsec, 19, 'e', 12)
2385 .arg(_Cic, 19, 'e', 12)
2386 .arg(_OMEGA0, 19, 'e', 12)
2387 .arg(_Cis, 19, 'e', 12);
2388 // =====================
2389 // BROADCAST ORBIT - 4
2390 // =====================
2391 out << QString(fmt)
2392 .arg(_i0, 19, 'e', 12)
2393 .arg(_Crc, 19, 'e', 12)
2394 .arg(_omega, 19, 'e', 12)
2395 .arg(_OMEGADOT, 19, 'e', 12);
2396 // =====================
2397 // BROADCAST ORBIT - 5
2398 // =====================
2399 if (navType() == t_eph::CNV1 ||
2400 navType() == t_eph::CNV2 ||
2401 navType() == t_eph::CNV3 ) {
2402 out << QString(fmt)
2403 .arg(_IDOT, 19, 'e', 12)
2404 .arg(_Delta_n_dot, 19, 'e', 12)
2405 .arg(_satType, 19, 'e', 12)
2406 .arg(_top, 19, 'e', 12);
2407 }
2408 else { // D1, D2, undefined
2409 out << QString(fmt)
2410 .arg(_IDOT, 19, 'e', 12)
2411 .arg("", 19, QChar(' '))
2412 .arg(_BDTweek, 19, 'e', 12)
2413 .arg("", 19, QChar(' '));
2414 }
2415 // =====================
2416 // BROADCAST ORBIT - 6
2417 // =====================
2418 if (navType() == t_eph::CNV1 ||
2419 navType() == t_eph::CNV2 ||
2420 navType() == t_eph::CNV3 ) {
2421 out << QString(fmt)
2422 .arg(_SISAI_oe, 19, 'e', 12)
2423 .arg(_SISAI_ocb, 19, 'e', 12)
2424 .arg(_SISAI_oc1, 19, 'e', 12)
2425 .arg(_SISAI_oc2, 19, 'e', 12);
2426 }
2427 else { // D1, D2, undefined
2428 out << QString(fmt)
2429 .arg(_URA, 19, 'e', 12)
2430 .arg(double(_SatH1), 19, 'e', 12)
2431 .arg(_TGD1, 19, 'e', 12)
2432 .arg(_TGD2, 19, 'e', 12);
2433 }
2434 // =====================
2435 // BROADCAST ORBIT - 7
2436 // =====================
2437 if (navType() == t_eph::CNV1) {
2438 out << QString(fmt)
2439 .arg(_ISC_B1Cd, 19, 'e', 12)
2440 .arg("", 19, QChar(' '))
2441 .arg(_TGD_B1Cp, 19, 'e', 12)
2442 .arg(_TGD_B2ap, 19, 'e', 12);
2443 }
2444 else if (navType() == t_eph::CNV2) {
2445 out << QString(fmt)
2446 .arg("", 19, QChar(' '))
2447 .arg(_ISC_B2ad, 19, 'e', 12)
2448 .arg(_TGD_B1Cp, 19, 'e', 12)
2449 .arg(_TGD_B2ap, 19, 'e', 12);
2450 }
2451 else if (navType() == t_eph::CNV3) {
2452 out << QString(fmt)
2453 .arg(_SISMAI, 19, 'e', 12)
2454 .arg(double(_health), 19, 'e', 12)
2455 .arg(_INTEGRITYF_B2b, 19, 'e', 12)
2456 .arg(_TGD_B2bI, 19, 'e', 12);
2457 }
2458 else { // D1, D2, undefined
2459 double tots = 0.0;
2460 if (_receptDateTime.isValid()) {// RTCM stream input
2461 tots = _TOE.bdssec();
2462 }
2463 else { // RINEX input
2464 tots = _TOT;
2465 }
2466 out << QString(fmt)
2467 .arg(tots, 19, 'e', 12)
2468 .arg(double(_AODC), 19, 'e', 12)
2469 .arg("", 19, QChar(' '))
2470 .arg("", 19, QChar(' '));
2471 }
2472
2473 // =====================
2474 // BROADCAST ORBIT - 8
2475 // =====================
2476 if (navType() == t_eph::CNV1) {
2477 out << QString(fmt)
2478 .arg(_SISMAI, 19, 'e', 12)
2479 .arg(double(_health), 19, 'e', 12)
2480 .arg(_INTEGRITYF_B1C, 19, 'e', 12)
2481 .arg(_IODC, 19, 'e', 12);
2482 }
2483 else if (navType() == t_eph::CNV2) {
2484 out << QString(fmt)
2485 .arg(_SISMAI, 19, 'e', 12)
2486 .arg(double(_health), 19, 'e', 12)
2487 .arg(_INTEGRITYF_B2aB1C, 19, 'e', 12)
2488 .arg(_IODC, 19, 'e', 12);
2489 }
2490 else if (navType() == t_eph::CNV3) {
2491 out << QString(fmt)
2492 .arg(_TOT, 19, 'e', 12)
2493 .arg("", 19, QChar(' '))
2494 .arg("", 19, QChar(' '))
2495 .arg("", 19, QChar(' '));
2496 }
2497
2498 // =====================
2499 // BROADCAST ORBIT - 9
2500 // =====================
2501 if (navType() == t_eph::CNV1 ||
2502 navType() == t_eph::CNV2) {
2503 out << QString(fmt)
2504 .arg(_TOT, 19, 'e', 12)
2505 .arg("", 19, QChar(' '))
2506 .arg("", 19, QChar(' '))
2507 .arg(_IODE, 19, 'e', 12);
2508 }
2509
2510
2511 return rnxStr;
2512}
Note: See TracBrowser for help on using the repository browser.