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

Last change on this file since 10622 was 10619, checked in by stuerze, 10 days ago

IRNSS replaced by NavIC

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