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

Last change on this file since 10904 was 10898, checked in by stuerze, 4 months ago

minor changes

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