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

Last change on this file since 9954 was 9939, checked in by stuerze, 17 months ago

minor changes

File size: 70.6 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 return 0;
1491}
1492
1493// RINEX Format String
1494//////////////////////////////////////////////////////////////////////////////
1495QString t_ephGal::toString(double version) const {
1496
1497 QString navStr = navTypeString(_navType, _prn, version);
1498 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
1499
1500 QTextStream out(&rnxStr);
1501
1502 out << QString("%1%2%3\n")
1503 .arg(_clock_bias, 19, 'e', 12)
1504 .arg(_clock_drift, 19, 'e', 12)
1505 .arg(_clock_driftrate, 19, 'e', 12);
1506
1507 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1508 // =====================
1509 // BROADCAST ORBIT - 1
1510 // =====================
1511 out << QString(fmt)
1512 .arg(_IODnav, 19, 'e', 12)
1513 .arg(_Crs, 19, 'e', 12)
1514 .arg(_Delta_n, 19, 'e', 12)
1515 .arg(_M0, 19, 'e', 12);
1516 // =====================
1517 // BROADCAST ORBIT - 2
1518 // =====================
1519 out << QString(fmt)
1520 .arg(_Cuc, 19, 'e', 12)
1521 .arg(_e, 19, 'e', 12)
1522 .arg(_Cus, 19, 'e', 12)
1523 .arg(_sqrt_A, 19, 'e', 12);
1524 // =====================
1525 // BROADCAST ORBIT - 3
1526 // =====================
1527 out << QString(fmt)
1528 .arg(_TOEsec, 19, 'e', 12)
1529 .arg(_Cic, 19, 'e', 12)
1530 .arg(_OMEGA0, 19, 'e', 12)
1531 .arg(_Cis, 19, 'e', 12);
1532 // =====================
1533 // BROADCAST ORBIT - 4
1534 // =====================
1535 out << QString(fmt)
1536 .arg(_i0, 19, 'e', 12)
1537 .arg(_Crc, 19, 'e', 12)
1538 .arg(_omega, 19, 'e', 12)
1539 .arg(_OMEGADOT, 19, 'e', 12);
1540 // =====================
1541 // BROADCAST ORBIT - 5
1542 // =====================
1543 int dataSource = 0;
1544 int SVhealth = 0;
1545 double BGD_1_5A = _BGD_1_5A;
1546 double BGD_1_5B = _BGD_1_5B;
1547 if (_fnav) {
1548 dataSource |= (1<<1);
1549 dataSource |= (1<<8);
1550 BGD_1_5B = 0.0;
1551 // SVhealth
1552 // Bit 3 : E5a DVS
1553 if (_e5aDataInValid) {
1554 SVhealth |= (1<<3);
1555 }
1556 // Bit 4-5: E5a HS
1557 if (_E5aHS == 1.0) {
1558 SVhealth |= (1<<4);
1559 }
1560 else if (_E5aHS == 2.0) {
1561 SVhealth |= (1<<5);
1562 }
1563 else if (_E5aHS == 3.0) {
1564 SVhealth |= (1<<4);
1565 SVhealth |= (1<<5);
1566 }
1567 }
1568 else if(_inav) {
1569 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1570 // and RNXv3.03 says both can be set if the navigation messages were merged
1571 dataSource |= (1<<0);
1572 dataSource |= (1<<2);
1573 dataSource |= (1<<9);
1574 // SVhealth
1575 // Bit 0 : E1-B DVS
1576 if (_e1DataInValid) {
1577 SVhealth |= (1<<0);
1578 }
1579 // Bit 1-2: E1-B HS
1580 if (_E1_bHS == 1.0) {
1581 SVhealth |= (1<<1);
1582 }
1583 else if (_E1_bHS == 2.0) {
1584 SVhealth |= (1<<2);
1585 }
1586 else if (_E1_bHS == 3.0) {
1587 SVhealth |= (1<<1);
1588 SVhealth |= (1<<2);
1589 }
1590 // Bit 3 : E5a DVS
1591 if (_e5aDataInValid) {
1592 SVhealth |= (1<<3);
1593 }
1594 // Bit 4-5: E5a HS
1595 if (_E5aHS == 1.0) {
1596 SVhealth |= (1<<4);
1597 }
1598 else if (_E5aHS == 2.0) {
1599 SVhealth |= (1<<5);
1600 }
1601 else if (_E5aHS == 3.0) {
1602 SVhealth |= (1<<4);
1603 SVhealth |= (1<<5);
1604 }
1605 // Bit 6 : E5b DVS
1606 if (_e5bDataInValid) {
1607 SVhealth |= (1<<6);
1608 }
1609 // Bit 7-8: E5b HS
1610 if (_E5bHS == 1.0) {
1611 SVhealth |= (1<<7);
1612 }
1613 else if (_E5bHS == 2.0) {
1614 SVhealth |= (1<<8);
1615 }
1616 else if (_E5bHS == 3.0) {
1617 SVhealth |= (1<<7);
1618 SVhealth |= (1<<8);
1619 }
1620 }
1621
1622 out << QString(fmt)
1623 .arg(_IDOT, 19, 'e', 12)
1624 .arg(double(dataSource), 19, 'e', 12)
1625 .arg(_TOEweek + 1024.0, 19, 'e', 12)
1626 .arg(0.0, 19, 'e', 12);
1627 // =====================
1628 // BROADCAST ORBIT - 6
1629 // =====================
1630 out << QString(fmt)
1631 .arg(_SISA, 19, 'e', 12)
1632 .arg(double(SVhealth), 19, 'e', 12)
1633 .arg(BGD_1_5A, 19, 'e', 12)
1634 .arg(BGD_1_5B, 19, 'e', 12);
1635 // =====================
1636 // BROADCAST ORBIT - 7
1637 // =====================
1638 double tot = _TOT;
1639 if (tot == 0.9999e9 && version < 3.0) {
1640 tot = 0.0;
1641 }
1642 out << QString(fmt)
1643 .arg(tot, 19, 'e', 12)
1644 .arg("", 19, QChar(' '))
1645 .arg("", 19, QChar(' '))
1646 .arg("", 19, QChar(' '));
1647
1648 return rnxStr;
1649}
1650
1651// Constructor
1652//////////////////////////////////////////////////////////////////////////////
1653t_ephSBAS::t_ephSBAS(double rnxVersion, const QStringList& lines) {
1654
1655 const int nLines = 4;
1656
1657 if (lines.size() != nLines) {
1658 _checkState = bad;
1659 return;
1660 }
1661
1662 // RINEX Format
1663 // ------------
1664 int fieldLen = 19;
1665
1666 int pos[4];
1667 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1668 pos[1] = pos[0] + fieldLen;
1669 pos[2] = pos[1] + fieldLen;
1670 pos[3] = pos[2] + fieldLen;
1671
1672 // Read four lines
1673 // ---------------
1674 for (int iLine = 0; iLine < nLines; iLine++) {
1675 QString line = lines[iLine];
1676
1677 if ( iLine == 0 ) {
1678 QTextStream in(line.left(pos[1]).toLatin1());
1679
1680 int year, month, day, hour, min;
1681 double sec;
1682
1683 QString prnStr, n;
1684 in >> prnStr;
1685 if (prnStr.size() == 1 && prnStr[0] == 'S') {
1686 in >> n;
1687 prnStr.append(n);
1688 }
1689 in >> year >> month >> day >> hour >> min >> sec;
1690 if (prnStr.at(0) == 'S') {
1691 _prn.set('S', prnStr.mid(1).toInt());
1692 }
1693 else {
1694 _prn.set('S', prnStr.toInt());
1695 }
1696
1697 if (year < 80) {
1698 year += 2000;
1699 }
1700 else if (year < 100) {
1701 year += 1900;
1702 }
1703
1704 _TOC.set(year, month, day, hour, min, sec);
1705
1706 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1707 readDbl(line, pos[2], fieldLen, _agf1 ) ||
1708 readDbl(line, pos[3], fieldLen, _TOT ) ) {
1709 _checkState = bad;
1710 return;
1711 }
1712 }
1713 // =====================
1714 // BROADCAST ORBIT - 1
1715 // =====================
1716 else if ( iLine == 1 ) {
1717 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1718 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1719 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1720 readDbl(line, pos[3], fieldLen, _health ) ) {
1721 _checkState = bad;
1722 return;
1723 }
1724 }
1725 // =====================
1726 // BROADCAST ORBIT - 2
1727 // =====================
1728 else if ( iLine == 2 ) {
1729 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1730 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1731 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1732 readDbl(line, pos[3], fieldLen, _ura ) ) {
1733 _checkState = bad;
1734 return;
1735 }
1736 }
1737 // =====================
1738 // BROADCAST ORBIT - 3
1739 // =====================
1740 else if ( iLine == 3 ) {
1741 double iodn;
1742 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1743 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1744 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
1745 readDbl(line, pos[3], fieldLen, iodn ) ) {
1746 _checkState = bad;
1747 return;
1748 } else {
1749 _IODN = int(iodn);
1750 }
1751 }
1752 }
1753
1754 _x_pos *= 1.e3;
1755 _y_pos *= 1.e3;
1756 _z_pos *= 1.e3;
1757 _x_velocity *= 1.e3;
1758 _y_velocity *= 1.e3;
1759 _z_velocity *= 1.e3;
1760 _x_acceleration *= 1.e3;
1761 _y_acceleration *= 1.e3;
1762 _z_acceleration *= 1.e3;
1763}
1764
1765// IOD of SBAS Ephemeris (virtual)
1766////////////////////////////////////////////////////////////////////////////
1767
1768unsigned int t_ephSBAS::IOD() const {
1769 unsigned char buffer[80];
1770 int size = 0;
1771 int numbits = 0;
1772 long long bitbuffer = 0;
1773 unsigned char *startbuffer = buffer;
1774
1775 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1776 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1777 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1778 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1779 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1780 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1781 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1782 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1783 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1784 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1785 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1786 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1787
1788 return CRC24(size, startbuffer);
1789}
1790
1791// Compute SBAS Satellite Position (virtual)
1792////////////////////////////////////////////////////////////////////////////
1793t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1794
1795 bncTime tt(GPSweek, GPSweeks);
1796 double dt = tt - _TOC;
1797
1798 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1799 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1800 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
1801
1802 vv[0] = _x_velocity + _x_acceleration * dt;
1803 vv[1] = _y_velocity + _y_acceleration * dt;
1804 vv[2] = _z_velocity + _z_acceleration * dt;
1805
1806 xc[3] = _agf0 + _agf1 * dt;
1807
1808 xc[4] = _agf1;
1809 xc[5] = 0.0;
1810
1811 return success;
1812}
1813
1814// Health status of SBAS Ephemeris (virtual)
1815////////////////////////////////////////////////////////////////////////////
1816unsigned int t_ephSBAS::isUnhealthy() const {
1817
1818 // Bit 5
1819 bool URAindexIs15 = (int(_health) & (1<<5));
1820 if (URAindexIs15) {
1821 // in this case it is recommended
1822 // to set the bits 0,1,2,3 to 1 (MT17health = 15)
1823 return 1;
1824 }
1825
1826 // Bit 0-3
1827 int MT17health = (int(_health)) & (0x0f);
1828 if (MT17health) {
1829 return 1;
1830 }
1831
1832 // Bit 4
1833 // bool MT17HealthIsUnavailable = (int(_health) & (1<<4));
1834 // is not used because the MT17health bits can be independently set if URA index is 15
1835
1836 return 0;
1837}
1838
1839
1840// RINEX Format String
1841//////////////////////////////////////////////////////////////////////////////
1842QString t_ephSBAS::toString(double version) const {
1843
1844 QString navStr = navTypeString(_navType, _prn, version);
1845 QString rnxStr = navStr + rinexDateStr(_TOC, _prn, version);
1846
1847 QTextStream out(&rnxStr);
1848
1849 out << QString("%1%2%3\n")
1850 .arg(_agf0, 19, 'e', 12)
1851 .arg(_agf1, 19, 'e', 12)
1852 .arg(_TOT, 19, 'e', 12);
1853
1854 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1855 // =====================
1856 // BROADCAST ORBIT - 1
1857 // =====================
1858 out << QString(fmt)
1859 .arg(1.e-3*_x_pos, 19, 'e', 12)
1860 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1861 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
1862 .arg(_health, 19, 'e', 12);
1863 // =====================
1864 // BROADCAST ORBIT - 2
1865 // =====================
1866 out << QString(fmt)
1867 .arg(1.e-3*_y_pos, 19, 'e', 12)
1868 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1869 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
1870 .arg(_ura, 19, 'e', 12);
1871 // =====================
1872 // BROADCAST ORBIT - 3
1873 // =====================
1874 out << QString(fmt)
1875 .arg(1.e-3*_z_pos, 19, 'e', 12)
1876 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1877 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
1878 .arg(double(_IODN), 19, 'e', 12);
1879
1880 return rnxStr;
1881}
1882
1883// Constructor
1884//////////////////////////////////////////////////////////////////////////////
1885t_ephBDS::t_ephBDS(double rnxVersion, const QStringList& lines) {
1886
1887 int nLines = 8;
1888
1889 if (navType() == t_eph::CNV1 ||
1890 navType() == t_eph::CNV2) {
1891 nLines += 2;
1892 }
1893 if (navType() == t_eph::CNV3) {
1894 nLines += 1;
1895 }
1896
1897 if (lines.size() != nLines) {
1898 _checkState = bad;
1899 return;
1900 }
1901
1902 // RINEX Format
1903 // ------------
1904 int fieldLen = 19;
1905
1906 int pos[4];
1907 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1908 pos[1] = pos[0] + fieldLen;
1909 pos[2] = pos[1] + fieldLen;
1910 pos[3] = pos[2] + fieldLen;
1911
1912 // Read eight lines
1913 // ----------------
1914 for (int iLine = 0; iLine < nLines; iLine++) {
1915 QString line = lines[iLine];
1916
1917 if ( iLine == 0 ) {
1918 QTextStream in(line.left(pos[1]).toLatin1());
1919
1920 int year, month, day, hour, min;
1921 double sec;
1922
1923 QString prnStr, n;
1924 in >> prnStr;
1925 if (prnStr.size() == 1 && prnStr[0] == 'C') {
1926 in >> n;
1927 prnStr.append(n);
1928 }
1929 in >> year >> month >> day >> hour >> min >> sec;
1930 if (prnStr.at(0) == 'C') {
1931 _prn.set('C', prnStr.mid(1).toInt());
1932 }
1933 else {
1934 _prn.set('C', prnStr.toInt());
1935 }
1936
1937 if (year < 80) {
1938 year += 2000;
1939 }
1940 else if (year < 100) {
1941 year += 1900;
1942 }
1943
1944 _TOC.setBDS(year, month, day, hour, min, sec);
1945
1946 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1947 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1948 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1949 _checkState = bad;
1950 return;
1951 }
1952 }
1953 // =====================
1954 // BROADCAST ORBIT - 1
1955 // =====================
1956 else if ( iLine == 1 ) {
1957 double aode;
1958 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1959 readDbl(line, pos[1], fieldLen, _Crs ) ||
1960 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1961 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1962 _checkState = bad;
1963 return;
1964 }
1965 _AODE = int(aode);
1966 }
1967 // =====================
1968 // BROADCAST ORBIT - 2
1969 // =====================
1970 else if ( iLine == 2 ) {
1971 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1972 readDbl(line, pos[1], fieldLen, _e ) ||
1973 readDbl(line, pos[2], fieldLen, _Cus ) ||
1974 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1975 _checkState = bad;
1976 return;
1977 }
1978 }
1979 // =====================
1980 // BROADCAST ORBIT - 3
1981 // =====================
1982 else if ( iLine == 3 ) {
1983 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
1984 readDbl(line, pos[1], fieldLen, _Cic ) ||
1985 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1986 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1987 _checkState = bad;
1988 return;
1989 }
1990 }
1991 // =====================
1992 // BROADCAST ORBIT - 4
1993 // =====================
1994 else if ( iLine == 4 ) {
1995 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1996 readDbl(line, pos[1], fieldLen, _Crc ) ||
1997 readDbl(line, pos[2], fieldLen, _omega ) ||
1998 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1999 _checkState = bad;
2000 return;
2001 }
2002 }
2003 // =====================
2004 // BROADCAST ORBIT - 5
2005 // =====================
2006 else if ( iLine == 5 ) {
2007
2008 if (navType() == t_eph::CNV1 ||
2009 navType() == t_eph::CNV2 ||
2010 navType() == t_eph::CNV3 ) {
2011 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
2012 readDbl(line, pos[1], fieldLen, _Delta_n_dot) ||
2013 readDbl(line, pos[2], fieldLen, _satType ) ||
2014 readDbl(line, pos[3], fieldLen, _top ) ) {
2015 _checkState = bad;
2016 return;
2017 }
2018 }
2019 else { // D1, D2, undefined
2020 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
2021 readDbl(line, pos[2], fieldLen, _BDTweek)) {
2022 _checkState = bad;
2023 return;
2024 }
2025 }
2026 }
2027 // =====================
2028 // BROADCAST ORBIT - 6
2029 // =====================
2030 else if ( iLine == 6 ) {
2031 if (navType() == t_eph::CNV1 ||
2032 navType() == t_eph::CNV2 ||
2033 navType() == t_eph::CNV3 ) {
2034 if ( readDbl(line, pos[0], fieldLen, _SISAI_oe ) ||
2035 readDbl(line, pos[1], fieldLen, _SISAI_ocb ) ||
2036 readDbl(line, pos[2], fieldLen, _SISAI_oc1 ) ||
2037 readDbl(line, pos[3], fieldLen, _SISAI_oc2 ) ) {
2038 _checkState = bad;
2039 return;
2040 }
2041 }
2042 else { // D1, D2, undefined
2043 double SatH1;
2044 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
2045 readDbl(line, pos[1], fieldLen, SatH1) ||
2046 readDbl(line, pos[2], fieldLen, _TGD1) ||
2047 readDbl(line, pos[3], fieldLen, _TGD2) ) {
2048 _checkState = bad;
2049 return;
2050 }
2051 _SatH1 = int(SatH1);
2052 }
2053 }
2054 // =====================
2055 // BROADCAST ORBIT - 7
2056 // =====================
2057 else if ( iLine == 7 ) {
2058 if (navType() == t_eph::CNV1) {
2059 if ( readDbl(line, pos[0], fieldLen, _ISC_B1Cd) ||
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::CNV2) {
2067 if ( readDbl(line, pos[1], fieldLen, _ISC_B2ad) ||
2068 readDbl(line, pos[2], fieldLen, _TGD_B1Cp) ||
2069 readDbl(line, pos[3], fieldLen, _TGD_B2ap) ) {
2070 _checkState = bad;
2071 return;
2072 }
2073 }
2074 else if (navType() == t_eph::CNV3) {
2075 double health;
2076 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2077 readDbl(line, pos[1], fieldLen, health ) ||
2078 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B2b) ||
2079 readDbl(line, pos[3], fieldLen, _TGD_B2bI) ) {
2080 _checkState = bad;
2081 return;
2082 }
2083 _health = int(health);
2084 }
2085 else { // D1, D2 or undefined
2086 double aodc;
2087 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
2088 readDbl(line, pos[1], fieldLen, aodc) ) {
2089 _checkState = bad;
2090 return;
2091 }
2092 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
2093 _TOT = _TOEsec;
2094 }
2095 _AODC = int(aodc);
2096 }
2097 }
2098 // =====================
2099 // BROADCAST ORBIT - 8
2100 // =====================
2101 else if ( iLine == 8 ) {
2102 double health;
2103 if (navType() == t_eph::CNV1) {
2104 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2105 readDbl(line, pos[1], fieldLen, health ) ||
2106 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B1C) ||
2107 readDbl(line, pos[3], fieldLen, _IODC) ) {
2108 _checkState = bad;
2109 return;
2110 }
2111 _health = int(health);
2112 }
2113 else if (navType() == t_eph::CNV2) {
2114 if ( readDbl(line, pos[0], fieldLen, _SISMAI ) ||
2115 readDbl(line, pos[1], fieldLen, health ) ||
2116 readDbl(line, pos[2], fieldLen, _INTEGRITYF_B2aB1C) ||
2117 readDbl(line, pos[3], fieldLen, _IODC) ) {
2118 _checkState = bad;
2119 return;
2120 }
2121 _health = int(health);
2122 }
2123 else if (navType() == t_eph::CNV3) {
2124 if ( readDbl(line, pos[0], fieldLen, _TOT)) {
2125 _checkState = bad;
2126 return;
2127 }
2128 }
2129
2130 }
2131 // =====================
2132 // BROADCAST ORBIT - 9
2133 // =====================
2134 else if ( iLine == 9 ) {
2135
2136 if (navType() == t_eph::CNV1 ||
2137 navType() == t_eph::CNV2) {
2138 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
2139 readDbl(line, pos[3], fieldLen, _IODE) ) {
2140 _checkState = bad;
2141 return;
2142 }
2143 }
2144
2145 }
2146 }
2147
2148 _TOE.setBDS(int(_BDTweek), _TOEsec);
2149 // remark: actually should be computed from second_tot
2150 // but it seems to be unreliable in RINEX files
2151 //_TOT = _TOC.bdssec();
2152}
2153
2154// IOD of BDS Ephemeris (virtual)
2155////////////////////////////////////////////////////////////////////////////
2156unsigned int t_ephBDS::IOD() const {
2157 return (int(_TOC.gpssec())/720) % 240; //return (int(_TOEsec)/720) % 240;
2158}
2159
2160// Compute BDS Satellite Position (virtual)
2161//////////////////////////////////////////////////////////////////////////////
2162t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
2163
2164 static const double gmBDS = 398.6004418e12;
2165 static const double omegaBDS = 7292115.0000e-11;
2166
2167 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
2168 vv[0] = vv[1] = vv[2] = 0.0;
2169
2170 bncTime tt(GPSweek, GPSweeks);
2171
2172 if (_sqrt_A == 0) {
2173 return failure;
2174 }
2175 double a0 = _sqrt_A * _sqrt_A;
2176
2177 double n0 = sqrt(gmBDS/(a0*a0*a0));
2178 double tk = tt - _TOE;
2179 double n = n0 + _Delta_n;
2180 double M = _M0 + n*tk;
2181 double E = M;
2182 double E_last;
2183 int nLoop = 0;
2184 do {
2185 E_last = E;
2186 E = M + _e*sin(E);
2187
2188 if (++nLoop == 100) {
2189 return failure;
2190 }
2191 } while ( fabs(E-E_last)*a0 > 0.001 );
2192
2193 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
2194 double u0 = v + _omega;
2195 double sin2u0 = sin(2*u0);
2196 double cos2u0 = cos(2*u0);
2197 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
2198 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
2199 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
2200 double xp = r*cos(u);
2201 double yp = r*sin(u);
2202 double toesec = (_TOE.gpssec() - 14.0);
2203 double sinom = 0;
2204 double cosom = 0;
2205 double sini = 0;
2206 double cosi = 0;
2207
2208 // Velocity
2209 // --------
2210 double tanv2 = tan(v/2);
2211 double dEdM = 1 / (1 - _e*cos(E));
2212 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
2213 / (1 + tanv2*tanv2) * dEdM * n;
2214 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
2215 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
2216 double dotr = a0 * _e*sin(E) * dEdM * n
2217 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
2218
2219 double dotx = dotr*cos(u) - r*sin(u)*dotu;
2220 double doty = dotr*sin(u) + r*cos(u)*dotu;
2221
2222 const double iMaxGEO = 10.0 / 180.0 * M_PI;
2223
2224 // MEO/IGSO satellite
2225 // ------------------
2226 if (_i0 > iMaxGEO) {
2227 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
2228
2229 sinom = sin(OM);
2230 cosom = cos(OM);
2231 sini = sin(i);
2232 cosi = cos(i);
2233
2234 xc[0] = xp*cosom - yp*cosi*sinom;
2235 xc[1] = xp*sinom + yp*cosi*cosom;
2236 xc[2] = yp*sini;
2237
2238 // Velocity
2239 // --------
2240
2241 double dotom = _OMEGADOT - t_CST::omega;
2242
2243 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
2244 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
2245 + yp*sini*sinom*doti; // dX / di
2246
2247 vv[1] = sinom *dotx + cosi*cosom *doty
2248 + xp*cosom*dotom - yp*cosi*sinom*dotom
2249 - yp*sini*cosom*doti;
2250
2251 vv[2] = sini *doty + yp*cosi *doti;
2252
2253 }
2254
2255 // GEO satellite
2256 // -------------
2257 else {
2258 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
2259 double ll = omegaBDS*tk;
2260
2261 sinom = sin(OM);
2262 cosom = cos(OM);
2263 sini = sin(i);
2264 cosi = cos(i);
2265
2266 double xx = xp*cosom - yp*cosi*sinom;
2267 double yy = xp*sinom + yp*cosi*cosom;
2268 double zz = yp*sini;
2269
2270 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
2271 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
2272
2273 ColumnVector X1(3); X1 << xx << yy << zz;
2274 ColumnVector X2 = RZ*RX*X1;
2275
2276 xc[0] = X2(1);
2277 xc[1] = X2(2);
2278 xc[2] = X2(3);
2279
2280 double dotom = _OMEGADOT;
2281
2282 double vx = cosom *dotx - cosi*sinom *doty
2283 - xp*sinom*dotom - yp*cosi*cosom*dotom
2284 + yp*sini*sinom*doti;
2285
2286 double vy = sinom *dotx + cosi*cosom *doty
2287 + xp*cosom*dotom - yp*cosi*sinom*dotom
2288 - yp*sini*cosom*doti;
2289
2290 double vz = sini *doty + yp*cosi *doti;
2291
2292 ColumnVector V(3); V << vx << vy << vz;
2293
2294 Matrix RdotZ(3,3);
2295 double C = cos(ll);
2296 double S = sin(ll);
2297 Matrix UU(3,3);
2298 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
2299 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
2300 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
2301 RdotZ = omegaBDS * UU;
2302
2303 ColumnVector VV(3);
2304 VV = RZ*RX*V + RdotZ*RX*X1;
2305
2306 vv[0] = VV(1);
2307 vv[1] = VV(2);
2308 vv[2] = VV(3);
2309 }
2310
2311 double tc = tt - _TOC;
2312 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
2313
2314// dotC = _clock_drift + _clock_driftrate*tc
2315// - 4.442807309e-10*_e * sqrt(a0) * cos(E) * dEdM * n;
2316
2317 // Relativistic Correction
2318 // -----------------------
2319 xc[3] -= 4.442807309e-10 * _e * sqrt(a0) *sin(E);
2320
2321 xc[4] = _clock_drift + _clock_driftrate*tc;
2322 xc[5] = _clock_driftrate;
2323
2324 return success;
2325}
2326
2327
2328// Health status of SBAS Ephemeris (virtual)
2329////////////////////////////////////////////////////////////////////////////
2330unsigned int t_ephBDS::isUnhealthy() const {
2331
2332 if (navType() == t_eph::CNV1 ||
2333 navType() == t_eph::CNV2 ||
2334 navType() == t_eph::CNV3) {
2335 return static_cast<unsigned int>(_health);
2336 }
2337
2338 return static_cast<unsigned int>(_SatH1);
2339
2340}
2341
2342
2343// RINEX Format String
2344//////////////////////////////////////////////////////////////////////////////
2345QString t_ephBDS::toString(double version) const {
2346
2347 QString navStr = navTypeString(_navType, _prn, version);
2348 QString rnxStr = navStr + rinexDateStr(_TOC-14.0, _prn, version);
2349
2350 QTextStream out(&rnxStr);
2351
2352 out << QString("%1%2%3\n")
2353 .arg(_clock_bias, 19, 'e', 12)
2354 .arg(_clock_drift, 19, 'e', 12)
2355 .arg(_clock_driftrate, 19, 'e', 12);
2356
2357 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
2358 // =====================
2359 // BROADCAST ORBIT - 1
2360 // =====================
2361 out << QString(fmt)
2362 .arg(double(_AODE), 19, 'e', 12)
2363 .arg(_Crs, 19, 'e', 12)
2364 .arg(_Delta_n, 19, 'e', 12)
2365 .arg(_M0, 19, 'e', 12);
2366 // =====================
2367 // BROADCAST ORBIT - 2
2368 // =====================
2369 out << QString(fmt)
2370 .arg(_Cuc, 19, 'e', 12)
2371 .arg(_e, 19, 'e', 12)
2372 .arg(_Cus, 19, 'e', 12)
2373 .arg(_sqrt_A, 19, 'e', 12);
2374 // =====================
2375 // BROADCAST ORBIT - 3
2376 // =====================
2377 out << QString(fmt)
2378 .arg(_TOEsec, 19, 'e', 12)
2379 .arg(_Cic, 19, 'e', 12)
2380 .arg(_OMEGA0, 19, 'e', 12)
2381 .arg(_Cis, 19, 'e', 12);
2382 // =====================
2383 // BROADCAST ORBIT - 4
2384 // =====================
2385 out << QString(fmt)
2386 .arg(_i0, 19, 'e', 12)
2387 .arg(_Crc, 19, 'e', 12)
2388 .arg(_omega, 19, 'e', 12)
2389 .arg(_OMEGADOT, 19, 'e', 12);
2390 // =====================
2391 // BROADCAST ORBIT - 5
2392 // =====================
2393 if (navType() == t_eph::CNV1 ||
2394 navType() == t_eph::CNV2 ||
2395 navType() == t_eph::CNV3 ) {
2396 out << QString(fmt)
2397 .arg(_IDOT, 19, 'e', 12)
2398 .arg(_Delta_n_dot, 19, 'e', 12)
2399 .arg(_satType, 19, 'e', 12)
2400 .arg(_top, 19, 'e', 12);
2401 }
2402 else { // D1, D2, undefined
2403 out << QString(fmt)
2404 .arg(_IDOT, 19, 'e', 12)
2405 .arg("", 19, QChar(' '))
2406 .arg(_BDTweek, 19, 'e', 12)
2407 .arg("", 19, QChar(' '));
2408 }
2409 // =====================
2410 // BROADCAST ORBIT - 6
2411 // =====================
2412 if (navType() == t_eph::CNV1 ||
2413 navType() == t_eph::CNV2 ||
2414 navType() == t_eph::CNV3 ) {
2415 out << QString(fmt)
2416 .arg(_SISAI_oe, 19, 'e', 12)
2417 .arg(_SISAI_ocb, 19, 'e', 12)
2418 .arg(_SISAI_oc1, 19, 'e', 12)
2419 .arg(_SISAI_oc2, 19, 'e', 12);
2420 }
2421 else { // D1, D2, undefined
2422 out << QString(fmt)
2423 .arg(_URA, 19, 'e', 12)
2424 .arg(double(_SatH1), 19, 'e', 12)
2425 .arg(_TGD1, 19, 'e', 12)
2426 .arg(_TGD2, 19, 'e', 12);
2427 }
2428 // =====================
2429 // BROADCAST ORBIT - 7
2430 // =====================
2431 if (navType() == t_eph::CNV1) {
2432 out << QString(fmt)
2433 .arg(_ISC_B1Cd, 19, 'e', 12)
2434 .arg("", 19, QChar(' '))
2435 .arg(_TGD_B1Cp, 19, 'e', 12)
2436 .arg(_TGD_B2ap, 19, 'e', 12);
2437 }
2438 else if (navType() == t_eph::CNV2) {
2439 out << QString(fmt)
2440 .arg("", 19, QChar(' '))
2441 .arg(_ISC_B2ad, 19, 'e', 12)
2442 .arg(_TGD_B1Cp, 19, 'e', 12)
2443 .arg(_TGD_B2ap, 19, 'e', 12);
2444 }
2445 else if (navType() == t_eph::CNV3) {
2446 out << QString(fmt)
2447 .arg(_SISMAI, 19, 'e', 12)
2448 .arg(double(_health), 19, 'e', 12)
2449 .arg(_INTEGRITYF_B2b, 19, 'e', 12)
2450 .arg(_TGD_B2bI, 19, 'e', 12);
2451 }
2452 else { // D1, D2, undefined
2453 double tots = 0.0;
2454 if (_receptDateTime.isValid()) {// RTCM stream input
2455 tots = _TOE.bdssec();
2456 }
2457 else { // RINEX input
2458 tots = _TOT;
2459 }
2460 out << QString(fmt)
2461 .arg(tots, 19, 'e', 12)
2462 .arg(double(_AODC), 19, 'e', 12)
2463 .arg("", 19, QChar(' '))
2464 .arg("", 19, QChar(' '));
2465 }
2466
2467 // =====================
2468 // BROADCAST ORBIT - 8
2469 // =====================
2470 if (navType() == t_eph::CNV1) {
2471 out << QString(fmt)
2472 .arg(_SISMAI, 19, 'e', 12)
2473 .arg(double(_health), 19, 'e', 12)
2474 .arg(_INTEGRITYF_B1C, 19, 'e', 12)
2475 .arg(_IODC, 19, 'e', 12);
2476 }
2477 else if (navType() == t_eph::CNV2) {
2478 out << QString(fmt)
2479 .arg(_SISMAI, 19, 'e', 12)
2480 .arg(double(_health), 19, 'e', 12)
2481 .arg(_INTEGRITYF_B2aB1C, 19, 'e', 12)
2482 .arg(_IODC, 19, 'e', 12);
2483 }
2484 else if (navType() == t_eph::CNV3) {
2485 out << QString(fmt)
2486 .arg(_TOT, 19, 'e', 12)
2487 .arg("", 19, QChar(' '))
2488 .arg("", 19, QChar(' '))
2489 .arg("", 19, QChar(' '));
2490 }
2491
2492 // =====================
2493 // BROADCAST ORBIT - 9
2494 // =====================
2495 if (navType() == t_eph::CNV1 ||
2496 navType() == t_eph::CNV2) {
2497 out << QString(fmt)
2498 .arg(_TOT, 19, 'e', 12)
2499 .arg("", 19, QChar(' '))
2500 .arg("", 19, QChar(' '))
2501 .arg(_IODE, 19, 'e', 12);
2502 }
2503
2504
2505 return rnxStr;
2506}
Note: See TracBrowser for help on using the repository browser.