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