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

Last change on this file since 9837 was 9789, checked in by stuerze, 22 months ago

some more changes to consider RINEX Version 4 nav file (EPH key only)

File size: 70.4 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 _flags_unknown = false;
833 }
834 else {
835 _M_delta_tau = 0.9999e9; // unknown
836 _M_FT = 1.5e1; // unknown
837 _flags_unknown = true;
838 }
839
840 if (lines.size() != nLines) {
841 _checkState = bad;
842 return;
843 }
844
845 // RINEX Format
846 // ------------
847 int fieldLen = 19;
848 double statusflags = 0.0;
849 double healthflags = 0.0;
850
851 int pos[4];
852 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
853 pos[1] = pos[0] + fieldLen;
854 pos[2] = pos[1] + fieldLen;
855 pos[3] = pos[2] + fieldLen;
856
857 // Read four lines
858 // ---------------
859 for (int iLine = 0; iLine < nLines; iLine++) {
860 QString line = lines[iLine];
861
862 if ( iLine == 0 ) {
863 QTextStream in(line.left(pos[1]).toLatin1());
864
865 int year, month, day, hour, min;
866 double sec;
867
868 QString prnStr, n;
869 in >> prnStr;
870 if (prnStr.size() == 1 && prnStr[0] == 'R') {
871 in >> n;
872 prnStr.append(n);
873 }
874 in >> year >> month >> day >> hour >> min >> sec;
875 if (prnStr.at(0) == 'R') {
876 _prn.set('R', prnStr.mid(1).toInt());
877 }
878 else {
879 _prn.set('R', prnStr.toInt());
880 }
881
882 if (year < 80) {
883 year += 2000;
884 }
885 else if (year < 100) {
886 year += 1900;
887 }
888
889 _gps_utc = gnumleap(year, month, day);
890
891 _TOC.set(year, month, day, hour, min, sec);
892 _TOC = _TOC + _gps_utc;
893 int nd = int((_TOC.gpssec())) / (24.0*60.0*60.0);
894 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
895 readDbl(line, pos[2], fieldLen, _gamma) ||
896 readDbl(line, pos[3], fieldLen, _tki ) ) {
897 _checkState = bad;
898 return;
899 }
900 _tki -= nd * 86400.0;
901 _tau = -_tau;
902 }
903 // =====================
904 // BROADCAST ORBIT - 1
905 // =====================
906 else if ( iLine == 1 ) {
907 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
908 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
909 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
910 readDbl(line, pos[3], fieldLen, _health ) ) {
911 _checkState = bad;
912 return;
913 }
914 }
915 // =====================
916 // BROADCAST ORBIT - 2
917 // =====================
918 else if ( iLine == 2 ) {
919 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
920 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
921 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
922 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
923 _checkState = bad;
924 return;
925 }
926 }
927 // =====================
928 // BROADCAST ORBIT - 3
929 // =====================
930 else if ( iLine == 3 ) {
931 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
932 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
933 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
934 readDbl(line, pos[3], fieldLen, _E ) ) {
935 _checkState = bad;
936 return;
937 }
938 }
939 // =====================
940 // BROADCAST ORBIT - 4
941 // =====================
942 else if ( iLine == 4 ) {
943 if ( readDbl(line, pos[0], fieldLen, statusflags ) ||
944 readDbl(line, pos[1], fieldLen, _M_delta_tau ) ||
945 readDbl(line, pos[2], fieldLen, _M_FT ) ||
946 readDbl(line, pos[3], fieldLen, healthflags ) ) {
947 _checkState = bad;
948 return;
949 }
950 else {
951 // status flags
952 // ============
953 // bit 0-1
954 _M_P = double(bitExtracted(statusflags, 2, 0));
955 // bit 2-3
956 _P1 = double(bitExtracted(statusflags, 2, 2));
957 // bit 4
958 _P2 = double(bitExtracted(statusflags, 1, 4));
959 // bit 5
960 _P3 = double(bitExtracted(statusflags, 1, 5));
961 // bit 6
962 _M_P4 = double(bitExtracted(statusflags, 1, 6));
963 // bit 7-8
964 _M_M = double(bitExtracted(statusflags, 2, 7));
965 /// GLO M/K exclusive flags/values only valid if flag M is set to '01'
966 if (!_M_M) {
967 _M_P4 = 0.0;
968 _M_P = 0.0;
969 }
970 // health flags
971 // ============
972 // bit 0 (is to be ignored, if bit 1 is zero)
973 _almanac_health = double(bitExtracted(healthflags, 1, 0));
974 // bit 1
975 _almanac_health_availablility_indicator = double(bitExtracted(healthflags, 1, 1));
976 // bit 2
977 _M_l3 = double(bitExtracted(healthflags, 1, 2));
978 }
979 }
980 }
981
982 // Initialize status vector
983 // ------------------------
984 _tt = _TOC;
985 _xv.ReSize(6); _xv = 0.0;
986 _xv(1) = _x_pos * 1.e3;
987 _xv(2) = _y_pos * 1.e3;
988 _xv(3) = _z_pos * 1.e3;
989 _xv(4) = _x_velocity * 1.e3;
990 _xv(5) = _y_velocity * 1.e3;
991 _xv(6) = _z_velocity * 1.e3;
992}
993
994// Compute Glonass Satellite Position (virtual)
995////////////////////////////////////////////////////////////////////////////
996t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
997
998 static const double nominalStep = 10.0;
999
1000 memset(xc, 0, 6*sizeof(double));
1001 memset(vv, 0, 3*sizeof(double));
1002
1003 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
1004
1005 if (fabs(dtPos) > 24 * 3600.0) {
1006 return failure;
1007 }
1008
1009 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
1010 double step = dtPos / nSteps;
1011
1012 double acc[3];
1013 acc[0] = _x_acceleration * 1.e3;
1014 acc[1] = _y_acceleration * 1.e3;
1015 acc[2] = _z_acceleration * 1.e3;
1016
1017 for (int ii = 1; ii <= nSteps; ii++) {
1018 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
1019 _tt = _tt + step;
1020 }
1021
1022 // Position and Velocity
1023 // ---------------------
1024 xc[0] = _xv(1);
1025 xc[1] = _xv(2);
1026 xc[2] = _xv(3);
1027
1028 vv[0] = _xv(4);
1029 vv[1] = _xv(5);
1030 vv[2] = _xv(6);
1031
1032 // Clock Correction
1033 // ----------------
1034 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
1035 xc[3] = -_tau + _gamma * dtClk;
1036
1037 xc[4] = _gamma;
1038 xc[5] = 0.0;
1039
1040 return success;
1041}
1042
1043// RINEX Format String
1044//////////////////////////////////////////////////////////////////////////////
1045QString t_ephGlo::toString(double version) const {
1046
1047 QString navStr = navTypeString(_navType, _prn, version);
1048 QString rnxStr = navStr + rinexDateStr(_TOC -_gps_utc, _prn, version);
1049 int nd = int((_TOC - _gps_utc).gpssec()) / (24.0*60.0*60.0);
1050 QTextStream out(&rnxStr);
1051
1052 out << QString("%1%2%3\n")
1053 .arg(-_tau, 19, 'e', 12)
1054 .arg(_gamma, 19, 'e', 12)
1055 .arg(_tki+nd*86400.0, 19, 'e', 12);
1056
1057 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1058 // =====================
1059 // BROADCAST ORBIT - 1
1060 // =====================
1061 out << QString(fmt)
1062 .arg(_x_pos, 19, 'e', 12)
1063 .arg(_x_velocity, 19, 'e', 12)
1064 .arg(_x_acceleration, 19, 'e', 12)
1065 .arg(_health, 19, 'e', 12);
1066 // =====================
1067 // BROADCAST ORBIT - 2
1068 // =====================
1069 out << QString(fmt)
1070 .arg(_y_pos, 19, 'e', 12)
1071 .arg(_y_velocity, 19, 'e', 12)
1072 .arg(_y_acceleration, 19, 'e', 12)
1073 .arg(_frequency_number, 19, 'e', 12);
1074 // =====================
1075 // BROADCAST ORBIT - 3
1076 // =====================
1077 out << QString(fmt)
1078 .arg(_z_pos, 19, 'e', 12)
1079 .arg(_z_velocity, 19, 'e', 12)
1080 .arg(_z_acceleration, 19, 'e', 12)
1081 .arg(_E, 19, 'e', 12);
1082 // =====================
1083 // BROADCAST ORBIT - 4
1084 // =====================
1085 if (version >= 3.05) {
1086 // unknown (RINEX version < 3.05)
1087 if (_flags_unknown) {
1088 out << QString(fmt)
1089 .arg("", 19, QChar(' ')) // statusflags blank if unknown
1090 .arg(_M_delta_tau, 19, 'e', 12)
1091 .arg(_M_FT, 19, 'e', 12)
1092 .arg("", 19, QChar(' ')); // healthflags blank if unknown
1093 }
1094 else {
1095 int statusflags = 0;
1096 // bit 7-8
1097 if (_M_M == 2.0) {
1098 statusflags |= (1<<7);
1099 }
1100 // bit 6
1101 if (_M_P4) {
1102 statusflags |= (1<<6);
1103 }
1104 // bit 5
1105 if (_P3) {
1106 statusflags |= (1<<5);
1107 }
1108 // bit 4
1109 if (_P2) {
1110 statusflags |= (1<<4);
1111 }
1112 // bit 2-3
1113 if (_P1 == 2.0) {
1114 statusflags |= (1<<2);
1115 }
1116 else if (_P1 == 1.0) {
1117 statusflags |= (1<<3);
1118 }
1119 else if (_P1 == 3.0) {
1120 statusflags |= (1<<2);
1121 statusflags |= (1<<3);
1122 }
1123 // bit 0-1
1124 if (_M_P == 2.0) {
1125 statusflags |= (1<<0);
1126 }
1127 else if (_M_P == 1.0) {
1128 statusflags |= (1<<1);
1129 }
1130 else if (_M_P == 3.0) {
1131 statusflags |= (1<<0);
1132 statusflags |= (1<<1);
1133 }
1134 // health flags
1135 // ============
1136 int healthflags = 0;
1137 // bit 0 (is to be ignored, if bit 1 is zero)
1138 if (_almanac_health) {
1139 healthflags |= (1<<0);
1140 }
1141 // bit 1
1142 if (_almanac_health_availablility_indicator) {
1143 healthflags |= (1<<1);
1144 }
1145 // bit 2
1146 if (_M_l3) {
1147 healthflags |= (1<<2);
1148 }
1149 out << QString(fmt)
1150 .arg(double(statusflags), 19, 'e', 12)
1151 .arg(_M_delta_tau, 19, 'e', 12)
1152 .arg(_M_FT, 19, 'e', 12)
1153 .arg(double(healthflags), 19, 'e', 12);
1154 }
1155 }
1156
1157 return rnxStr;
1158}
1159
1160// Derivative of the state vector using a simple force model (static)
1161////////////////////////////////////////////////////////////////////////////
1162ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
1163 double* acc) {
1164
1165 // State vector components
1166 // -----------------------
1167 ColumnVector rr = xv.rows(1,3);
1168 ColumnVector vv = xv.rows(4,6);
1169
1170 // Acceleration
1171 // ------------
1172 static const double gmWGS = 398.60044e12;
1173 static const double AE = 6378136.0;
1174 static const double OMEGA = 7292115.e-11;
1175 static const double C20 = -1082.6257e-6;
1176
1177 double rho = rr.NormFrobenius();
1178 double t1 = -gmWGS/(rho*rho*rho);
1179 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
1180 double t3 = OMEGA * OMEGA;
1181 double t4 = 2.0 * OMEGA;
1182 double z2 = rr(3) * rr(3);
1183
1184 // Vector of derivatives
1185 // ---------------------
1186 ColumnVector va(6);
1187 va(1) = vv(1);
1188 va(2) = vv(2);
1189 va(3) = vv(3);
1190 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
1191 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
1192 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
1193
1194 return va;
1195}
1196
1197// IOD of Glonass Ephemeris (virtual)
1198////////////////////////////////////////////////////////////////////////////
1199unsigned int t_ephGlo::IOD() const {
1200 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
1201 return (unsigned long)tMoscow.daysec() / 900;
1202}
1203
1204// Health status of Glonass Ephemeris (virtual)
1205////////////////////////////////////////////////////////////////////////////
1206unsigned int t_ephGlo::isUnhealthy() const {
1207
1208 if (_almanac_health_availablility_indicator) {
1209 if ((_health == 0 && _almanac_health == 0) ||
1210 (_health == 1 && _almanac_health == 0) ||
1211 (_health == 1 && _almanac_health == 1)) {
1212 return 1;
1213 }
1214 }
1215 else if (!_almanac_health_availablility_indicator) {
1216 if (_health) {
1217 return 1;
1218 }
1219 }
1220 return 0; /* (_health == 0 && _almanac_health == 1) or (_health == 0) */
1221}
1222
1223// Constructor
1224//////////////////////////////////////////////////////////////////////////////
1225t_ephGal::t_ephGal(double rnxVersion, const QStringList& lines) {
1226 int year, month, day, hour, min;
1227 double sec;
1228 QString prnStr;
1229 const int nLines = 8;
1230 if (lines.size() != nLines) {
1231 _checkState = bad;
1232 return;
1233 }
1234
1235 // RINEX Format
1236 // ------------
1237 int fieldLen = 19;
1238 double SVhealth = 0.0;
1239 double datasource = 0.0;
1240
1241 int pos[4];
1242 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1243 pos[1] = pos[0] + fieldLen;
1244 pos[2] = pos[1] + fieldLen;
1245 pos[3] = pos[2] + fieldLen;
1246
1247 // Read eight lines
1248 // ----------------
1249 for (int iLine = 0; iLine < nLines; iLine++) {
1250 QString line = lines[iLine];
1251
1252 if ( iLine == 0 ) {
1253 QTextStream in(line.left(pos[1]).toLatin1());
1254 QString n;
1255 in >> prnStr;
1256 if (prnStr.size() == 1 && prnStr[0] == 'E') {
1257 in >> n;
1258 prnStr.append(n);
1259 }
1260 in >> year >> month >> day >> hour >> min >> sec;
1261 if (year < 80) {
1262 year += 2000;
1263 }
1264 else if (year < 100) {
1265 year += 1900;
1266 }
1267
1268 _TOC.set(year, month, day, hour, min, sec);
1269
1270 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1271 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1272 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1273 _checkState = bad;
1274 return;
1275 }
1276 }
1277 // =====================
1278 // BROADCAST ORBIT - 1
1279 // =====================
1280 else if ( iLine == 1 ) {
1281 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
1282 readDbl(line, pos[1], fieldLen, _Crs ) ||
1283 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1284 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1285 _checkState = bad;
1286 return;
1287 }
1288 }
1289 // =====================
1290 // BROADCAST ORBIT - 2
1291 // =====================
1292 else if ( iLine == 2 ) {
1293 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1294 readDbl(line, pos[1], fieldLen, _e ) ||
1295 readDbl(line, pos[2], fieldLen, _Cus ) ||
1296 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1297 _checkState = bad;
1298 return;
1299 }
1300 }
1301 // =====================
1302 // BROADCAST ORBIT - 3
1303 // =====================
1304 else if ( iLine == 3 ) {
1305 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
1306 readDbl(line, pos[1], fieldLen, _Cic ) ||
1307 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1308 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1309 _checkState = bad;
1310 return;
1311 }
1312 }
1313 // =====================
1314 // BROADCAST ORBIT - 4
1315 // =====================
1316 else if ( iLine == 4 ) {
1317 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1318 readDbl(line, pos[1], fieldLen, _Crc ) ||
1319 readDbl(line, pos[2], fieldLen, _omega ) ||
1320 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1321 _checkState = bad;
1322 return;
1323 }
1324 }
1325 // =====================
1326 // BROADCAST ORBIT - 5
1327 // =====================
1328 else if ( iLine == 5 ) {
1329 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
1330 readDbl(line, pos[1], fieldLen, datasource) ||
1331 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
1332 _checkState = bad;
1333 return;
1334 } else {
1335 if (int(datasource) & (1<<8)) {
1336 _fnav = true;
1337 _inav = false;
1338 } else if (int(datasource) & (1<<9)) {
1339 _fnav = false;
1340 _inav = true;
1341 }
1342 _TOEweek -= 1024.0;
1343 }
1344 }
1345 // =====================
1346 // BROADCAST ORBIT - 6
1347 // =====================
1348 else if ( iLine == 6 ) {
1349 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
1350 readDbl(line, pos[1], fieldLen, SVhealth) ||
1351 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
1352 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
1353 _checkState = bad;
1354 return;
1355 } else {
1356 // Bit 0
1357 _e1DataInValid = (int(SVhealth) & (1<<0));
1358 // Bit 1-2
1359 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
1360 // Bit 3
1361 _e5aDataInValid = (int(SVhealth) & (1<<3));
1362 // Bit 4-5
1363 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
1364 // Bit 6
1365 _e5bDataInValid = (int(SVhealth) & (1<<6));
1366 // Bit 7-8
1367 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
1368
1369 if (prnStr.at(0) == 'E') {
1370 _prn.set('E', prnStr.mid(1).toInt(), _inav ? 1 : 0);
1371 }
1372 }
1373 }
1374 // =====================
1375 // BROADCAST ORBIT - 7
1376 // =====================
1377 else if ( iLine == 7 ) {
1378 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
1379 _checkState = bad;
1380 return;
1381 }
1382 }
1383 }
1384}
1385
1386// Compute Galileo Satellite Position (virtual)
1387////////////////////////////////////////////////////////////////////////////
1388t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1389
1390 static const double omegaEarth = 7292115.1467e-11;
1391 static const double gmWGS = 398.6004418e12;
1392
1393 memset(xc, 0, 6*sizeof(double));
1394 memset(vv, 0, 3*sizeof(double));
1395
1396 double a0 = _sqrt_A * _sqrt_A;
1397 if (a0 == 0) {
1398 return failure;
1399 }
1400
1401 double n0 = sqrt(gmWGS/(a0*a0*a0));
1402
1403 bncTime tt(GPSweek, GPSweeks);
1404 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
1405
1406 double n = n0 + _Delta_n;
1407 double M = _M0 + n*tk;
1408 double E = M;
1409 double E_last;
1410 int nLoop = 0;
1411 do {
1412 E_last = E;
1413 E = M + _e*sin(E);
1414
1415 if (++nLoop == 100) {
1416 return failure;
1417 }
1418 } while ( fabs(E-E_last)*a0 > 0.001 );
1419 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
1420 double u0 = v + _omega;
1421 double sin2u0 = sin(2*u0);
1422 double cos2u0 = cos(2*u0);
1423 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1424 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1425 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1426 double xp = r*cos(u);
1427 double yp = r*sin(u);
1428 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
1429 omegaEarth*_TOEsec;
1430
1431 double sinom = sin(OM);
1432 double cosom = cos(OM);
1433 double sini = sin(i);
1434 double cosi = cos(i);
1435 xc[0] = xp*cosom - yp*cosi*sinom;
1436 xc[1] = xp*sinom + yp*cosi*cosom;
1437 xc[2] = yp*sini;
1438
1439 double tc = tt - _TOC;
1440 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1441
1442 // Velocity
1443 // --------
1444 double tanv2 = tan(v/2);
1445 double dEdM = 1 / (1 - _e*cos(E));
1446 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
1447 * dEdM * n;
1448 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1449 double dotom = _OMEGADOT - omegaEarth;
1450 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1451 double dotr = a0 * _e*sin(E) * dEdM * n
1452 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1453 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1454 double doty = dotr*sin(u) + r*cos(u)*dotu;
1455
1456 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1457 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1458 + yp*sini*sinom*doti; // dX / di
1459
1460 vv[1] = sinom *dotx + cosi*cosom *doty
1461 + xp*cosom*dotom - yp*cosi*sinom*dotom
1462 - yp*sini*cosom*doti;
1463
1464 vv[2] = sini *doty + yp*cosi *doti;
1465
1466 // Relativistic Correction
1467 // -----------------------
1468 xc[3] -= 4.442807309e-10 * _e * sqrt(a0) *sin(E);
1469
1470 xc[4] = _clock_drift + _clock_driftrate*tc;
1471 xc[5] = _clock_driftrate;
1472
1473 return success;
1474}
1475
1476// Health status of Galileo Ephemeris (virtual)
1477////////////////////////////////////////////////////////////////////////////
1478unsigned int t_ephGal::isUnhealthy() const {
1479 if (_E5aHS && _E5bHS && _E1_bHS) {
1480 return 1;
1481 }
1482 return 0;
1483}
1484
1485// RINEX Format String
1486//////////////////////////////////////////////////////////////////////////////
1487QString t_ephGal::toString(double version) const {
1488
1489 QString navStr = navTypeString(_navType, _prn, version);
1490 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
1491
1492 QTextStream out(&rnxStr);
1493
1494 out << QString("%1%2%3\n")
1495 .arg(_clock_bias, 19, 'e', 12)
1496 .arg(_clock_drift, 19, 'e', 12)
1497 .arg(_clock_driftrate, 19, 'e', 12);
1498
1499 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1500 // =====================
1501 // BROADCAST ORBIT - 1
1502 // =====================
1503 out << QString(fmt)
1504 .arg(_IODnav, 19, 'e', 12)
1505 .arg(_Crs, 19, 'e', 12)
1506 .arg(_Delta_n, 19, 'e', 12)
1507 .arg(_M0, 19, 'e', 12);
1508 // =====================
1509 // BROADCAST ORBIT - 2
1510 // =====================
1511 out << QString(fmt)
1512 .arg(_Cuc, 19, 'e', 12)
1513 .arg(_e, 19, 'e', 12)
1514 .arg(_Cus, 19, 'e', 12)
1515 .arg(_sqrt_A, 19, 'e', 12);
1516 // =====================
1517 // BROADCAST ORBIT - 3
1518 // =====================
1519 out << QString(fmt)
1520 .arg(_TOEsec, 19, 'e', 12)
1521 .arg(_Cic, 19, 'e', 12)
1522 .arg(_OMEGA0, 19, 'e', 12)
1523 .arg(_Cis, 19, 'e', 12);
1524 // =====================
1525 // BROADCAST ORBIT - 4
1526 // =====================
1527 out << QString(fmt)
1528 .arg(_i0, 19, 'e', 12)
1529 .arg(_Crc, 19, 'e', 12)
1530 .arg(_omega, 19, 'e', 12)
1531 .arg(_OMEGADOT, 19, 'e', 12);
1532 // =====================
1533 // BROADCAST ORBIT - 5
1534 // =====================
1535 int dataSource = 0;
1536 int SVhealth = 0;
1537 double BGD_1_5A = _BGD_1_5A;
1538 double BGD_1_5B = _BGD_1_5B;
1539 if (_fnav) {
1540 dataSource |= (1<<1);
1541 dataSource |= (1<<8);
1542 BGD_1_5B = 0.0;
1543 // SVhealth
1544 // Bit 3 : E5a DVS
1545 if (_e5aDataInValid) {
1546 SVhealth |= (1<<3);
1547 }
1548 // Bit 4-5: E5a HS
1549 if (_E5aHS == 1.0) {
1550 SVhealth |= (1<<4);
1551 }
1552 else if (_E5aHS == 2.0) {
1553 SVhealth |= (1<<5);
1554 }
1555 else if (_E5aHS == 3.0) {
1556 SVhealth |= (1<<4);
1557 SVhealth |= (1<<5);
1558 }
1559 }
1560 else if(_inav) {
1561 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1562 // and RNXv3.03 says both can be set if the navigation messages were merged
1563 dataSource |= (1<<0);
1564 dataSource |= (1<<2);
1565 dataSource |= (1<<9);
1566 // SVhealth
1567 // Bit 0 : E1-B DVS
1568 if (_e1DataInValid) {
1569 SVhealth |= (1<<0);
1570 }
1571 // Bit 1-2: E1-B HS
1572 if (_E1_bHS == 1.0) {
1573 SVhealth |= (1<<1);
1574 }
1575 else if (_E1_bHS == 2.0) {
1576 SVhealth |= (1<<2);
1577 }
1578 else if (_E1_bHS == 3.0) {
1579 SVhealth |= (1<<1);
1580 SVhealth |= (1<<2);
1581 }
1582 // Bit 3 : E5a DVS
1583 if (_e5aDataInValid) {
1584 SVhealth |= (1<<3);
1585 }
1586 // Bit 4-5: E5a HS
1587 if (_E5aHS == 1.0) {
1588 SVhealth |= (1<<4);
1589 }
1590 else if (_E5aHS == 2.0) {
1591 SVhealth |= (1<<5);
1592 }
1593 else if (_E5aHS == 3.0) {
1594 SVhealth |= (1<<4);
1595 SVhealth |= (1<<5);
1596 }
1597 // Bit 6 : E5b DVS
1598 if (_e5bDataInValid) {
1599 SVhealth |= (1<<6);
1600 }
1601 // Bit 7-8: E5b HS
1602 if (_E5bHS == 1.0) {
1603 SVhealth |= (1<<7);
1604 }
1605 else if (_E5bHS == 2.0) {
1606 SVhealth |= (1<<8);
1607 }
1608 else if (_E5bHS == 3.0) {
1609 SVhealth |= (1<<7);
1610 SVhealth |= (1<<8);
1611 }
1612 }
1613
1614 out << QString(fmt)
1615 .arg(_IDOT, 19, 'e', 12)
1616 .arg(double(dataSource), 19, 'e', 12)
1617 .arg(_TOEweek + 1024.0, 19, 'e', 12)
1618 .arg(0.0, 19, 'e', 12);
1619 // =====================
1620 // BROADCAST ORBIT - 6
1621 // =====================
1622 out << QString(fmt)
1623 .arg(_SISA, 19, 'e', 12)
1624 .arg(double(SVhealth), 19, 'e', 12)
1625 .arg(BGD_1_5A, 19, 'e', 12)
1626 .arg(BGD_1_5B, 19, 'e', 12);
1627 // =====================
1628 // BROADCAST ORBIT - 7
1629 // =====================
1630 double tot = _TOT;
1631 if (tot == 0.9999e9 && version < 3.0) {
1632 tot = 0.0;
1633 }
1634 out << QString(fmt)
1635 .arg(tot, 19, 'e', 12)
1636 .arg("", 19, QChar(' '))
1637 .arg("", 19, QChar(' '))
1638 .arg("", 19, QChar(' '));
1639
1640 return rnxStr;
1641}
1642
1643// Constructor
1644//////////////////////////////////////////////////////////////////////////////
1645t_ephSBAS::t_ephSBAS(double rnxVersion, const QStringList& lines) {
1646
1647 const int nLines = 4;
1648
1649 if (lines.size() != nLines) {
1650 _checkState = bad;
1651 return;
1652 }
1653
1654 // RINEX Format
1655 // ------------
1656 int fieldLen = 19;
1657
1658 int pos[4];
1659 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1660 pos[1] = pos[0] + fieldLen;
1661 pos[2] = pos[1] + fieldLen;
1662 pos[3] = pos[2] + fieldLen;
1663
1664 // Read four lines
1665 // ---------------
1666 for (int iLine = 0; iLine < nLines; iLine++) {
1667 QString line = lines[iLine];
1668
1669 if ( iLine == 0 ) {
1670 QTextStream in(line.left(pos[1]).toLatin1());
1671
1672 int year, month, day, hour, min;
1673 double sec;
1674
1675 QString prnStr, n;
1676 in >> prnStr;
1677 if (prnStr.size() == 1 && prnStr[0] == 'S') {
1678 in >> n;
1679 prnStr.append(n);
1680 }
1681 in >> year >> month >> day >> hour >> min >> sec;
1682 if (prnStr.at(0) == 'S') {
1683 _prn.set('S', prnStr.mid(1).toInt());
1684 }
1685 else {
1686 _prn.set('S', prnStr.toInt());
1687 }
1688
1689 if (year < 80) {
1690 year += 2000;
1691 }
1692 else if (year < 100) {
1693 year += 1900;
1694 }
1695
1696 _TOC.set(year, month, day, hour, min, sec);
1697
1698 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1699 readDbl(line, pos[2], fieldLen, _agf1 ) ||
1700 readDbl(line, pos[3], fieldLen, _TOT ) ) {
1701 _checkState = bad;
1702 return;
1703 }
1704 }
1705 // =====================
1706 // BROADCAST ORBIT - 1
1707 // =====================
1708 else if ( iLine == 1 ) {
1709 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1710 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1711 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1712 readDbl(line, pos[3], fieldLen, _health ) ) {
1713 _checkState = bad;
1714 return;
1715 }
1716 }
1717 // =====================
1718 // BROADCAST ORBIT - 2
1719 // =====================
1720 else if ( iLine == 2 ) {
1721 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1722 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1723 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1724 readDbl(line, pos[3], fieldLen, _ura ) ) {
1725 _checkState = bad;
1726 return;
1727 }
1728 }
1729 // =====================
1730 // BROADCAST ORBIT - 3
1731 // =====================
1732 else if ( iLine == 3 ) {
1733 double iodn;
1734 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1735 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1736 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
1737 readDbl(line, pos[3], fieldLen, iodn ) ) {
1738 _checkState = bad;
1739 return;
1740 } else {
1741 _IODN = int(iodn);
1742 }
1743 }
1744 }
1745
1746 _x_pos *= 1.e3;
1747 _y_pos *= 1.e3;
1748 _z_pos *= 1.e3;
1749 _x_velocity *= 1.e3;
1750 _y_velocity *= 1.e3;
1751 _z_velocity *= 1.e3;
1752 _x_acceleration *= 1.e3;
1753 _y_acceleration *= 1.e3;
1754 _z_acceleration *= 1.e3;
1755}
1756
1757// IOD of SBAS Ephemeris (virtual)
1758////////////////////////////////////////////////////////////////////////////
1759
1760unsigned int t_ephSBAS::IOD() const {
1761 unsigned char buffer[80];
1762 int size = 0;
1763 int numbits = 0;
1764 long long bitbuffer = 0;
1765 unsigned char *startbuffer = buffer;
1766
1767 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1768 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1769 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1770 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1771 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1772 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1773 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1774 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1775 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1776 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1777 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1778 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1779
1780 return CRC24(size, startbuffer);
1781}
1782
1783// Compute SBAS Satellite Position (virtual)
1784////////////////////////////////////////////////////////////////////////////
1785t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1786
1787 bncTime tt(GPSweek, GPSweeks);
1788 double dt = tt - _TOC;
1789
1790 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1791 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1792 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
1793
1794 vv[0] = _x_velocity + _x_acceleration * dt;
1795 vv[1] = _y_velocity + _y_acceleration * dt;
1796 vv[2] = _z_velocity + _z_acceleration * dt;
1797
1798 xc[3] = _agf0 + _agf1 * dt;
1799
1800 xc[4] = _agf1;
1801 xc[5] = 0.0;
1802
1803 return success;
1804}
1805
1806// Health status of SBAS Ephemeris (virtual)
1807////////////////////////////////////////////////////////////////////////////
1808unsigned int t_ephSBAS::isUnhealthy() const {
1809
1810 // Bit 5
1811 bool URAindexIs15 = (int(_health) & (1<<5));
1812 if (URAindexIs15) {
1813 // in this case it is recommended
1814 // to set the bits 0,1,2,3 to 1 (MT17health = 15)
1815 return 1;
1816 }
1817
1818 // Bit 0-3
1819 int MT17health = (int(_health)) & (0x0f);
1820 if (MT17health) {
1821 return 1;
1822 }
1823
1824 // Bit 4
1825 // bool MT17HealthIsUnavailable = (int(_health) & (1<<4));
1826 // is not used because the MT17health bits can be independently set if URA index is 15
1827
1828 return 0;
1829}
1830
1831
1832// RINEX Format String
1833//////////////////////////////////////////////////////////////////////////////
1834QString t_ephSBAS::toString(double version) const {
1835
1836 QString navStr = navTypeString(_navType, _prn, version);
1837 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
1838
1839 QTextStream out(&rnxStr);
1840
1841 out << QString("%1%2%3\n")
1842 .arg(_agf0, 19, 'e', 12)
1843 .arg(_agf1, 19, 'e', 12)
1844 .arg(_TOT, 19, 'e', 12);
1845
1846 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1847 // =====================
1848 // BROADCAST ORBIT - 1
1849 // =====================
1850 out << QString(fmt)
1851 .arg(1.e-3*_x_pos, 19, 'e', 12)
1852 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1853 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
1854 .arg(_health, 19, 'e', 12);
1855 // =====================
1856 // BROADCAST ORBIT - 2
1857 // =====================
1858 out << QString(fmt)
1859 .arg(1.e-3*_y_pos, 19, 'e', 12)
1860 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1861 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
1862 .arg(_ura, 19, 'e', 12);
1863 // =====================
1864 // BROADCAST ORBIT - 3
1865 // =====================
1866 out << QString(fmt)
1867 .arg(1.e-3*_z_pos, 19, 'e', 12)
1868 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1869 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
1870 .arg(double(_IODN), 19, 'e', 12);
1871
1872 return rnxStr;
1873}
1874
1875// Constructor
1876//////////////////////////////////////////////////////////////////////////////
1877t_ephBDS::t_ephBDS(double rnxVersion, const QStringList& lines) {
1878
1879 int nLines = 8;
1880
1881 if (navType() == t_eph::CNV1 ||
1882 navType() == t_eph::CNV2) {
1883 nLines += 2;
1884 }
1885 if (navType() == t_eph::CNV3) {
1886 nLines += 1;
1887 }
1888
1889 if (lines.size() != nLines) {
1890 _checkState = bad;
1891 return;
1892 }
1893
1894 // RINEX Format
1895 // ------------
1896 int fieldLen = 19;
1897
1898 int pos[4];
1899 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1900 pos[1] = pos[0] + fieldLen;
1901 pos[2] = pos[1] + fieldLen;
1902 pos[3] = pos[2] + fieldLen;
1903
1904 // Read eight lines
1905 // ----------------
1906 for (int iLine = 0; iLine < nLines; iLine++) {
1907 QString line = lines[iLine];
1908
1909 if ( iLine == 0 ) {
1910 QTextStream in(line.left(pos[1]).toLatin1());
1911
1912 int year, month, day, hour, min;
1913 double sec;
1914
1915 QString prnStr, n;
1916 in >> prnStr;
1917 if (prnStr.size() == 1 && prnStr[0] == 'C') {
1918 in >> n;
1919 prnStr.append(n);
1920 }
1921 in >> year >> month >> day >> hour >> min >> sec;
1922 if (prnStr.at(0) == 'C') {
1923 _prn.set('C', prnStr.mid(1).toInt());
1924 }
1925 else {
1926 _prn.set('C', prnStr.toInt());
1927 }
1928
1929 if (year < 80) {
1930 year += 2000;
1931 }
1932 else if (year < 100) {
1933 year += 1900;
1934 }
1935
1936 _TOC.setBDS(year, month, day, hour, min, sec);
1937
1938 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1939 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1940 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1941 _checkState = bad;
1942 return;
1943 }
1944 }
1945 // =====================
1946 // BROADCAST ORBIT - 1
1947 // =====================
1948 else if ( iLine == 1 ) {
1949 double aode;
1950 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1951 readDbl(line, pos[1], fieldLen, _Crs ) ||
1952 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1953 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1954 _checkState = bad;
1955 return;
1956 }
1957 _AODE = int(aode);
1958 }
1959 // =====================
1960 // BROADCAST ORBIT - 2
1961 // =====================
1962 else if ( iLine == 2 ) {
1963 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1964 readDbl(line, pos[1], fieldLen, _e ) ||
1965 readDbl(line, pos[2], fieldLen, _Cus ) ||
1966 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1967 _checkState = bad;
1968 return;
1969 }
1970 }
1971 // =====================
1972 // BROADCAST ORBIT - 3
1973 // =====================
1974 else if ( iLine == 3 ) {
1975 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
1976 readDbl(line, pos[1], fieldLen, _Cic ) ||
1977 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1978 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1979 _checkState = bad;
1980 return;
1981 }
1982 }
1983 // =====================
1984 // BROADCAST ORBIT - 4
1985 // =====================
1986 else if ( iLine == 4 ) {
1987 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1988 readDbl(line, pos[1], fieldLen, _Crc ) ||
1989 readDbl(line, pos[2], fieldLen, _omega ) ||
1990 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1991 _checkState = bad;
1992 return;
1993 }
1994 }
1995 // =====================
1996 // BROADCAST ORBIT - 5
1997 // =====================
1998 else if ( iLine == 5 ) {
1999
2000 if (navType() == t_eph::CNV1 ||
2001 navType() == t_eph::CNV2 ||
2002 navType() == t_eph::CNV3 ) {
2003 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
2004 readDbl(line, pos[1], fieldLen, _Delta_n_dot) ||
2005 readDbl(line, pos[2], fieldLen, _satType ) ||
2006 readDbl(line, pos[3], fieldLen, _top ) ) {
2007 _checkState = bad;
2008 return;
2009 }
2010 }
2011 else { // D1, D2, undefined
2012 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
2013 readDbl(line, pos[2], fieldLen, _BDTweek)) {
2014 _checkState = bad;
2015 return;
2016 }
2017 }
2018 }
2019 // =====================
2020 // BROADCAST ORBIT - 6
2021 // =====================
2022 else if ( iLine == 6 ) {
2023 if (navType() == t_eph::CNV1 ||
2024 navType() == t_eph::CNV2 ||
2025 navType() == t_eph::CNV3 ) {
2026 if ( readDbl(line, pos[0], fieldLen, _SISAI_oe ) ||
2027 readDbl(line, pos[1], fieldLen, _SISAI_ocb ) ||
2028 readDbl(line, pos[2], fieldLen, _SISAI_oc1 ) ||
2029 readDbl(line, pos[3], fieldLen, _SISAI_oc2 ) ) {
2030 _checkState = bad;
2031 return;
2032 }
2033 }
2034 else { // D1, D2, undefined
2035 double SatH1;
2036 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
2037 readDbl(line, pos[1], fieldLen, SatH1) ||
2038 readDbl(line, pos[2], fieldLen, _TGD1) ||
2039 readDbl(line, pos[3], fieldLen, _TGD2) ) {
2040 _checkState = bad;
2041 return;
2042 }
2043 _SatH1 = int(SatH1);
2044 }
2045 }
2046 // =====================
2047 // BROADCAST ORBIT - 7
2048 // =====================
2049 else if ( iLine == 7 ) {
2050 if (navType() == t_eph::CNV1) {
2051 if ( readDbl(line, pos[0], fieldLen, _ISC_B1Cd) ||
2052 readDbl(line, pos[2], fieldLen, _TGD_B1Cp) ||
2053 readDbl(line, pos[3], fieldLen, _TGD_B2ap) ) {
2054 _checkState = bad;
2055 return;
2056 }
2057 }
2058 else if (navType() == t_eph::CNV2) {
2059 if ( readDbl(line, pos[1], fieldLen, _ISC_B2ad) ||
2060 readDbl(line, pos[2], fieldLen, _TGD_B1Cp) ||
2061 readDbl(line, pos[3], fieldLen, _TGD_B2ap) ) {
2062 _checkState = bad;
2063 return;
2064 }
2065 }
2066 else if (navType() == t_eph::CNV3) {
2067 double health;
2068 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2069 readDbl(line, pos[1], fieldLen, health ) ||
2070 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B2b) ||
2071 readDbl(line, pos[3], fieldLen, _TGD_B2bI) ) {
2072 _checkState = bad;
2073 return;
2074 }
2075 _health = int(health);
2076 }
2077 else { // D1, D2 or undefined
2078 double aodc;
2079 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
2080 readDbl(line, pos[1], fieldLen, aodc) ) {
2081 _checkState = bad;
2082 return;
2083 }
2084 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
2085 _TOT = _TOEsec;
2086 }
2087 _AODC = int(aodc);
2088 }
2089 }
2090 // =====================
2091 // BROADCAST ORBIT - 8
2092 // =====================
2093 else if ( iLine == 8 ) {
2094 double health;
2095 if (navType() == t_eph::CNV1) {
2096 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2097 readDbl(line, pos[1], fieldLen, health ) ||
2098 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B1C) ||
2099 readDbl(line, pos[3], fieldLen, _IODC) ) {
2100 _checkState = bad;
2101 return;
2102 }
2103 _health = int(health);
2104 }
2105 else if (navType() == t_eph::CNV2) {
2106 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2107 readDbl(line, pos[1], fieldLen, health ) ||
2108 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B2aB1C) ||
2109 readDbl(line, pos[3], fieldLen, _IODC) ) {
2110 _checkState = bad;
2111 return;
2112 }
2113 _health = int(health);
2114 }
2115 else if (navType() == t_eph::CNV3) {
2116 if ( readDbl(line, pos[0], fieldLen, _TOT)) {
2117 _checkState = bad;
2118 return;
2119 }
2120 }
2121
2122 }
2123 // =====================
2124 // BROADCAST ORBIT - 9
2125 // =====================
2126 else if ( iLine == 9 ) {
2127
2128 if (navType() == t_eph::CNV1 ||
2129 navType() == t_eph::CNV2) {
2130 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
2131 readDbl(line, pos[3], fieldLen, _IODE) ) {
2132 _checkState = bad;
2133 return;
2134 }
2135 }
2136
2137 }
2138 }
2139
2140 _TOE.setBDS(int(_BDTweek), _TOEsec);
2141 // remark: actually should be computed from second_tot
2142 // but it seems to be unreliable in RINEX files
2143 //_TOT = _TOC.bdssec();
2144}
2145
2146// IOD of BDS Ephemeris (virtual)
2147////////////////////////////////////////////////////////////////////////////
2148unsigned int t_ephBDS::IOD() const {
2149 return (int(_TOEsec)/720) % 240;
2150}
2151
2152// Compute BDS Satellite Position (virtual)
2153//////////////////////////////////////////////////////////////////////////////
2154t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
2155
2156 static const double gmBDS = 398.6004418e12;
2157 static const double omegaBDS = 7292115.0000e-11;
2158
2159 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
2160 vv[0] = vv[1] = vv[2] = 0.0;
2161
2162 bncTime tt(GPSweek, GPSweeks);
2163
2164 if (_sqrt_A == 0) {
2165 return failure;
2166 }
2167 double a0 = _sqrt_A * _sqrt_A;
2168
2169 double n0 = sqrt(gmBDS/(a0*a0*a0));
2170 double tk = tt - _TOE;
2171 double n = n0 + _Delta_n;
2172 double M = _M0 + n*tk;
2173 double E = M;
2174 double E_last;
2175 int nLoop = 0;
2176 do {
2177 E_last = E;
2178 E = M + _e*sin(E);
2179
2180 if (++nLoop == 100) {
2181 return failure;
2182 }
2183 } while ( fabs(E-E_last)*a0 > 0.001 );
2184
2185 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
2186 double u0 = v + _omega;
2187 double sin2u0 = sin(2*u0);
2188 double cos2u0 = cos(2*u0);
2189 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
2190 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
2191 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
2192 double xp = r*cos(u);
2193 double yp = r*sin(u);
2194 double toesec = (_TOE.gpssec() - 14.0);
2195 double sinom = 0;
2196 double cosom = 0;
2197 double sini = 0;
2198 double cosi = 0;
2199
2200 // Velocity
2201 // --------
2202 double tanv2 = tan(v/2);
2203 double dEdM = 1 / (1 - _e*cos(E));
2204 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
2205 / (1 + tanv2*tanv2) * dEdM * n;
2206 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
2207 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
2208 double dotr = a0 * _e*sin(E) * dEdM * n
2209 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
2210
2211 double dotx = dotr*cos(u) - r*sin(u)*dotu;
2212 double doty = dotr*sin(u) + r*cos(u)*dotu;
2213
2214 const double iMaxGEO = 10.0 / 180.0 * M_PI;
2215
2216 // MEO/IGSO satellite
2217 // ------------------
2218 if (_i0 > iMaxGEO) {
2219 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
2220
2221 sinom = sin(OM);
2222 cosom = cos(OM);
2223 sini = sin(i);
2224 cosi = cos(i);
2225
2226 xc[0] = xp*cosom - yp*cosi*sinom;
2227 xc[1] = xp*sinom + yp*cosi*cosom;
2228 xc[2] = yp*sini;
2229
2230 // Velocity
2231 // --------
2232
2233 double dotom = _OMEGADOT - t_CST::omega;
2234
2235 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
2236 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
2237 + yp*sini*sinom*doti; // dX / di
2238
2239 vv[1] = sinom *dotx + cosi*cosom *doty
2240 + xp*cosom*dotom - yp*cosi*sinom*dotom
2241 - yp*sini*cosom*doti;
2242
2243 vv[2] = sini *doty + yp*cosi *doti;
2244
2245 }
2246
2247 // GEO satellite
2248 // -------------
2249 else {
2250 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
2251 double ll = omegaBDS*tk;
2252
2253 sinom = sin(OM);
2254 cosom = cos(OM);
2255 sini = sin(i);
2256 cosi = cos(i);
2257
2258 double xx = xp*cosom - yp*cosi*sinom;
2259 double yy = xp*sinom + yp*cosi*cosom;
2260 double zz = yp*sini;
2261
2262 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
2263 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
2264
2265 ColumnVector X1(3); X1 << xx << yy << zz;
2266 ColumnVector X2 = RZ*RX*X1;
2267
2268 xc[0] = X2(1);
2269 xc[1] = X2(2);
2270 xc[2] = X2(3);
2271
2272 double dotom = _OMEGADOT;
2273
2274 double vx = cosom *dotx - cosi*sinom *doty
2275 - xp*sinom*dotom - yp*cosi*cosom*dotom
2276 + yp*sini*sinom*doti;
2277
2278 double vy = sinom *dotx + cosi*cosom *doty
2279 + xp*cosom*dotom - yp*cosi*sinom*dotom
2280 - yp*sini*cosom*doti;
2281
2282 double vz = sini *doty + yp*cosi *doti;
2283
2284 ColumnVector V(3); V << vx << vy << vz;
2285
2286 Matrix RdotZ(3,3);
2287 double C = cos(ll);
2288 double S = sin(ll);
2289 Matrix UU(3,3);
2290 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
2291 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
2292 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
2293 RdotZ = omegaBDS * UU;
2294
2295 ColumnVector VV(3);
2296 VV = RZ*RX*V + RdotZ*RX*X1;
2297
2298 vv[0] = VV(1);
2299 vv[1] = VV(2);
2300 vv[2] = VV(3);
2301 }
2302
2303 double tc = tt - _TOC;
2304 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
2305
2306// dotC = _clock_drift + _clock_driftrate*tc
2307// - 4.442807309e-10*_e * sqrt(a0) * cos(E) * dEdM * n;
2308
2309 // Relativistic Correction
2310 // -----------------------
2311 xc[3] -= 4.442807309e-10 * _e * sqrt(a0) *sin(E);
2312
2313 xc[4] = _clock_drift + _clock_driftrate*tc;
2314 xc[5] = _clock_driftrate;
2315
2316 return success;
2317}
2318
2319
2320// Health status of SBAS Ephemeris (virtual)
2321////////////////////////////////////////////////////////////////////////////
2322unsigned int t_ephBDS::isUnhealthy() const {
2323
2324 if (navType() == t_eph::CNV1 ||
2325 navType() == t_eph::CNV2 ||
2326 navType() == t_eph::CNV3) {
2327 return static_cast<unsigned int>(_health);
2328 }
2329
2330 return static_cast<unsigned int>(_SatH1);
2331
2332}
2333
2334
2335// RINEX Format String
2336//////////////////////////////////////////////////////////////////////////////
2337QString t_ephBDS::toString(double version) const {
2338
2339 QString navStr = navTypeString(_navType, _prn, version);
2340 QString rnxStr = navStr + rinexDateStr(_TOC-14.0, _prn, version);
2341
2342 QTextStream out(&rnxStr);
2343
2344 out << QString("%1%2%3\n")
2345 .arg(_clock_bias, 19, 'e', 12)
2346 .arg(_clock_drift, 19, 'e', 12)
2347 .arg(_clock_driftrate, 19, 'e', 12);
2348
2349 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
2350 // =====================
2351 // BROADCAST ORBIT - 1
2352 // =====================
2353 out << QString(fmt)
2354 .arg(double(_AODE), 19, 'e', 12)
2355 .arg(_Crs, 19, 'e', 12)
2356 .arg(_Delta_n, 19, 'e', 12)
2357 .arg(_M0, 19, 'e', 12);
2358 // =====================
2359 // BROADCAST ORBIT - 2
2360 // =====================
2361 out << QString(fmt)
2362 .arg(_Cuc, 19, 'e', 12)
2363 .arg(_e, 19, 'e', 12)
2364 .arg(_Cus, 19, 'e', 12)
2365 .arg(_sqrt_A, 19, 'e', 12);
2366 // =====================
2367 // BROADCAST ORBIT - 3
2368 // =====================
2369 out << QString(fmt)
2370 .arg(_TOEsec, 19, 'e', 12)
2371 .arg(_Cic, 19, 'e', 12)
2372 .arg(_OMEGA0, 19, 'e', 12)
2373 .arg(_Cis, 19, 'e', 12);
2374 // =====================
2375 // BROADCAST ORBIT - 4
2376 // =====================
2377 out << QString(fmt)
2378 .arg(_i0, 19, 'e', 12)
2379 .arg(_Crc, 19, 'e', 12)
2380 .arg(_omega, 19, 'e', 12)
2381 .arg(_OMEGADOT, 19, 'e', 12);
2382 // =====================
2383 // BROADCAST ORBIT - 5
2384 // =====================
2385 if (navType() == t_eph::CNV1 ||
2386 navType() == t_eph::CNV2 ||
2387 navType() == t_eph::CNV3 ) {
2388 out << QString(fmt)
2389 .arg(_IDOT, 19, 'e', 12)
2390 .arg(_Delta_n_dot, 19, 'e', 12)
2391 .arg(_satType, 19, 'e', 12)
2392 .arg(_top, 19, 'e', 12);
2393 }
2394 else { // D1, D2, undefined
2395 out << QString(fmt)
2396 .arg(_IDOT, 19, 'e', 12)
2397 .arg("", 19, QChar(' '))
2398 .arg(_BDTweek, 19, 'e', 12)
2399 .arg("", 19, QChar(' '));
2400 }
2401 // =====================
2402 // BROADCAST ORBIT - 6
2403 // =====================
2404 if (navType() == t_eph::CNV1 ||
2405 navType() == t_eph::CNV2 ||
2406 navType() == t_eph::CNV3 ) {
2407 out << QString(fmt)
2408 .arg(_SISAI_oe, 19, 'e', 12)
2409 .arg(_SISAI_ocb, 19, 'e', 12)
2410 .arg(_SISAI_oc1, 19, 'e', 12)
2411 .arg(_SISAI_oc2, 19, 'e', 12);
2412 }
2413 else { // D1, D2, undefined
2414 out << QString(fmt)
2415 .arg(_URA, 19, 'e', 12)
2416 .arg(double(_SatH1), 19, 'e', 12)
2417 .arg(_TGD1, 19, 'e', 12)
2418 .arg(_TGD2, 19, 'e', 12);
2419 }
2420 // =====================
2421 // BROADCAST ORBIT - 7
2422 // =====================
2423 if (navType() == t_eph::CNV1) {
2424 out << QString(fmt)
2425 .arg(_ISC_B1Cd, 19, 'e', 12)
2426 .arg("", 19, QChar(' '))
2427 .arg(_TGD_B1Cp, 19, 'e', 12)
2428 .arg(_TGD_B2ap, 19, 'e', 12);
2429 }
2430 else if (navType() == t_eph::CNV2) {
2431 out << QString(fmt)
2432 .arg("", 19, QChar(' '))
2433 .arg(_ISC_B2ad, 19, 'e', 12)
2434 .arg(_TGD_B1Cp, 19, 'e', 12)
2435 .arg(_TGD_B2ap, 19, 'e', 12);
2436 }
2437 else if (navType() == t_eph::CNV3) {
2438 out << QString(fmt)
2439 .arg(_SISMAI, 19, 'e', 12)
2440 .arg(double(_health), 19, 'e', 12)
2441 .arg(_INTEGRITYF_B2b, 19, 'e', 12)
2442 .arg(_TGD_B2bI, 19, 'e', 12);
2443 }
2444 else { // D1, D2, undefined
2445 double tots = 0.0;
2446 if (_receptDateTime.isValid()) {// RTCM stream input
2447 tots = _TOE.bdssec();
2448 }
2449 else { // RINEX input
2450 tots = _TOT;
2451 }
2452 out << QString(fmt)
2453 .arg(tots, 19, 'e', 12)
2454 .arg(double(_AODC), 19, 'e', 12)
2455 .arg("", 19, QChar(' '))
2456 .arg("", 19, QChar(' '));
2457 }
2458
2459 // =====================
2460 // BROADCAST ORBIT - 8
2461 // =====================
2462 if (navType() == t_eph::CNV1) {
2463 out << QString(fmt)
2464 .arg(_SISMAI, 19, 'e', 12)
2465 .arg(double(_health), 19, 'e', 12)
2466 .arg(_INTEGRITYF_B1C, 19, 'e', 12)
2467 .arg(_IODC, 19, 'e', 12);
2468 }
2469 else if (navType() == t_eph::CNV2) {
2470 out << QString(fmt)
2471 .arg(_SISMAI, 19, 'e', 12)
2472 .arg(double(_health), 19, 'e', 12)
2473 .arg(_INTEGRITYF_B2aB1C, 19, 'e', 12)
2474 .arg(_IODC, 19, 'e', 12);
2475 }
2476 else if (navType() == t_eph::CNV3) {
2477 out << QString(fmt)
2478 .arg(_TOT, 19, 'e', 12)
2479 .arg("", 19, QChar(' '))
2480 .arg("", 19, QChar(' '))
2481 .arg("", 19, QChar(' '));
2482 }
2483
2484 // =====================
2485 // BROADCAST ORBIT - 9
2486 // =====================
2487 if (navType() == t_eph::CNV1 ||
2488 navType() == t_eph::CNV2) {
2489 out << QString(fmt)
2490 .arg(_TOT, 19, 'e', 12)
2491 .arg("", 19, QChar(' '))
2492 .arg("", 19, QChar(' '))
2493 .arg(_IODE, 19, 'e', 12);
2494 }
2495
2496
2497 return rnxStr;
2498}
Note: See TracBrowser for help on using the repository browser.