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