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

Last change on this file since 6809 was 6809, checked in by stuerze, 9 years ago

I/NAV - F/NAV issue (hopefully:) solved in another way

File size: 48.7 KB
Line 
1#include <sstream>
2#include <iostream>
3#include <iomanip>
4#include <cstring>
5
6#include <newmatio.h>
7
8#include "ephemeris.h"
9#include "bncutils.h"
10#include "bnctime.h"
11#include "bnccore.h"
12#include "bncutils.h"
13#include "satObs.h"
14#include "pppInclude.h"
15#include "pppModel.h"
16
17using namespace std;
18
19// Constructor
20////////////////////////////////////////////////////////////////////////////
21t_eph::t_eph() {
22 _checkState = unchecked;
23 _orbCorr = 0;
24 _clkCorr = 0;
25}
26
27//
28////////////////////////////////////////////////////////////////////////////
29void t_eph::setOrbCorr(const t_orbCorr* orbCorr) {
30 delete _orbCorr;
31 _orbCorr = new t_orbCorr(*orbCorr);
32}
33
34//
35////////////////////////////////////////////////////////////////////////////
36void t_eph::setClkCorr(const t_clkCorr* clkCorr) {
37 delete _clkCorr;
38 _clkCorr = new t_clkCorr(*clkCorr);
39}
40
41//
42////////////////////////////////////////////////////////////////////////////
43t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
44
45 if (_checkState == bad) {
46 return failure;
47 }
48 const QVector<int> updateInt = QVector<int>() << 1 << 2 << 5 << 10 << 15 << 30
49 << 60 << 120 << 240 << 300 << 600
50 << 900 << 1800 << 3600 << 7200
51 << 10800;
52 xc.ReSize(4);
53 vv.ReSize(3);
54 if (position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data()) != success) {
55 return failure;
56 }
57 if (useCorr) {
58 if (_orbCorr && _clkCorr) {
59 double dtO = tt - _orbCorr->_time;
60 if (_orbCorr->_updateInt) {
61 dtO -= (0.5 * updateInt[_orbCorr->_updateInt]);
62 }
63 ColumnVector dx(3);
64 dx[0] = _orbCorr->_xr[0] + _orbCorr->_dotXr[0] * dtO;
65 dx[1] = _orbCorr->_xr[1] + _orbCorr->_dotXr[1] * dtO;
66 dx[2] = _orbCorr->_xr[2] + _orbCorr->_dotXr[2] * dtO;
67
68 if (_orbCorr->_system == 'R') {
69 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), dx, dx);
70 }
71
72 xc[0] -= dx[0];
73 xc[1] -= dx[1];
74 xc[2] -= dx[2];
75
76 double dtC = tt - _clkCorr->_time;
77 if (_clkCorr->_updateInt) {
78 dtC -= (0.5 * updateInt[_clkCorr->_updateInt]);
79 }
80 xc[3] += _clkCorr->_dClk + _clkCorr->_dotDClk * dtC + _clkCorr->_dotDotDClk * dtC * dtC;
81 }
82 else {
83 return failure;
84 }
85 }
86 return success;
87}
88
89//
90//////////////////////////////////////////////////////////////////////////////
91QString t_eph::rinexDateStr(const bncTime& tt, const t_prn& prn, double version) {
92 QString prnStr(prn.toString().c_str());
93 return rinexDateStr(tt, prnStr, version);
94}
95
96//
97//////////////////////////////////////////////////////////////////////////////
98QString t_eph::rinexDateStr(const bncTime& tt, const QString& prnStr, double version) {
99
100 QString datStr;
101
102 unsigned year, month, day, hour, min;
103 double sec;
104 tt.civil_date(year, month, day);
105 tt.civil_time(hour, min, sec);
106
107 QTextStream out(&datStr);
108
109 if (version < 3.0) {
110 QString prnHlp = prnStr.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
111 out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
112 .arg(year % 100, 2, 10, QChar('0'))
113 .arg(month, 2)
114 .arg(day, 2)
115 .arg(hour, 2)
116 .arg(min, 2)
117 .arg(sec, 5, 'f',1);
118 }
119 else {
120 out << prnStr << QString(" %1 %2 %3 %4 %5 %6")
121 .arg(year, 4)
122 .arg(month, 2, 10, QChar('0'))
123 .arg(day, 2, 10, QChar('0'))
124 .arg(hour, 2, 10, QChar('0'))
125 .arg(min, 2, 10, QChar('0'))
126 .arg(int(sec), 2, 10, QChar('0'));
127 }
128
129 return datStr;
130}
131
132// Constructor
133//////////////////////////////////////////////////////////////////////////////
134t_ephGPS::t_ephGPS(float rnxVersion, const QStringList& lines) {
135
136 const int nLines = 8;
137
138 if (lines.size() != nLines) {
139 _checkState = bad;
140 return;
141 }
142
143 // RINEX Format
144 // ------------
145 int fieldLen = 19;
146
147 int pos[4];
148 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
149 pos[1] = pos[0] + fieldLen;
150 pos[2] = pos[1] + fieldLen;
151 pos[3] = pos[2] + fieldLen;
152
153 // Read eight lines
154 // ----------------
155 for (int iLine = 0; iLine < nLines; iLine++) {
156 QString line = lines[iLine];
157
158 if ( iLine == 0 ) {
159 QTextStream in(line.left(pos[1]).toAscii());
160
161 int year, month, day, hour, min;
162 double sec;
163
164 QString prnStr;
165 in >> prnStr >> year >> month >> day >> hour >> min >> sec;
166 if (prnStr.at(0) == 'G') {
167 _prn.set('G', prnStr.mid(1).toInt());
168 }
169 else if (prnStr.at(0) == 'J') {
170 _prn.set('J', prnStr.mid(1).toInt());
171 }
172 else {
173 _prn.set('G', prnStr.toInt());
174 }
175
176 if (year < 80) {
177 year += 2000;
178 }
179 else if (year < 100) {
180 year += 1900;
181 }
182
183 _TOC.set(year, month, day, hour, min, sec);
184
185 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
186 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
187 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
188 _checkState = bad;
189 return;
190 }
191 }
192
193 else if ( iLine == 1 ) {
194 if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
195 readDbl(line, pos[1], fieldLen, _Crs ) ||
196 readDbl(line, pos[2], fieldLen, _Delta_n) ||
197 readDbl(line, pos[3], fieldLen, _M0 ) ) {
198 _checkState = bad;
199 return;
200 }
201 }
202
203 else if ( iLine == 2 ) {
204 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
205 readDbl(line, pos[1], fieldLen, _e ) ||
206 readDbl(line, pos[2], fieldLen, _Cus ) ||
207 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
208 _checkState = bad;
209 return;
210 }
211 }
212
213 else if ( iLine == 3 ) {
214 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
215 readDbl(line, pos[1], fieldLen, _Cic ) ||
216 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
217 readDbl(line, pos[3], fieldLen, _Cis ) ) {
218 _checkState = bad;
219 return;
220 }
221 }
222
223 else if ( iLine == 4 ) {
224 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
225 readDbl(line, pos[1], fieldLen, _Crc ) ||
226 readDbl(line, pos[2], fieldLen, _omega ) ||
227 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
228 _checkState = bad;
229 return;
230 }
231 }
232
233 else if ( iLine == 5 ) {
234 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
235 readDbl(line, pos[1], fieldLen, _L2Codes) ||
236 readDbl(line, pos[2], fieldLen, _TOEweek ) ||
237 readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
238 _checkState = bad;
239 return;
240 }
241 }
242
243 else if ( iLine == 6 ) {
244 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
245 readDbl(line, pos[1], fieldLen, _health) ||
246 readDbl(line, pos[2], fieldLen, _TGD ) ||
247 readDbl(line, pos[3], fieldLen, _IODC ) ) {
248 _checkState = bad;
249 return;
250 }
251 }
252
253 else if ( iLine == 7 ) {
254 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
255 _checkState = bad;
256 return;
257 }
258 readDbl(line, pos[1], fieldLen, _fitInterval); // _fitInterval optional
259 }
260 }
261}
262
263// Set GPS Satellite Position
264////////////////////////////////////////////////////////////////////////////
265void t_ephGPS::set(const gpsephemeris* ee) {
266
267 _receptDateTime = currentDateAndTimeGPS();
268
269 if (PRN_GPS_START <= ee->satellite && ee->satellite <= PRN_GPS_END) {
270 _prn.set('G', ee->satellite);
271 }
272 else if (PRN_QZSS_START <= ee->satellite && ee->satellite <= PRN_QZSS_END) {
273 _prn.set('J', ee->satellite - PRN_QZSS_START + 1);
274 }
275 else {
276 _checkState = bad;
277 return;
278 }
279
280 _TOC.set(ee->GPSweek, ee->TOC);
281 _clock_bias = ee->clock_bias;
282 _clock_drift = ee->clock_drift;
283 _clock_driftrate = ee->clock_driftrate;
284
285 _IODE = ee->IODE;
286 _Crs = ee->Crs;
287 _Delta_n = ee->Delta_n;
288 _M0 = ee->M0;
289
290 _Cuc = ee->Cuc;
291 _e = ee->e;
292 _Cus = ee->Cus;
293 _sqrt_A = ee->sqrt_A;
294
295 _TOEsec = ee->TOE;
296 _Cic = ee->Cic;
297 _OMEGA0 = ee->OMEGA0;
298 _Cis = ee->Cis;
299
300 _i0 = ee->i0;
301 _Crc = ee->Crc;
302 _omega = ee->omega;
303 _OMEGADOT = ee->OMEGADOT;
304
305 _IDOT = ee->IDOT;
306 _L2Codes = 0.0;
307 _TOEweek = ee->GPSweek;
308 _L2PFlag = 0.0;
309
310 _ura = accuracyFromIndex(ee->URAindex, type());
311
312 _health = ee->SVhealth;
313 _TGD = ee->TGD;
314 _IODC = ee->IODC;
315
316 _TOT = 0.9999e9;
317 _fitInterval = 0.0;
318}
319
320// Compute GPS Satellite Position (virtual)
321////////////////////////////////////////////////////////////////////////////
322t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
323
324 if (_checkState == bad) {
325 return failure;
326 }
327
328 static const double omegaEarth = 7292115.1467e-11;
329 static const double gmGRS = 398.6005e12;
330
331 memset(xc, 0, 4*sizeof(double));
332 memset(vv, 0, 3*sizeof(double));
333
334 double a0 = _sqrt_A * _sqrt_A;
335 if (a0 == 0) {
336 return failure;
337 }
338
339 double n0 = sqrt(gmGRS/(a0*a0*a0));
340
341 bncTime tt(GPSweek, GPSweeks);
342 double tk = tt - bncTime(int(_TOEweek), _TOEsec);
343
344 double n = n0 + _Delta_n;
345 double M = _M0 + n*tk;
346 double E = M;
347 double E_last;
348 do {
349 E_last = E;
350 E = M + _e*sin(E);
351 } while ( fabs(E-E_last)*a0 > 0.001 );
352 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
353 double u0 = v + _omega;
354 double sin2u0 = sin(2*u0);
355 double cos2u0 = cos(2*u0);
356 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
357 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
358 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
359 double xp = r*cos(u);
360 double yp = r*sin(u);
361 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
362 omegaEarth*_TOEsec;
363
364 double sinom = sin(OM);
365 double cosom = cos(OM);
366 double sini = sin(i);
367 double cosi = cos(i);
368 xc[0] = xp*cosom - yp*cosi*sinom;
369 xc[1] = xp*sinom + yp*cosi*cosom;
370 xc[2] = yp*sini;
371
372 double tc = tt - _TOC;
373 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
374
375 // Velocity
376 // --------
377 double tanv2 = tan(v/2);
378 double dEdM = 1 / (1 - _e*cos(E));
379 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
380 * dEdM * n;
381 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
382 double dotom = _OMEGADOT - omegaEarth;
383 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
384 double dotr = a0 * _e*sin(E) * dEdM * n
385 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
386 double dotx = dotr*cos(u) - r*sin(u)*dotu;
387 double doty = dotr*sin(u) + r*cos(u)*dotu;
388
389 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
390 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
391 + yp*sini*sinom*doti; // dX / di
392
393 vv[1] = sinom *dotx + cosi*cosom *doty
394 + xp*cosom*dotom - yp*cosi*sinom*dotom
395 - yp*sini*cosom*doti;
396
397 vv[2] = sini *doty + yp*cosi *doti;
398
399 // Relativistic Correction
400 // -----------------------
401 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
402
403 return success;
404}
405
406// RINEX Format String
407//////////////////////////////////////////////////////////////////////////////
408QString t_ephGPS::toString(double version) const {
409
410 QString rnxStr = rinexDateStr(_TOC, _prn, version);
411
412 QTextStream out(&rnxStr);
413
414 out << QString("%1%2%3\n")
415 .arg(_clock_bias, 19, 'e', 12)
416 .arg(_clock_drift, 19, 'e', 12)
417 .arg(_clock_driftrate, 19, 'e', 12);
418
419 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
420
421 out << QString(fmt)
422 .arg(_IODE, 19, 'e', 12)
423 .arg(_Crs, 19, 'e', 12)
424 .arg(_Delta_n, 19, 'e', 12)
425 .arg(_M0, 19, 'e', 12);
426
427 out << QString(fmt)
428 .arg(_Cuc, 19, 'e', 12)
429 .arg(_e, 19, 'e', 12)
430 .arg(_Cus, 19, 'e', 12)
431 .arg(_sqrt_A, 19, 'e', 12);
432
433 out << QString(fmt)
434 .arg(_TOEsec, 19, 'e', 12)
435 .arg(_Cic, 19, 'e', 12)
436 .arg(_OMEGA0, 19, 'e', 12)
437 .arg(_Cis, 19, 'e', 12);
438
439 out << QString(fmt)
440 .arg(_i0, 19, 'e', 12)
441 .arg(_Crc, 19, 'e', 12)
442 .arg(_omega, 19, 'e', 12)
443 .arg(_OMEGADOT, 19, 'e', 12);
444
445 out << QString(fmt)
446 .arg(_IDOT, 19, 'e', 12)
447 .arg(_L2Codes, 19, 'e', 12)
448 .arg(_TOEweek, 19, 'e', 12)
449 .arg(_L2PFlag, 19, 'e', 12);
450
451 out << QString(fmt)
452 .arg(_ura, 19, 'e', 12)
453 .arg(_health, 19, 'e', 12)
454 .arg(_TGD, 19, 'e', 12)
455 .arg(_IODC, 19, 'e', 12);
456
457 out << QString(fmt)
458 .arg(_TOT, 19, 'e', 12)
459 .arg(_fitInterval, 19, 'e', 12)
460 .arg("", 19, QChar(' '))
461 .arg("", 19, QChar(' '));
462
463 return rnxStr;
464}
465
466// Constructor
467//////////////////////////////////////////////////////////////////////////////
468t_ephGlo::t_ephGlo(float rnxVersion, const QStringList& lines) {
469
470 const int nLines = 4;
471
472 if (lines.size() != nLines) {
473 _checkState = bad;
474 return;
475 }
476
477 // RINEX Format
478 // ------------
479 int fieldLen = 19;
480
481 int pos[4];
482 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
483 pos[1] = pos[0] + fieldLen;
484 pos[2] = pos[1] + fieldLen;
485 pos[3] = pos[2] + fieldLen;
486
487 // Read four lines
488 // ---------------
489 for (int iLine = 0; iLine < nLines; iLine++) {
490 QString line = lines[iLine];
491
492 if ( iLine == 0 ) {
493 QTextStream in(line.left(pos[1]).toAscii());
494
495 int year, month, day, hour, min;
496 double sec;
497
498 QString prnStr;
499 in >> prnStr >> year >> month >> day >> hour >> min >> sec;
500 if (prnStr.at(0) == 'R') {
501 _prn.set('R', prnStr.mid(1).toInt());
502 }
503 else {
504 _prn.set('R', prnStr.toInt());
505 }
506
507 if (year < 80) {
508 year += 2000;
509 }
510 else if (year < 100) {
511 year += 1900;
512 }
513
514 _gps_utc = gnumleap(year, month, day);
515
516 _TOC.set(year, month, day, hour, min, sec);
517 _TOC = _TOC + _gps_utc;
518
519 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
520 readDbl(line, pos[2], fieldLen, _gamma) ||
521 readDbl(line, pos[3], fieldLen, _tki ) ) {
522 _checkState = bad;
523 return;
524 }
525
526 _tau = -_tau;
527 }
528
529 else if ( iLine == 1 ) {
530 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
531 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
532 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
533 readDbl(line, pos[3], fieldLen, _health ) ) {
534 _checkState = bad;
535 return;
536 }
537 }
538
539 else if ( iLine == 2 ) {
540 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
541 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
542 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
543 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
544 _checkState = bad;
545 return;
546 }
547 }
548
549 else if ( iLine == 3 ) {
550 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
551 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
552 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
553 readDbl(line, pos[3], fieldLen, _E ) ) {
554 _checkState = bad;
555 return;
556 }
557 }
558 }
559
560 // Initialize status vector
561 // ------------------------
562 _tt = _TOC;
563 _xv.ReSize(6);
564 _xv(1) = _x_pos * 1.e3;
565 _xv(2) = _y_pos * 1.e3;
566 _xv(3) = _z_pos * 1.e3;
567 _xv(4) = _x_velocity * 1.e3;
568 _xv(5) = _y_velocity * 1.e3;
569 _xv(6) = _z_velocity * 1.e3;
570}
571
572// Set Glonass Ephemeris
573////////////////////////////////////////////////////////////////////////////
574void t_ephGlo::set(const glonassephemeris* ee) {
575
576 _receptDateTime = currentDateAndTimeGPS();
577
578 _prn.set('R', ee->almanac_number);
579
580 int ww = ee->GPSWeek;
581 int tow = ee->GPSTOW;
582 updatetime(&ww, &tow, ee->tb*1000, 0); // Moscow -> GPS
583
584 // Check the day once more
585 // -----------------------
586 bool timeChanged = false;
587 {
588 const double secPerDay = 24 * 3600.0;
589 const double secPerWeek = 7 * secPerDay;
590 int ww_old = ww;
591 int tow_old = tow;
592 int currentWeek;
593 double currentSec;
594 currentGPSWeeks(currentWeek, currentSec);
595 bncTime currentTime(currentWeek, currentSec);
596 bncTime hTime(ww, (double) tow);
597
598 if (hTime - currentTime > secPerDay/2.0) {
599 timeChanged = true;
600 tow -= int(secPerDay);
601 if (tow < 0) {
602 tow += int(secPerWeek);
603 ww -= 1;
604 }
605 }
606 else if (hTime - currentTime < -secPerDay/2.0) {
607 timeChanged = true;
608 tow += int(secPerDay);
609 if (tow > secPerWeek) {
610 tow -= int(secPerWeek);
611 ww += 1;
612 }
613 }
614
615 if (false && timeChanged && BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
616 bncTime newHTime(ww, (double) tow);
617 cout << "GLONASS " << ee->almanac_number << " Time Changed at "
618 << currentTime.datestr() << " " << currentTime.timestr()
619 << endl
620 << "old: " << hTime.datestr() << " " << hTime.timestr()
621 << endl
622 << "new: " << newHTime.datestr() << " " << newHTime.timestr()
623 << endl
624 << "eph: " << ee->GPSWeek << " " << ee->GPSTOW << " " << ee->tb
625 << endl
626 << "ww, tow (old): " << ww_old << " " << tow_old
627 << endl
628 << "ww, tow (new): " << ww << " " << tow
629 << endl << endl;
630 }
631 }
632
633 bncTime hlpTime(ww, (double) tow);
634 unsigned year, month, day;
635 hlpTime.civil_date(year, month, day);
636 _gps_utc = gnumleap(year, month, day);
637
638 _TOC.set(ww, tow);
639 _E = ee->E;
640 _tau = ee->tau;
641 _gamma = ee->gamma;
642 _x_pos = ee->x_pos;
643 _x_velocity = ee->x_velocity;
644 _x_acceleration = ee->x_acceleration;
645 _y_pos = ee->y_pos;
646 _y_velocity = ee->y_velocity;
647 _y_acceleration = ee->y_acceleration;
648 _z_pos = ee->z_pos;
649 _z_velocity = ee->z_velocity;
650 _z_acceleration = ee->z_acceleration;
651 _health = 0;
652 _frequency_number = ee->frequency_number;
653 _tki = ee->tk-3*60*60; if (_tki < 0) _tki += 86400;
654
655 // Initialize status vector
656 // ------------------------
657 _tt = _TOC;
658
659 _xv(1) = _x_pos * 1.e3;
660 _xv(2) = _y_pos * 1.e3;
661 _xv(3) = _z_pos * 1.e3;
662 _xv(4) = _x_velocity * 1.e3;
663 _xv(5) = _y_velocity * 1.e3;
664 _xv(6) = _z_velocity * 1.e3;
665}
666
667// Compute Glonass Satellite Position (virtual)
668////////////////////////////////////////////////////////////////////////////
669t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
670
671 if (_checkState == bad) {
672 return failure;
673 }
674
675 static const double nominalStep = 10.0;
676
677 memset(xc, 0, 4*sizeof(double));
678 memset(vv, 0, 3*sizeof(double));
679
680 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
681
682 if (fabs(dtPos) > 24*3600.0) {
683 return failure;
684 }
685
686 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
687 double step = dtPos / nSteps;
688
689 double acc[3];
690 acc[0] = _x_acceleration * 1.e3;
691 acc[1] = _y_acceleration * 1.e3;
692 acc[2] = _z_acceleration * 1.e3;
693 for (int ii = 1; ii <= nSteps; ii++) {
694 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
695 _tt = _tt + step;
696 }
697
698 // Position and Velocity
699 // ---------------------
700 xc[0] = _xv(1);
701 xc[1] = _xv(2);
702 xc[2] = _xv(3);
703
704 vv[0] = _xv(4);
705 vv[1] = _xv(5);
706 vv[2] = _xv(6);
707
708 // Clock Correction
709 // ----------------
710 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
711 xc[3] = -_tau + _gamma * dtClk;
712
713 return success;
714}
715
716// RINEX Format String
717//////////////////////////////////////////////////////////////////////////////
718QString t_ephGlo::toString(double version) const {
719
720 QString rnxStr = rinexDateStr(_TOC-_gps_utc, _prn, version);
721
722 QTextStream out(&rnxStr);
723
724 out << QString("%1%2%3\n")
725 .arg(-_tau, 19, 'e', 12)
726 .arg(_gamma, 19, 'e', 12)
727 .arg(_tki, 19, 'e', 12);
728
729 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
730
731 out << QString(fmt)
732 .arg(_x_pos, 19, 'e', 12)
733 .arg(_x_velocity, 19, 'e', 12)
734 .arg(_x_acceleration, 19, 'e', 12)
735 .arg(_health, 19, 'e', 12);
736
737 out << QString(fmt)
738 .arg(_y_pos, 19, 'e', 12)
739 .arg(_y_velocity, 19, 'e', 12)
740 .arg(_y_acceleration, 19, 'e', 12)
741 .arg(_frequency_number, 19, 'e', 12);
742
743 out << QString(fmt)
744 .arg(_z_pos, 19, 'e', 12)
745 .arg(_z_velocity, 19, 'e', 12)
746 .arg(_z_acceleration, 19, 'e', 12)
747 .arg(_E, 19, 'e', 12);
748
749 return rnxStr;
750}
751
752// Derivative of the state vector using a simple force model (static)
753////////////////////////////////////////////////////////////////////////////
754ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
755 double* acc) {
756
757 // State vector components
758 // -----------------------
759 ColumnVector rr = xv.rows(1,3);
760 ColumnVector vv = xv.rows(4,6);
761
762 // Acceleration
763 // ------------
764 static const double gmWGS = 398.60044e12;
765 static const double AE = 6378136.0;
766 static const double OMEGA = 7292115.e-11;
767 static const double C20 = -1082.6257e-6;
768
769 double rho = rr.norm_Frobenius();
770 double t1 = -gmWGS/(rho*rho*rho);
771 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
772 double t3 = OMEGA * OMEGA;
773 double t4 = 2.0 * OMEGA;
774 double z2 = rr(3) * rr(3);
775
776 // Vector of derivatives
777 // ---------------------
778 ColumnVector va(6);
779 va(1) = vv(1);
780 va(2) = vv(2);
781 va(3) = vv(3);
782 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
783 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
784 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
785
786 return va;
787}
788
789// IOD of Glonass Ephemeris (virtual)
790////////////////////////////////////////////////////////////////////////////
791int t_ephGlo::IOD() const {
792 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
793 return int(tMoscow.daysec() / 900);
794}
795
796// Constructor
797//////////////////////////////////////////////////////////////////////////////
798t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
799 int year, month, day, hour, min;
800 double sec;
801 QString prnStr;
802 const int nLines = 8;
803 if (lines.size() != nLines) {
804 _checkState = bad;
805 return;
806 }
807 _flags = 0;
808
809 // RINEX Format
810 // ------------
811 int fieldLen = 19;
812 double SVhealth = 0.0;
813 double datasource = 0.0;
814
815 int pos[4];
816 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
817 pos[1] = pos[0] + fieldLen;
818 pos[2] = pos[1] + fieldLen;
819 pos[3] = pos[2] + fieldLen;
820
821 // Read eight lines
822 // ----------------
823 for (int iLine = 0; iLine < nLines; iLine++) {
824 QString line = lines[iLine];
825
826 if ( iLine == 0 ) {
827 QTextStream in(line.left(pos[1]).toAscii());
828
829 in >> prnStr >> year >> month >> day >> hour >> min >> sec;
830 if (year < 80) {
831 year += 2000;
832 }
833 else if (year < 100) {
834 year += 1900;
835 }
836
837 _TOC.set(year, month, day, hour, min, sec);
838
839 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
840 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
841 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
842 _checkState = bad;
843 return;
844 }
845 }
846
847 else if ( iLine == 1 ) {
848 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
849 readDbl(line, pos[1], fieldLen, _Crs ) ||
850 readDbl(line, pos[2], fieldLen, _Delta_n) ||
851 readDbl(line, pos[3], fieldLen, _M0 ) ) {
852 _checkState = bad;
853 return;
854 }
855 }
856
857 else if ( iLine == 2 ) {
858 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
859 readDbl(line, pos[1], fieldLen, _e ) ||
860 readDbl(line, pos[2], fieldLen, _Cus ) ||
861 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
862 _checkState = bad;
863 return;
864 }
865 }
866
867 else if ( iLine == 3 ) {
868 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
869 readDbl(line, pos[1], fieldLen, _Cic ) ||
870 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
871 readDbl(line, pos[3], fieldLen, _Cis ) ) {
872 _checkState = bad;
873 return;
874 }
875 }
876
877 else if ( iLine == 4 ) {
878 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
879 readDbl(line, pos[1], fieldLen, _Crc ) ||
880 readDbl(line, pos[2], fieldLen, _omega ) ||
881 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
882 _checkState = bad;
883 return;
884 }
885 }
886
887 else if ( iLine == 5 ) {
888 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
889 readDbl(line, pos[1], fieldLen, datasource) ||
890 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
891 _checkState = bad;
892 return;
893 } else {
894 if (int(datasource) & (1<<8)) {
895 _flags |= GALEPHF_FNAV;
896 } else if (int(datasource) & (1<<9)) {
897 _flags |= GALEPHF_INAV;
898 }
899 }
900 }
901
902 else if ( iLine == 6 ) {
903 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
904 readDbl(line, pos[1], fieldLen, SVhealth) ||
905 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
906 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
907 _checkState = bad;
908 return;
909 } else {
910 // Bit 0
911 if (int(SVhealth) & (1<<0)) {
912 _flags |= GALEPHF_E1DINVALID;
913 }
914 // Bit 1-2
915 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
916 // Bit 3
917 if (int(SVhealth) & (1<<3)) {
918 _flags |= GALEPHF_E5ADINVALID;
919 }
920 // Bit 4-5
921 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
922 // Bit 6
923 if (int(SVhealth) & (1<<6)) {
924 _flags |= GALEPHF_E5BDINVALID;
925 }
926 // Bit 7-8
927 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
928
929 if (prnStr.at(0) == 'E') {
930 _prn.set('E', prnStr.mid(1,2).toInt(), _flags);
931 }
932 else {
933 _prn.set('E', prnStr.mid(1,2).toInt(), _flags);
934 }
935 }
936 }
937
938 else if ( iLine == 7 ) {
939 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
940 _checkState = bad;
941 return;
942 }
943 }
944 }
945}
946
947// Set Galileo Satellite Position
948////////////////////////////////////////////////////////////////////////////
949void t_ephGal::set(const galileoephemeris* ee) {
950
951 _receptDateTime = currentDateAndTimeGPS();
952
953 _flags = ee->flags;
954 _prn.set('E', ee->satellite, _flags);
955
956 _TOC.set(ee->Week, ee->TOC);
957 _clock_bias = ee->clock_bias;
958 _clock_drift = ee->clock_drift;
959 _clock_driftrate = ee->clock_driftrate;
960
961 _IODnav = ee->IODnav;
962 _Crs = ee->Crs;
963 _Delta_n = ee->Delta_n;
964 _M0 = ee->M0;
965
966 _Cuc = ee->Cuc;
967 _e = ee->e;
968 _Cus = ee->Cus;
969 _sqrt_A = ee->sqrt_A;
970
971 _TOEsec = _TOC.gpssec();
972 // _TOEsec = ee->TOE; // TODO:
973
974 _Cic = ee->Cic;
975 _OMEGA0 = ee->OMEGA0;
976 _Cis = ee->Cis;
977
978 _i0 = ee->i0;
979 _Crc = ee->Crc;
980 _omega = ee->omega;
981 _OMEGADOT = ee->OMEGADOT;
982
983 _IDOT = ee->IDOT;
984 _TOEweek = ee->Week;
985
986 _SISA = accuracyFromIndex(ee->SISA, type());
987 _E5aHS = ee->E5aHS;
988 _E5bHS = ee->E5bHS;
989 _E1_bHS = ee->E1_HS;
990 _BGD_1_5A = ee->BGD_1_5A;
991 _BGD_1_5B = ee->BGD_1_5B;
992
993 _TOT = 0.9999e9;
994}
995
996// Compute Galileo Satellite Position (virtual)
997////////////////////////////////////////////////////////////////////////////
998t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
999
1000 if (_checkState == bad) {
1001 return failure;
1002 }
1003
1004 static const double omegaEarth = 7292115.1467e-11;
1005 static const double gmWGS = 398.60044e12;
1006
1007 memset(xc, 0, 4*sizeof(double));
1008 memset(vv, 0, 3*sizeof(double));
1009
1010 double a0 = _sqrt_A * _sqrt_A;
1011 if (a0 == 0) {
1012 return failure;
1013 }
1014
1015 double n0 = sqrt(gmWGS/(a0*a0*a0));
1016
1017 bncTime tt(GPSweek, GPSweeks);
1018 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
1019
1020 double n = n0 + _Delta_n;
1021 double M = _M0 + n*tk;
1022 double E = M;
1023 double E_last;
1024 do {
1025 E_last = E;
1026 E = M + _e*sin(E);
1027 } while ( fabs(E-E_last)*a0 > 0.001 );
1028 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
1029 double u0 = v + _omega;
1030 double sin2u0 = sin(2*u0);
1031 double cos2u0 = cos(2*u0);
1032 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1033 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1034 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1035 double xp = r*cos(u);
1036 double yp = r*sin(u);
1037 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
1038 omegaEarth*_TOEsec;
1039
1040 double sinom = sin(OM);
1041 double cosom = cos(OM);
1042 double sini = sin(i);
1043 double cosi = cos(i);
1044 xc[0] = xp*cosom - yp*cosi*sinom;
1045 xc[1] = xp*sinom + yp*cosi*cosom;
1046 xc[2] = yp*sini;
1047
1048 double tc = tt - _TOC;
1049 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1050
1051 // Velocity
1052 // --------
1053 double tanv2 = tan(v/2);
1054 double dEdM = 1 / (1 - _e*cos(E));
1055 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
1056 * dEdM * n;
1057 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1058 double dotom = _OMEGADOT - omegaEarth;
1059 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1060 double dotr = a0 * _e*sin(E) * dEdM * n
1061 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1062 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1063 double doty = dotr*sin(u) + r*cos(u)*dotu;
1064
1065 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1066 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1067 + yp*sini*sinom*doti; // dX / di
1068
1069 vv[1] = sinom *dotx + cosi*cosom *doty
1070 + xp*cosom*dotom - yp*cosi*sinom*dotom
1071 - yp*sini*cosom*doti;
1072
1073 vv[2] = sini *doty + yp*cosi *doti;
1074
1075 // Relativistic Correction
1076 // -----------------------
1077 // xc(4) -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1078 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
1079
1080 return success;
1081}
1082
1083// RINEX Format String
1084//////////////////////////////////////////////////////////////////////////////
1085QString t_ephGal::toString(double version) const {
1086
1087 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1088
1089 QTextStream out(&rnxStr);
1090
1091 out << QString("%1%2%3\n")
1092 .arg(_clock_bias, 19, 'e', 12)
1093 .arg(_clock_drift, 19, 'e', 12)
1094 .arg(_clock_driftrate, 19, 'e', 12);
1095
1096 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1097
1098 out << QString(fmt)
1099 .arg(_IODnav, 19, 'e', 12)
1100 .arg(_Crs, 19, 'e', 12)
1101 .arg(_Delta_n, 19, 'e', 12)
1102 .arg(_M0, 19, 'e', 12);
1103
1104 out << QString(fmt)
1105 .arg(_Cuc, 19, 'e', 12)
1106 .arg(_e, 19, 'e', 12)
1107 .arg(_Cus, 19, 'e', 12)
1108 .arg(_sqrt_A, 19, 'e', 12);
1109
1110 out << QString(fmt)
1111 .arg(_TOEsec, 19, 'e', 12)
1112 .arg(_Cic, 19, 'e', 12)
1113 .arg(_OMEGA0, 19, 'e', 12)
1114 .arg(_Cis, 19, 'e', 12);
1115
1116 out << QString(fmt)
1117 .arg(_i0, 19, 'e', 12)
1118 .arg(_Crc, 19, 'e', 12)
1119 .arg(_omega, 19, 'e', 12)
1120 .arg(_OMEGADOT, 19, 'e', 12);
1121
1122 int dataSource = 0;
1123 int SVhealth = 0;
1124 double BGD_1_5A = _BGD_1_5A;
1125 double BGD_1_5B = _BGD_1_5B;
1126 if ((_flags & GALEPHF_FNAV) == GALEPHF_FNAV) {
1127 dataSource |= (1<<1);
1128 dataSource |= (1<<8);
1129 BGD_1_5B = 0.0;
1130 // SVhealth
1131 // Bit 3 : E5a DVS
1132 if ((_flags & GALEPHF_E5ADINVALID) == GALEPHF_E5ADINVALID) {
1133 SVhealth |= (1<<3);
1134 }
1135 // Bit 4-5: E5a HS
1136 if (_E5aHS == 1.0) {
1137 SVhealth |= (1<<4);
1138 }
1139 else if (_E5aHS == 2.0) {
1140 SVhealth |= (1<<5);
1141 }
1142 else if (_E5aHS == 3.0) {
1143 SVhealth |= (1<<4);
1144 SVhealth |= (1<<5);
1145 }
1146 }
1147 else if ((_flags & GALEPHF_INAV) == GALEPHF_INAV) {
1148 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1149 // and RNXv3.03 says both can be set if the navigation messages were merged
1150 dataSource |= (1<<0);
1151 dataSource |= (1<<2);
1152 dataSource |= (1<<9);
1153 // SVhealth
1154 // Bit 0 : E1-B DVS
1155 if ((_flags & GALEPHF_E1DINVALID) == GALEPHF_E1DINVALID) {
1156 SVhealth |= (1<<0);
1157 }
1158 // Bit 1-2: E1-B HS
1159 if (_E1_bHS == 1.0) {
1160 SVhealth |= (1<<1);
1161 }
1162 else if (_E1_bHS == 2.0) {
1163 SVhealth |= (1<<2);
1164 }
1165 else if (_E1_bHS == 3.0) {
1166 SVhealth |= (1<<1);
1167 SVhealth |= (1<<2);
1168 }
1169 // Bit 3 : E5a DVS
1170 if ((_flags & GALEPHF_E5ADINVALID) == GALEPHF_E5ADINVALID) {
1171 SVhealth |= (1<<3);
1172 }
1173 // Bit 4-5: E5a HS
1174 if (_E5aHS == 1.0) {
1175 SVhealth |= (1<<4);
1176 }
1177 else if (_E5aHS == 2.0) {
1178 SVhealth |= (1<<5);
1179 }
1180 else if (_E5aHS == 3.0) {
1181 SVhealth |= (1<<4);
1182 SVhealth |= (1<<5);
1183 }
1184 // Bit 6 : E5b DVS
1185 if ((_flags & GALEPHF_E5BDINVALID) == GALEPHF_E5BDINVALID) {
1186 SVhealth |= (1<<6);
1187 }
1188 // Bit 7-8: E5b HS
1189 if (_E5bHS == 1.0) {
1190 SVhealth |= (1<<7);
1191 }
1192 else if (_E5bHS == 2.0) {
1193 SVhealth |= (1<<8);
1194 }
1195 else if (_E5bHS == 3.0) {
1196 SVhealth |= (1<<7);
1197 SVhealth |= (1<<8);
1198 }
1199 }
1200
1201 out << QString(fmt)
1202 .arg(_IDOT, 19, 'e', 12)
1203 .arg(double(dataSource), 19, 'e', 12)
1204 .arg(_TOEweek, 19, 'e', 12)
1205 .arg(0.0, 19, 'e', 12);
1206
1207 out << QString(fmt)
1208 .arg(_SISA, 19, 'e', 12)
1209 .arg(double(SVhealth), 19, 'e', 12)
1210 .arg(BGD_1_5A, 19, 'e', 12)
1211 .arg(BGD_1_5B, 19, 'e', 12);
1212
1213 out << QString(fmt)
1214 .arg(_TOT, 19, 'e', 12)
1215 .arg("", 19, QChar(' '))
1216 .arg("", 19, QChar(' '))
1217 .arg("", 19, QChar(' '));
1218
1219 return rnxStr;
1220}
1221
1222// Constructor
1223//////////////////////////////////////////////////////////////////////////////
1224t_ephSBAS::t_ephSBAS(float rnxVersion, const QStringList& lines) {
1225
1226 const int nLines = 4;
1227
1228 if (lines.size() != nLines) {
1229 _checkState = bad;
1230 return;
1231 }
1232
1233 // RINEX Format
1234 // ------------
1235 int fieldLen = 19;
1236
1237 int pos[4];
1238 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1239 pos[1] = pos[0] + fieldLen;
1240 pos[2] = pos[1] + fieldLen;
1241 pos[3] = pos[2] + fieldLen;
1242
1243 // Read four lines
1244 // ---------------
1245 for (int iLine = 0; iLine < nLines; iLine++) {
1246 QString line = lines[iLine];
1247
1248 if ( iLine == 0 ) {
1249 QTextStream in(line.left(pos[1]).toAscii());
1250
1251 int year, month, day, hour, min;
1252 double sec;
1253
1254 QString prnStr;
1255 in >> prnStr >> year >> month >> day >> hour >> min >> sec;
1256 if (prnStr.at(0) == 'S') {
1257 _prn.set('S', prnStr.mid(1).toInt());
1258 }
1259 else {
1260 _prn.set('S', prnStr.toInt());
1261 }
1262
1263 if (year < 80) {
1264 year += 2000;
1265 }
1266 else if (year < 100) {
1267 year += 1900;
1268 }
1269
1270 _TOC.set(year, month, day, hour, min, sec);
1271
1272 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1273 readDbl(line, pos[2], fieldLen, _agf1 ) ||
1274 readDbl(line, pos[3], fieldLen, _TOW ) ) {
1275 _checkState = bad;
1276 return;
1277 }
1278 }
1279
1280 else if ( iLine == 1 ) {
1281 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1282 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1283 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1284 readDbl(line, pos[3], fieldLen, _health ) ) {
1285 _checkState = bad;
1286 return;
1287 }
1288 }
1289
1290 else if ( iLine == 2 ) {
1291 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1292 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1293 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1294 readDbl(line, pos[3], fieldLen, _ura ) ) {
1295 _checkState = bad;
1296 return;
1297 }
1298 }
1299
1300 else if ( iLine == 3 ) {
1301 double iodn;
1302 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1303 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1304 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
1305 readDbl(line, pos[3], fieldLen, iodn ) ) {
1306 _checkState = bad;
1307 return;
1308 _IODN = int(iodn);
1309 }
1310 }
1311 }
1312
1313 _x_pos *= 1.e3;
1314 _y_pos *= 1.e3;
1315 _z_pos *= 1.e3;
1316 _x_velocity *= 1.e3;
1317 _y_velocity *= 1.e3;
1318 _z_velocity *= 1.e3;
1319 _x_acceleration *= 1.e3;
1320 _y_acceleration *= 1.e3;
1321 _z_acceleration *= 1.e3;
1322}
1323
1324// Set SBAS Satellite Position
1325////////////////////////////////////////////////////////////////////////////
1326void t_ephSBAS::set(const sbasephemeris* ee) {
1327
1328 _prn.set('S', ee->satellite - PRN_SBAS_START + 20);
1329 _TOC.set(ee->GPSweek_TOE, double(ee->TOE));
1330
1331 _IODN = ee->IODN;
1332 _TOW = ee->TOW;
1333
1334 _agf0 = ee->agf0;
1335 _agf1 = ee->agf1;
1336
1337 _x_pos = ee->x_pos;
1338 _x_velocity = ee->x_velocity;
1339 _x_acceleration = ee->x_acceleration;
1340
1341 _y_pos = ee->y_pos;
1342 _y_velocity = ee->y_velocity;
1343 _y_acceleration = ee->y_acceleration;
1344
1345 _z_pos = ee->z_pos;
1346 _z_velocity = ee->z_velocity;
1347 _z_acceleration = ee->z_acceleration;
1348
1349 _ura = accuracyFromIndex(ee->URA, type());
1350
1351 _health = 0;
1352}
1353
1354// Compute SBAS Satellite Position (virtual)
1355////////////////////////////////////////////////////////////////////////////
1356t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1357
1358 if (_checkState == bad) {
1359 return failure;
1360 }
1361
1362 bncTime tt(GPSweek, GPSweeks);
1363 double dt = tt - _TOC;
1364
1365 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1366 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1367 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
1368
1369 vv[0] = _x_velocity + _x_acceleration * dt;
1370 vv[1] = _y_velocity + _y_acceleration * dt;
1371 vv[2] = _z_velocity + _z_acceleration * dt;
1372
1373 xc[3] = _agf0 + _agf1 * dt;
1374
1375 return success;
1376}
1377
1378// RINEX Format String
1379//////////////////////////////////////////////////////////////////////////////
1380QString t_ephSBAS::toString(double version) const {
1381
1382 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1383
1384 QTextStream out(&rnxStr);
1385
1386 out << QString("%1%2%3\n")
1387 .arg(_agf0, 19, 'e', 12)
1388 .arg(_agf1, 19, 'e', 12)
1389 .arg(_TOW, 19, 'e', 12);
1390
1391 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1392
1393 out << QString(fmt)
1394 .arg(1.e-3*_x_pos, 19, 'e', 12)
1395 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1396 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
1397 .arg(_health, 19, 'e', 12);
1398
1399 out << QString(fmt)
1400 .arg(1.e-3*_y_pos, 19, 'e', 12)
1401 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1402 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
1403 .arg(_ura, 19, 'e', 12);
1404
1405 out << QString(fmt)
1406 .arg(1.e-3*_z_pos, 19, 'e', 12)
1407 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1408 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
1409 .arg(double(_IODN), 19, 'e', 12);
1410
1411 return rnxStr;
1412}
1413
1414// Constructor
1415//////////////////////////////////////////////////////////////////////////////
1416t_ephBDS::t_ephBDS(float rnxVersion, const QStringList& lines) {
1417
1418 const int nLines = 8;
1419
1420 if (lines.size() != nLines) {
1421 _checkState = bad;
1422 return;
1423 }
1424
1425 // RINEX Format
1426 // ------------
1427 int fieldLen = 19;
1428 double TOEw;
1429
1430 int pos[4];
1431 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1432 pos[1] = pos[0] + fieldLen;
1433 pos[2] = pos[1] + fieldLen;
1434 pos[3] = pos[2] + fieldLen;
1435
1436 // Read eight lines
1437 // ----------------
1438 for (int iLine = 0; iLine < nLines; iLine++) {
1439 QString line = lines[iLine];
1440
1441 if ( iLine == 0 ) {
1442 QTextStream in(line.left(pos[1]).toAscii());
1443
1444 int year, month, day, hour, min;
1445 double sec;
1446
1447 QString prnStr;
1448 in >> prnStr >> year >> month >> day >> hour >> min >> sec;
1449 if (prnStr.at(0) == 'C') {
1450 _prn.set('C', prnStr.mid(1).toInt());
1451 }
1452 else {
1453 _prn.set('C', prnStr.toInt());
1454 }
1455
1456 if (year < 80) {
1457 year += 2000;
1458 }
1459 else if (year < 100) {
1460 year += 1900;
1461 }
1462
1463 _TOC_bdt.set(year, month, day, hour, min, sec);
1464
1465 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1466 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1467 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1468 _checkState = bad;
1469 return;
1470 }
1471 }
1472
1473 else if ( iLine == 1 ) {
1474 double aode;
1475 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1476 readDbl(line, pos[1], fieldLen, _Crs ) ||
1477 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1478 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1479 _checkState = bad;
1480 return;
1481 }
1482 _AODE = int(aode);
1483 }
1484
1485 else if ( iLine == 2 ) {
1486 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1487 readDbl(line, pos[1], fieldLen, _e ) ||
1488 readDbl(line, pos[2], fieldLen, _Cus ) ||
1489 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1490 _checkState = bad;
1491 return;
1492 }
1493 }
1494
1495 else if ( iLine == 3 ) {
1496 if ( readDbl(line, pos[0], fieldLen, _TOEs ) ||
1497 readDbl(line, pos[1], fieldLen, _Cic ) ||
1498 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1499 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1500 _checkState = bad;
1501 return;
1502 }
1503 }
1504
1505 else if ( iLine == 4 ) {
1506 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1507 readDbl(line, pos[1], fieldLen, _Crc ) ||
1508 readDbl(line, pos[2], fieldLen, _omega ) ||
1509 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1510 _checkState = bad;
1511 return;
1512 }
1513 }
1514
1515 else if ( iLine == 5 ) {
1516 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
1517 readDbl(line, pos[2], fieldLen, TOEw) ) {
1518 _checkState = bad;
1519 return;
1520 }
1521 }
1522
1523 else if ( iLine == 6 ) {
1524 double SatH1;
1525 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
1526 readDbl(line, pos[1], fieldLen, SatH1) ||
1527 readDbl(line, pos[2], fieldLen, _TGD1) ||
1528 readDbl(line, pos[3], fieldLen, _TGD2) ) {
1529 _checkState = bad;
1530 return;
1531 }
1532 _SatH1 = int(SatH1);
1533 }
1534
1535 else if ( iLine == 7 ) {
1536 double aodc;
1537 if ( readDbl(line, pos[0], fieldLen, _TOTs) ||
1538 readDbl(line, pos[1], fieldLen, aodc) ) {
1539 _checkState = bad;
1540 return;
1541 }
1542 if (_TOTs == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
1543 _TOTs = _TOEs;
1544 }
1545 _AODC = int(aodc);
1546 }
1547 }
1548
1549 TOEw += 1356; // BDT -> GPS week number
1550 _TOE_bdt.set(int(TOEw), _TOEs);
1551
1552 // GPS->BDT
1553 // --------
1554 _TOC = _TOC_bdt + 14.0;
1555 _TOE = _TOE_bdt + 14.0;
1556
1557 // remark: actually should be computed from second_tot
1558 // but it seems to be unreliable in RINEX files
1559 _TOT = _TOC;
1560}
1561
1562// Set BDS Satellite Position
1563////////////////////////////////////////////////////////////////////////////
1564void t_ephBDS::set(const bdsephemeris* ee) {
1565
1566 // RTCM usage: set RINEX File entries to zero
1567 // ------------------------------------------
1568 _TOTs = 0.0;
1569 _TOEs = 0.0;
1570
1571 _receptDateTime = currentDateAndTimeGPS();
1572
1573 _prn.set('C', ee->satellite - PRN_BDS_START + 1);
1574
1575 _TOE_bdt.set(1356 + ee->BDSweek, ee->TOE);
1576 _TOE = _TOE_bdt + 14.0;
1577
1578 _TOC_bdt.set(1356 + ee->BDSweek, ee->TOC);
1579 _TOC = _TOC_bdt + 14.0;
1580
1581 _AODE = ee->AODE;
1582 _AODC = ee->AODC;
1583
1584 _clock_bias = ee->clock_bias;
1585 _clock_drift = ee->clock_drift;
1586 _clock_driftrate = ee->clock_driftrate;
1587
1588 _Crs = ee->Crs;
1589 _Delta_n = ee->Delta_n;
1590 _M0 = ee->M0;
1591
1592 _Cuc = ee->Cuc;
1593 _e = ee->e;
1594 _Cus = ee->Cus;
1595 _sqrt_A = ee->sqrt_A;
1596
1597 _Cic = ee->Cic;
1598 _OMEGA0 = ee->OMEGA0;
1599 _Cis = ee->Cis;
1600
1601 _i0 = ee->i0;
1602 _Crc = ee->Crc;
1603 _omega = ee->omega;
1604 _OMEGADOT = ee->OMEGADOT;
1605
1606 _IDOT = ee->IDOT;
1607
1608 _URA = accuracyFromIndex(ee->URAI, type());
1609 _SatH1 = (ee->flags & BDSEPHF_SATH1) ? 1: 0;
1610 _TGD1 = ee->TGD_B1_B3;
1611 _TGD2 = ee->TGD_B2_B3;
1612}
1613
1614// Compute BDS Satellite Position (virtual)
1615//////////////////////////////////////////////////////////////////////////////
1616t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
1617
1618 if (_checkState == bad) {
1619 return failure;
1620 }
1621
1622 static const double gmBDS = 398.6004418e12;
1623 static const double omegaBDS = 7292115.0000e-11;
1624
1625 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
1626 vv[0] = vv[1] = vv[2] = 0.0;
1627
1628 bncTime tt(GPSweek, GPSweeks);
1629
1630 if (_sqrt_A == 0) {
1631 return failure;
1632 }
1633 double a0 = _sqrt_A * _sqrt_A;
1634
1635 double n0 = sqrt(gmBDS/(a0*a0*a0));
1636 double tk = tt - _TOE;
1637 double n = n0 + _Delta_n;
1638 double M = _M0 + n*tk;
1639 double E = M;
1640 double E_last;
1641 int nLoop = 0;
1642 do {
1643 E_last = E;
1644 E = M + _e*sin(E);
1645
1646 if (++nLoop == 100) {
1647 return failure;
1648 }
1649 } while ( fabs(E-E_last)*a0 > 0.001 );
1650
1651 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
1652 double u0 = v + _omega;
1653 double sin2u0 = sin(2*u0);
1654 double cos2u0 = cos(2*u0);
1655 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1656 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1657 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1658 double xp = r*cos(u);
1659 double yp = r*sin(u);
1660 double toesec = (_TOE.gpssec() - 14.0);
1661
1662 double sinom = 0;
1663 double cosom = 0;
1664 double sini = 0;
1665 double cosi = 0;
1666
1667 const double iMaxGEO = 10.0 / 180.0 * M_PI;
1668
1669 // MEO/IGSO satellite
1670 // ------------------
1671 if (_i0 > iMaxGEO) {
1672 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
1673
1674 sinom = sin(OM);
1675 cosom = cos(OM);
1676 sini = sin(i);
1677 cosi = cos(i);
1678
1679 xc[0] = xp*cosom - yp*cosi*sinom;
1680 xc[1] = xp*sinom + yp*cosi*cosom;
1681 xc[2] = yp*sini;
1682 }
1683
1684 // GEO satellite
1685 // -------------
1686 else {
1687 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
1688 double ll = omegaBDS*tk;
1689
1690 sinom = sin(OM);
1691 cosom = cos(OM);
1692 sini = sin(i);
1693 cosi = cos(i);
1694
1695 double xx = xp*cosom - yp*cosi*sinom;
1696 double yy = xp*sinom + yp*cosi*cosom;
1697 double zz = yp*sini;
1698
1699 Matrix R1 = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
1700 Matrix R2 = BNC_PPP::t_astro::rotZ(ll);
1701
1702 ColumnVector X1(3); X1 << xx << yy << zz;
1703 ColumnVector X2 = R2*R1*X1;
1704
1705 xc[0] = X2(1);
1706 xc[1] = X2(2);
1707 xc[2] = X2(3);
1708 }
1709
1710 double tc = tt - _TOC;
1711 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc
1712 - 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1713
1714 // Velocity
1715 // --------
1716 double tanv2 = tan(v/2);
1717 double dEdM = 1 / (1 - _e*cos(E));
1718 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
1719 / (1 + tanv2*tanv2) * dEdM * n;
1720 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1721 double dotom = _OMEGADOT - t_CST::omega;
1722 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1723 double dotr = a0 * _e*sin(E) * dEdM * n
1724 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1725 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1726 double doty = dotr*sin(u) + r*cos(u)*dotu;
1727
1728 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1729 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1730 + yp*sini*sinom*doti; // dX / di
1731
1732 vv[1] = sinom *dotx + cosi*cosom *doty
1733 + xp*cosom*dotom - yp*cosi*sinom*dotom
1734 - yp*sini*cosom*doti;
1735
1736 vv[2] = sini *doty + yp*cosi *doti;
1737
1738 // dotC = _clock_drift + _clock_driftrate*tc
1739 // - 4.442807633e-10*_e*sqrt(a0)*cos(E) * dEdM * n;
1740
1741 return success;
1742}
1743
1744// RINEX Format String
1745//////////////////////////////////////////////////////////////////////////////
1746QString t_ephBDS::toString(double version) const {
1747
1748 QString rnxStr = rinexDateStr(_TOC_bdt, _prn, version);
1749
1750 QTextStream out(&rnxStr);
1751
1752 out << QString("%1%2%3\n")
1753 .arg(_clock_bias, 19, 'e', 12)
1754 .arg(_clock_drift, 19, 'e', 12)
1755 .arg(_clock_driftrate, 19, 'e', 12);
1756
1757 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1758
1759 out << QString(fmt)
1760 .arg(double(_AODE), 19, 'e', 12)
1761 .arg(_Crs, 19, 'e', 12)
1762 .arg(_Delta_n, 19, 'e', 12)
1763 .arg(_M0, 19, 'e', 12);
1764
1765 out << QString(fmt)
1766 .arg(_Cuc, 19, 'e', 12)
1767 .arg(_e, 19, 'e', 12)
1768 .arg(_Cus, 19, 'e', 12)
1769 .arg(_sqrt_A, 19, 'e', 12);
1770
1771 double toes = _TOEs;
1772 if (!toes) { // RTCM stream input
1773 toes = _TOE_bdt.gpssec();
1774 }
1775 out << QString(fmt)
1776 .arg(toes, 19, 'e', 12)
1777 .arg(_Cic, 19, 'e', 12)
1778 .arg(_OMEGA0, 19, 'e', 12)
1779 .arg(_Cis, 19, 'e', 12);
1780
1781 out << QString(fmt)
1782 .arg(_i0, 19, 'e', 12)
1783 .arg(_Crc, 19, 'e', 12)
1784 .arg(_omega, 19, 'e', 12)
1785 .arg(_OMEGADOT, 19, 'e', 12);
1786
1787 out << QString(fmt)
1788 .arg(_IDOT, 19, 'e', 12)
1789 .arg(0.0, 19, 'e', 12)
1790 .arg(double(_TOE_bdt.gpsw() - 1356.0), 19, 'e', 12)
1791 .arg(0.0, 19, 'e', 12);
1792
1793 out << QString(fmt)
1794 .arg(_URA, 19, 'e', 12)
1795 .arg(double(_SatH1), 19, 'e', 12)
1796 .arg(_TGD1, 19, 'e', 12)
1797 .arg(_TGD2, 19, 'e', 12);
1798
1799 double tots = _TOTs;
1800 if (!tots) { // RTCM stream input
1801 tots = _TOE_bdt.gpssec();
1802 }
1803 out << QString(fmt)
1804 .arg(tots, 19, 'e', 12)
1805 .arg(double(_AODC), 19, 'e', 12)
1806 .arg("", 19, QChar(' '))
1807 .arg("", 19, QChar(' '));
1808 return rnxStr;
1809}
1810
Note: See TracBrowser for help on using the repository browser.