source: ntrip/branches/BNC_2.11.0/src/RTCM3/ephemeris.cpp@ 6813

Last change on this file since 6813 was 6214, checked in by stuerze, 10 years ago

prevent usage of very old GLONASS navigation messages

File size: 37.8 KB
Line 
1#include <math.h>
2#include <sstream>
3#include <iostream>
4#include <iomanip>
5#include <cstring>
6
7#include <newmatio.h>
8
9#include "ephemeris.h"
10#include "bncutils.h"
11#include "timeutils.h"
12#include "bnctime.h"
13#include "bnccore.h"
14
15using namespace std;
16
17// Returns CRC24
18////////////////////////////////////////////////////////////////////////////
19static unsigned long CRC24(long size, const unsigned char *buf) {
20 unsigned long crc = 0;
21 int ii;
22 while (size--) {
23 crc ^= (*buf++) << (16);
24 for(ii = 0; ii < 8; ii++) {
25 crc <<= 1;
26 if (crc & 0x1000000) {
27 crc ^= 0x01864cfb;
28 }
29 }
30 }
31 return crc;
32}
33
34// Set GPS Satellite Position
35////////////////////////////////////////////////////////////////////////////
36void t_ephGPS::set(const gpsephemeris* ee) {
37
38 _receptDateTime = currentDateAndTimeGPS();
39
40 _prn = QString("G%1").arg(ee->satellite, 2, 10, QChar('0'));
41
42 _TOC.set(ee->GPSweek, ee->TOC);
43 _clock_bias = ee->clock_bias;
44 _clock_drift = ee->clock_drift;
45 _clock_driftrate = ee->clock_driftrate;
46
47 _IODE = ee->IODE;
48 _Crs = ee->Crs;
49 _Delta_n = ee->Delta_n;
50 _M0 = ee->M0;
51
52 _Cuc = ee->Cuc;
53 _e = ee->e;
54 _Cus = ee->Cus;
55 _sqrt_A = ee->sqrt_A;
56
57 _TOEsec = ee->TOE;
58 _Cic = ee->Cic;
59 _OMEGA0 = ee->OMEGA0;
60 _Cis = ee->Cis;
61
62 _i0 = ee->i0;
63 _Crc = ee->Crc;
64 _omega = ee->omega;
65 _OMEGADOT = ee->OMEGADOT;
66
67 _IDOT = ee->IDOT;
68 _L2Codes = 0.0;
69 _TOEweek = ee->GPSweek;
70 _L2PFlag = 0.0;
71
72 if (ee->URAindex <= 6) {
73 _ura = ceil(10.0*pow(2.0, 1.0+((double)ee->URAindex)/2.0))/10.0;
74 }
75 else {
76 _ura = ceil(10.0*pow(2.0, ((double)ee->URAindex)/2.0))/10.0;
77 }
78 _health = ee->SVhealth;
79 _TGD = ee->TGD;
80 _IODC = ee->IODC;
81
82 _TOT = 0.9999e9;
83 _fitInterval = 0.0;
84
85 _ok = true;
86}
87
88// Compute GPS Satellite Position (virtual)
89////////////////////////////////////////////////////////////////////////////
90t_irc t_ephGPS::position(int GPSweek, double GPSweeks,
91 double* xc,
92 double* vv) const {
93
94
95 static const double omegaEarth = 7292115.1467e-11;
96 static const double gmGRS = 398.6005e12;
97
98 memset(xc, 0, 4*sizeof(double));
99 memset(vv, 0, 3*sizeof(double));
100
101 double a0 = _sqrt_A * _sqrt_A;
102 if (a0 == 0) {
103 return failure;
104 }
105
106 double n0 = sqrt(gmGRS/(a0*a0*a0));
107
108 bncTime tt(GPSweek, GPSweeks);
109 double tk = tt - bncTime(int(_TOEweek), _TOEsec);
110
111 double n = n0 + _Delta_n;
112 double M = _M0 + n*tk;
113 double E = M;
114 double E_last;
115 do {
116 E_last = E;
117 E = M + _e*sin(E);
118 } while ( fabs(E-E_last)*a0 > 0.001 );
119 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
120 double u0 = v + _omega;
121 double sin2u0 = sin(2*u0);
122 double cos2u0 = cos(2*u0);
123 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
124 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
125 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
126 double xp = r*cos(u);
127 double yp = r*sin(u);
128 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
129 omegaEarth*_TOEsec;
130
131 double sinom = sin(OM);
132 double cosom = cos(OM);
133 double sini = sin(i);
134 double cosi = cos(i);
135 xc[0] = xp*cosom - yp*cosi*sinom;
136 xc[1] = xp*sinom + yp*cosi*cosom;
137 xc[2] = yp*sini;
138
139 double tc = tt - _TOC;
140 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
141
142 // Velocity
143 // --------
144 double tanv2 = tan(v/2);
145 double dEdM = 1 / (1 - _e*cos(E));
146 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
147 * dEdM * n;
148 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
149 double dotom = _OMEGADOT - omegaEarth;
150 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
151 double dotr = a0 * _e*sin(E) * dEdM * n
152 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
153 double dotx = dotr*cos(u) - r*sin(u)*dotu;
154 double doty = dotr*sin(u) + r*cos(u)*dotu;
155
156 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
157 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
158 + yp*sini*sinom*doti; // dX / di
159
160 vv[1] = sinom *dotx + cosi*cosom *doty
161 + xp*cosom*dotom - yp*cosi*sinom*dotom
162 - yp*sini*cosom*doti;
163
164 vv[2] = sini *doty + yp*cosi *doti;
165
166 // Relativistic Correction
167 // -----------------------
168 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
169
170 return success;
171}
172
173// build up RTCM3 for GPS
174////////////////////////////////////////////////////////////////////////////
175#define GPSTOINT(type, value) static_cast<type>(round(value))
176
177#define GPSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
178 |(GPSTOINT(long long,b)&((1ULL<<a)-1)); \
179 numbits += (a); \
180 while(numbits >= 8) { \
181 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
182
183#define GPSADDBITSFLOAT(a,b,c) {long long i = GPSTOINT(long long,(b)/(c)); \
184 GPSADDBITS(a,i)};
185
186int t_ephGPS::RTCM3(unsigned char *buffer) {
187
188 unsigned char *startbuffer = buffer;
189 buffer= buffer+3;
190 int size = 0;
191 int numbits = 0;
192 unsigned long long bitbuffer = 0;
193 if (_ura <= 2.40){
194 _ura = 0;
195 }
196 else if (_ura <= 3.40){
197 _ura = 1;
198 }
199 else if (_ura <= 6.85){
200 _ura = 2;
201 }
202 else if (_ura <= 9.65){
203 _ura = 3;
204 }
205 else if (_ura <= 13.65){
206 _ura = 4;
207 }
208 else if (_ura <= 24.00){
209 _ura = 5;
210 }
211 else if (_ura <= 48.00){
212 _ura = 6;
213 }
214 else if (_ura <= 96.00){
215 _ura = 7;
216 }
217 else if (_ura <= 192.00){
218 _ura = 8;
219 }
220 else if (_ura <= 384.00){
221 _ura = 9;
222 }
223 else if (_ura <= 768.00){
224 _ura = 10;
225 }
226 else if (_ura <= 1536.00){
227 _ura = 11;
228 }
229 else if (_ura <= 1536.00){
230 _ura = 12;
231 }
232 else if (_ura <= 2072.00){
233 _ura = 13;
234 }
235 else if (_ura <= 6144.00){
236 _ura = 14;
237 }
238 else{
239 _ura = 15;
240 }
241
242 GPSADDBITS(12, 1019)
243 GPSADDBITS(6,_prn.right((_prn.length()-1)).toInt())
244 GPSADDBITS(10, _TOC.gpsw())
245 GPSADDBITS(4, _ura)
246 GPSADDBITS(2,_L2Codes)
247 GPSADDBITSFLOAT(14, _IDOT, M_PI/static_cast<double>(1<<30)
248 /static_cast<double>(1<<13))
249 GPSADDBITS(8, _IODE)
250 GPSADDBITS(16, static_cast<int>(_TOC.gpssec())>>4)
251 GPSADDBITSFLOAT(8, _clock_driftrate, 1.0/static_cast<double>(1<<30)
252 /static_cast<double>(1<<25))
253 GPSADDBITSFLOAT(16, _clock_drift, 1.0/static_cast<double>(1<<30)
254 /static_cast<double>(1<<13))
255 GPSADDBITSFLOAT(22, _clock_bias, 1.0/static_cast<double>(1<<30)
256 /static_cast<double>(1<<1))
257 GPSADDBITS(10, _IODC)
258 GPSADDBITSFLOAT(16, _Crs, 1.0/static_cast<double>(1<<5))
259 GPSADDBITSFLOAT(16, _Delta_n, M_PI/static_cast<double>(1<<30)
260 /static_cast<double>(1<<13))
261 GPSADDBITSFLOAT(32, _M0, M_PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
262 GPSADDBITSFLOAT(16, _Cuc, 1.0/static_cast<double>(1<<29))
263 GPSADDBITSFLOAT(32, _e, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<3))
264 GPSADDBITSFLOAT(16, _Cus, 1.0/static_cast<double>(1<<29))
265 GPSADDBITSFLOAT(32, _sqrt_A, 1.0/static_cast<double>(1<<19))
266 GPSADDBITS(16, static_cast<int>(_TOEsec)>>4)
267 GPSADDBITSFLOAT(16, _Cic, 1.0/static_cast<double>(1<<29))
268 GPSADDBITSFLOAT(32, _OMEGA0, M_PI/static_cast<double>(1<<30)
269 /static_cast<double>(1<<1))
270 GPSADDBITSFLOAT(16, _Cis, 1.0/static_cast<double>(1<<29))
271 GPSADDBITSFLOAT(32, _i0, M_PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
272 GPSADDBITSFLOAT(16, _Crc, 1.0/static_cast<double>(1<<5))
273 GPSADDBITSFLOAT(32, _omega, M_PI/static_cast<double>(1<<30)
274 /static_cast<double>(1<<1))
275 GPSADDBITSFLOAT(24, _OMEGADOT, M_PI/static_cast<double>(1<<30)
276 /static_cast<double>(1<<13))
277 GPSADDBITSFLOAT(8, _TGD, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
278 GPSADDBITS(6, _health)
279 GPSADDBITS(1, _L2PFlag)
280 GPSADDBITS(1, 0) /* GPS fit interval */
281
282 startbuffer[0]=0xD3;
283 startbuffer[1]=(size >> 8);
284 startbuffer[2]=size;
285 unsigned long i = CRC24(size+3, startbuffer);
286 buffer[size++] = i >> 16;
287 buffer[size++] = i >> 8;
288 buffer[size++] = i;
289 size += 3;
290 return size;
291}
292
293// Derivative of the state vector using a simple force model (static)
294////////////////////////////////////////////////////////////////////////////
295ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
296 double* acc) {
297
298 // State vector components
299 // -----------------------
300 ColumnVector rr = xv.rows(1,3);
301 ColumnVector vv = xv.rows(4,6);
302
303 // Acceleration
304 // ------------
305 static const double gmWGS = 398.60044e12;
306 static const double AE = 6378136.0;
307 static const double OMEGA = 7292115.e-11;
308 static const double C20 = -1082.6257e-6;
309
310 double rho = rr.norm_Frobenius();
311 double t1 = -gmWGS/(rho*rho*rho);
312 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
313 double t3 = OMEGA * OMEGA;
314 double t4 = 2.0 * OMEGA;
315 double z2 = rr(3) * rr(3);
316
317 // Vector of derivatives
318 // ---------------------
319 ColumnVector va(6);
320 va(1) = vv(1);
321 va(2) = vv(2);
322 va(3) = vv(3);
323 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
324 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
325 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
326
327 return va;
328}
329
330// Compute Glonass Satellite Position (virtual)
331////////////////////////////////////////////////////////////////////////////
332t_irc t_ephGlo::position(int GPSweek, double GPSweeks,
333 double* xc, double* vv) const {
334
335 static const double nominalStep = 10.0;
336
337 memset(xc, 0, 4*sizeof(double));
338 memset(vv, 0, 3*sizeof(double));
339
340 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
341
342 if (fabs(dtPos) > 24*3600.0) {
343 return failure;
344 }
345
346 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
347 double step = dtPos / nSteps;
348
349 double acc[3];
350 acc[0] = _x_acceleration * 1.e3;
351 acc[1] = _y_acceleration * 1.e3;
352 acc[2] = _z_acceleration * 1.e3;
353 for (int ii = 1; ii <= nSteps; ii++) {
354 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
355 _tt = _tt + step;
356 }
357
358 // Position and Velocity
359 // ---------------------
360 xc[0] = _xv(1);
361 xc[1] = _xv(2);
362 xc[2] = _xv(3);
363
364 vv[0] = _xv(4);
365 vv[1] = _xv(5);
366 vv[2] = _xv(6);
367
368 // Clock Correction
369 // ----------------
370 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
371 xc[3] = -_tau + _gamma * dtClk;
372
373 return success;
374}
375
376// IOD of Glonass Ephemeris (virtual)
377////////////////////////////////////////////////////////////////////////////
378int t_ephGlo::IOD() const {
379 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
380 return int(tMoscow.daysec() / 900);
381}
382
383// Set Glonass Ephemeris
384////////////////////////////////////////////////////////////////////////////
385void t_ephGlo::set(const glonassephemeris* ee) {
386
387 _receptDateTime = currentDateAndTimeGPS();
388
389 _prn = QString("R%1").arg(ee->almanac_number, 2, 10, QChar('0'));
390
391 int ww = ee->GPSWeek;
392 int tow = ee->GPSTOW;
393 updatetime(&ww, &tow, ee->tb*1000, 0); // Moscow -> GPS
394
395 // Check the day once more
396 // -----------------------
397 bool timeChanged = false;
398 {
399 const double secPerDay = 24 * 3600.0;
400 const double secPerWeek = 7 * secPerDay;
401 int ww_old = ww;
402 int tow_old = tow;
403 int currentWeek;
404 double currentSec;
405 currentGPSWeeks(currentWeek, currentSec);
406 bncTime currentTime(currentWeek, currentSec);
407 bncTime hTime(ww, (double) tow);
408
409 if (hTime - currentTime > secPerDay/2.0) {
410 timeChanged = true;
411 tow -= int(secPerDay);
412 if (tow < 0) {
413 tow += int(secPerWeek);
414 ww -= 1;
415 }
416 }
417 else if (hTime - currentTime < -secPerDay/2.0) {
418 timeChanged = true;
419 tow += int(secPerDay);
420 if (tow > secPerWeek) {
421 tow -= int(secPerWeek);
422 ww += 1;
423 }
424 }
425
426 if (false && timeChanged && BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
427 bncTime newHTime(ww, (double) tow);
428 cout << "GLONASS " << ee->almanac_number << " Time Changed at "
429 << currentTime.datestr() << " " << currentTime.timestr()
430 << endl
431 << "old: " << hTime.datestr() << " " << hTime.timestr()
432 << endl
433 << "new: " << newHTime.datestr() << " " << newHTime.timestr()
434 << endl
435 << "eph: " << ee->GPSWeek << " " << ee->GPSTOW << " " << ee->tb
436 << endl
437 << "ww, tow (old): " << ww_old << " " << tow_old
438 << endl
439 << "ww, tow (new): " << ww << " " << tow
440 << endl << endl;
441 }
442 }
443
444 bncTime hlpTime(ww, (double) tow);
445 unsigned year, month, day;
446 hlpTime.civil_date(year, month, day);
447 _gps_utc = gnumleap(year, month, day);
448
449 _TOC.set(ww, tow);
450 _E = ee->E;
451 _tau = ee->tau;
452 _gamma = ee->gamma;
453 _x_pos = ee->x_pos;
454 _x_velocity = ee->x_velocity;
455 _x_acceleration = ee->x_acceleration;
456 _y_pos = ee->y_pos;
457 _y_velocity = ee->y_velocity;
458 _y_acceleration = ee->y_acceleration;
459 _z_pos = ee->z_pos;
460 _z_velocity = ee->z_velocity;
461 _z_acceleration = ee->z_acceleration;
462 _health = 0;
463 _frequency_number = ee->frequency_number;
464 _tki = ee->tk-3*60*60; if (_tki < 0) _tki += 86400;
465
466 // Initialize status vector
467 // ------------------------
468 _tt = _TOC;
469
470 _xv(1) = _x_pos * 1.e3;
471 _xv(2) = _y_pos * 1.e3;
472 _xv(3) = _z_pos * 1.e3;
473 _xv(4) = _x_velocity * 1.e3;
474 _xv(5) = _y_velocity * 1.e3;
475 _xv(6) = _z_velocity * 1.e3;
476
477 _ok = true;
478}
479
480// build up RTCM3 for GLONASS
481////////////////////////////////////////////////////////////////////////////
482#define GLONASSTOINT(type, value) static_cast<type>(round(value))
483
484#define GLONASSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
485 |(GLONASSTOINT(long long,b)&((1ULL<<(a))-1)); \
486 numbits += (a); \
487 while(numbits >= 8) { \
488 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
489#define GLONASSADDBITSFLOATM(a,b,c) {int s; long long i; \
490 if(b < 0.0) \
491 { \
492 s = 1; \
493 i = GLONASSTOINT(long long,(-b)/(c)); \
494 if(!i) s = 0; \
495 } \
496 else \
497 { \
498 s = 0; \
499 i = GLONASSTOINT(long long,(b)/(c)); \
500 } \
501 GLONASSADDBITS(1,s) \
502 GLONASSADDBITS(a-1,i)}
503
504int t_ephGlo::RTCM3(unsigned char *buffer)
505{
506
507 int size = 0;
508 int numbits = 0;
509 long long bitbuffer = 0;
510 unsigned char *startbuffer = buffer;
511 buffer= buffer+3;
512
513 GLONASSADDBITS(12, 1020)
514 GLONASSADDBITS(6, _prn.right((_prn.length()-1)).toInt())
515 GLONASSADDBITS(5, 7+_frequency_number)
516 GLONASSADDBITS(1, 0)
517 GLONASSADDBITS(1, 0)
518 GLONASSADDBITS(2, 0)
519 _tki=_tki+3*60*60;
520 GLONASSADDBITS(5, static_cast<int>(_tki)/(60*60))
521 GLONASSADDBITS(6, (static_cast<int>(_tki)/60)%60)
522 GLONASSADDBITS(1, (static_cast<int>(_tki)/30)%30)
523 GLONASSADDBITS(1, _health)
524 GLONASSADDBITS(1, 0)
525 unsigned long long timeofday = (static_cast<int>(_tt.gpssec()+3*60*60-_gps_utc)%86400);
526 GLONASSADDBITS(7, timeofday/60/15)
527 GLONASSADDBITSFLOATM(24, _x_velocity*1000, 1000.0/static_cast<double>(1<<20))
528 GLONASSADDBITSFLOATM(27, _x_pos*1000, 1000.0/static_cast<double>(1<<11))
529 GLONASSADDBITSFLOATM(5, _x_acceleration*1000, 1000.0/static_cast<double>(1<<30))
530 GLONASSADDBITSFLOATM(24, _y_velocity*1000, 1000.0/static_cast<double>(1<<20))
531 GLONASSADDBITSFLOATM(27, _y_pos*1000, 1000.0/static_cast<double>(1<<11))
532 GLONASSADDBITSFLOATM(5, _y_acceleration*1000, 1000.0/static_cast<double>(1<<30))
533 GLONASSADDBITSFLOATM(24, _z_velocity*1000, 1000.0/static_cast<double>(1<<20))
534 GLONASSADDBITSFLOATM(27,_z_pos*1000, 1000.0/static_cast<double>(1<<11))
535 GLONASSADDBITSFLOATM(5, _z_acceleration*1000, 1000.0/static_cast<double>(1<<30))
536 GLONASSADDBITS(1, 0)
537 GLONASSADDBITSFLOATM(11, _gamma, 1.0/static_cast<double>(1<<30)
538 /static_cast<double>(1<<10))
539 GLONASSADDBITS(2, 0) /* GLONASS-M P */
540 GLONASSADDBITS(1, 0) /* GLONASS-M ln(3) */
541 GLONASSADDBITSFLOATM(22, _tau, 1.0/static_cast<double>(1<<30))
542 GLONASSADDBITS(5, 0) /* GLONASS-M delta tau */
543 GLONASSADDBITS(5, _E)
544 GLONASSADDBITS(1, 0) /* GLONASS-M P4 */
545 GLONASSADDBITS(4, 0) /* GLONASS-M FT */
546 GLONASSADDBITS(11, 0) /* GLONASS-M NT */
547 GLONASSADDBITS(2, 0) /* GLONASS-M active? */
548 GLONASSADDBITS(1, 0) /* GLONASS additional data */
549 GLONASSADDBITS(11, 0) /* GLONASS NA */
550 GLONASSADDBITS(32, 0) /* GLONASS tau C */
551 GLONASSADDBITS(5, 0) /* GLONASS-M N4 */
552 GLONASSADDBITS(22, 0) /* GLONASS-M tau GPS */
553 GLONASSADDBITS(1, 0) /* GLONASS-M ln(5) */
554 GLONASSADDBITS(7, 0) /* Reserved */
555
556 startbuffer[0]=0xD3;
557 startbuffer[1]=(size >> 8);
558 startbuffer[2]=size;
559 unsigned long i = CRC24(size+3, startbuffer);
560 buffer[size++] = i >> 16;
561 buffer[size++] = i >> 8;
562 buffer[size++] = i;
563 size += 3;
564 return size;
565}
566
567// Set Galileo Satellite Position
568////////////////////////////////////////////////////////////////////////////
569void t_ephGal::set(const galileoephemeris* ee) {
570
571 _receptDateTime = currentDateAndTimeGPS();
572
573 _prn = QString("E%1").arg(ee->satellite, 2, 10, QChar('0'));
574
575 _TOC.set(ee->Week, ee->TOC);
576 _clock_bias = ee->clock_bias;
577 _clock_drift = ee->clock_drift;
578 _clock_driftrate = ee->clock_driftrate;
579
580 _IODnav = ee->IODnav;
581 _Crs = ee->Crs;
582 _Delta_n = ee->Delta_n;
583 _M0 = ee->M0;
584
585 _Cuc = ee->Cuc;
586 _e = ee->e;
587 _Cus = ee->Cus;
588 _sqrt_A = ee->sqrt_A;
589
590 _TOEsec = _TOC.gpssec();
591 //// _TOEsec = ee->TOE; //// TODO:
592 _Cic = ee->Cic;
593 _OMEGA0 = ee->OMEGA0;
594 _Cis = ee->Cis;
595
596 _i0 = ee->i0;
597 _Crc = ee->Crc;
598 _omega = ee->omega;
599 _OMEGADOT = ee->OMEGADOT;
600
601 _IDOT = ee->IDOT;
602 _TOEweek = ee->Week;
603
604 _SISA = ee->SISA;
605 _E5aHS = ee->E5aHS;
606 _E5bHS = ee->E5bHS;
607 _BGD_1_5A = ee->BGD_1_5A;
608 _BGD_1_5B = ee->BGD_1_5B;
609
610 _TOT = 0.9999e9;
611
612 _flags = ee->flags;
613
614 _ok = true;
615}
616
617// Compute Galileo Satellite Position (virtual)
618////////////////////////////////////////////////////////////////////////////
619t_irc t_ephGal::position(int GPSweek, double GPSweeks,
620 double* xc,
621 double* vv) const {
622
623 static const double omegaEarth = 7292115.1467e-11;
624 static const double gmWGS = 398.60044e12;
625
626 memset(xc, 0, 4*sizeof(double));
627 memset(vv, 0, 3*sizeof(double));
628
629 double a0 = _sqrt_A * _sqrt_A;
630 if (a0 == 0) {
631 return failure;
632 }
633
634 double n0 = sqrt(gmWGS/(a0*a0*a0));
635
636 bncTime tt(GPSweek, GPSweeks);
637 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
638
639 double n = n0 + _Delta_n;
640 double M = _M0 + n*tk;
641 double E = M;
642 double E_last;
643 do {
644 E_last = E;
645 E = M + _e*sin(E);
646 } while ( fabs(E-E_last)*a0 > 0.001 );
647 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
648 double u0 = v + _omega;
649 double sin2u0 = sin(2*u0);
650 double cos2u0 = cos(2*u0);
651 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
652 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
653 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
654 double xp = r*cos(u);
655 double yp = r*sin(u);
656 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
657 omegaEarth*_TOEsec;
658
659 double sinom = sin(OM);
660 double cosom = cos(OM);
661 double sini = sin(i);
662 double cosi = cos(i);
663 xc[0] = xp*cosom - yp*cosi*sinom;
664 xc[1] = xp*sinom + yp*cosi*cosom;
665 xc[2] = yp*sini;
666
667 double tc = tt - _TOC;
668 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
669
670 // Velocity
671 // --------
672 double tanv2 = tan(v/2);
673 double dEdM = 1 / (1 - _e*cos(E));
674 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
675 * dEdM * n;
676 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
677 double dotom = _OMEGADOT - omegaEarth;
678 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
679 double dotr = a0 * _e*sin(E) * dEdM * n
680 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
681 double dotx = dotr*cos(u) - r*sin(u)*dotu;
682 double doty = dotr*sin(u) + r*cos(u)*dotu;
683
684 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
685 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
686 + yp*sini*sinom*doti; // dX / di
687
688 vv[1] = sinom *dotx + cosi*cosom *doty
689 + xp*cosom*dotom - yp*cosi*sinom*dotom
690 - yp*sini*cosom*doti;
691
692 vv[2] = sini *doty + yp*cosi *doti;
693
694 // Relativistic Correction
695 // -----------------------
696 // xc(4) -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
697 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
698
699 return success;
700}
701
702// build up RTCM3 for Galileo
703////////////////////////////////////////////////////////////////////////////
704#define GALILEOTOINT(type, value) static_cast<type>(round(value))
705
706#define GALILEOADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
707 |(GALILEOTOINT(long long,b)&((1LL<<a)-1)); \
708 numbits += (a); \
709 while(numbits >= 8) { \
710 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
711#define GALILEOADDBITSFLOAT(a,b,c) {long long i = GALILEOTOINT(long long,(b)/(c)); \
712 GALILEOADDBITS(a,i)};
713
714int t_ephGal::RTCM3(unsigned char *buffer) {
715 int size = 0;
716 int numbits = 0;
717 long long bitbuffer = 0;
718 unsigned char *startbuffer = buffer;
719 buffer= buffer+3;
720
721 bool inav = ( (_flags & GALEPHF_INAV) == GALEPHF_INAV );
722
723 GALILEOADDBITS(12, inav ? 1046 : 1045)
724 GALILEOADDBITS(6, _prn.right((_prn.length()-1)).toInt())
725 GALILEOADDBITS(12, _TOC.gpsw())
726 GALILEOADDBITS(10, _IODnav)
727 GALILEOADDBITS(8, _SISA)
728 GALILEOADDBITSFLOAT(14, _IDOT, M_PI/static_cast<double>(1<<30)
729 /static_cast<double>(1<<13))
730 GALILEOADDBITS(14, _TOC.gpssec()/60)
731 GALILEOADDBITSFLOAT(6, _clock_driftrate, 1.0/static_cast<double>(1<<30)
732 /static_cast<double>(1<<29))
733 GALILEOADDBITSFLOAT(21, _clock_drift, 1.0/static_cast<double>(1<<30)
734 /static_cast<double>(1<<16))
735 GALILEOADDBITSFLOAT(31, _clock_bias, 1.0/static_cast<double>(1<<30)
736 /static_cast<double>(1<<4))
737 GALILEOADDBITSFLOAT(16, _Crs, 1.0/static_cast<double>(1<<5))
738 GALILEOADDBITSFLOAT(16, _Delta_n, M_PI/static_cast<double>(1<<30)
739 /static_cast<double>(1<<13))
740 GALILEOADDBITSFLOAT(32, _M0, M_PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
741 GALILEOADDBITSFLOAT(16, _Cuc, 1.0/static_cast<double>(1<<29))
742 GALILEOADDBITSFLOAT(32, _e, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<3))
743 GALILEOADDBITSFLOAT(16, _Cus, 1.0/static_cast<double>(1<<29))
744 GALILEOADDBITSFLOAT(32, _sqrt_A, 1.0/static_cast<double>(1<<19))
745 GALILEOADDBITS(14, _TOEsec/60)
746 GALILEOADDBITSFLOAT(16, _Cic, 1.0/static_cast<double>(1<<29))
747 GALILEOADDBITSFLOAT(32, _OMEGA0, M_PI/static_cast<double>(1<<30)
748 /static_cast<double>(1<<1))
749 GALILEOADDBITSFLOAT(16, _Cis, 1.0/static_cast<double>(1<<29))
750 GALILEOADDBITSFLOAT(32, _i0, M_PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
751 GALILEOADDBITSFLOAT(16, _Crc, 1.0/static_cast<double>(1<<5))
752 GALILEOADDBITSFLOAT(32, _omega, M_PI/static_cast<double>(1<<30)
753 /static_cast<double>(1<<1))
754 GALILEOADDBITSFLOAT(24, _OMEGADOT, M_PI/static_cast<double>(1<<30)
755 /static_cast<double>(1<<13))
756 GALILEOADDBITSFLOAT(10, _BGD_1_5A, 1.0/static_cast<double>(1<<30)
757 /static_cast<double>(1<<2))
758 if(inav)
759 {
760 GALILEOADDBITSFLOAT(10, _BGD_1_5B, 1.0/static_cast<double>(1<<30)
761 /static_cast<double>(1<<2))
762 GALILEOADDBITS(2, static_cast<int>(_E5bHS))
763 GALILEOADDBITS(1, _flags & GALEPHF_E5BDINVALID)
764 }
765 else
766 {
767 GALILEOADDBITS(2, static_cast<int>(_E5aHS))
768 GALILEOADDBITS(1, _flags & GALEPHF_E5ADINVALID)
769 }
770 _TOEsec = 0.9999E9;
771 GALILEOADDBITS(20, _TOEsec)
772
773 GALILEOADDBITS(inav ? 1 : 3, 0)
774
775 startbuffer[0]=0xD3;
776 startbuffer[1]=(size >> 8);
777 startbuffer[2]=size;
778 unsigned long i = CRC24(size+3, startbuffer);
779 buffer[size++] = i >> 16;
780 buffer[size++] = i >> 8;
781 buffer[size++] = i;
782 size += 3;
783 return size;
784}
785
786// Constructor
787//////////////////////////////////////////////////////////////////////////////
788t_ephGPS::t_ephGPS(float rnxVersion, const QStringList& lines) {
789
790 const int nLines = 8;
791
792 _ok = false;
793
794 if (lines.size() != nLines) {
795 return;
796 }
797
798 // RINEX Format
799 // ------------
800 int fieldLen = 19;
801
802 int pos[4];
803 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
804 pos[1] = pos[0] + fieldLen;
805 pos[2] = pos[1] + fieldLen;
806 pos[3] = pos[2] + fieldLen;
807
808 // Read eight lines
809 // ----------------
810 for (int iLine = 0; iLine < nLines; iLine++) {
811 QString line = lines[iLine];
812
813 if ( iLine == 0 ) {
814 QTextStream in(line.left(pos[1]).toAscii());
815
816 int year, month, day, hour, min;
817 double sec;
818
819 in >> _prn >> year >> month >> day >> hour >> min >> sec;
820
821 if (_prn.at(0) != 'G') {
822 _prn = QString("G%1").arg(_prn.toInt(), 2, 10, QLatin1Char('0'));
823 }
824
825 if (year < 80) {
826 year += 2000;
827 }
828 else if (year < 100) {
829 year += 1900;
830 }
831
832 _TOC.set(year, month, day, hour, min, sec);
833
834 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
835 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
836 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
837 return;
838 }
839 }
840
841 else if ( iLine == 1 ) {
842 if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
843 readDbl(line, pos[1], fieldLen, _Crs ) ||
844 readDbl(line, pos[2], fieldLen, _Delta_n) ||
845 readDbl(line, pos[3], fieldLen, _M0 ) ) {
846 return;
847 }
848 }
849
850 else if ( iLine == 2 ) {
851 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
852 readDbl(line, pos[1], fieldLen, _e ) ||
853 readDbl(line, pos[2], fieldLen, _Cus ) ||
854 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
855 return;
856 }
857 }
858
859 else if ( iLine == 3 ) {
860 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
861 readDbl(line, pos[1], fieldLen, _Cic ) ||
862 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
863 readDbl(line, pos[3], fieldLen, _Cis ) ) {
864 return;
865 }
866 }
867
868 else if ( iLine == 4 ) {
869 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
870 readDbl(line, pos[1], fieldLen, _Crc ) ||
871 readDbl(line, pos[2], fieldLen, _omega ) ||
872 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
873 return;
874 }
875 }
876
877 else if ( iLine == 5 ) {
878 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
879 readDbl(line, pos[1], fieldLen, _L2Codes) ||
880 readDbl(line, pos[2], fieldLen, _TOEweek ) ||
881 readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
882 return;
883 }
884 }
885
886 else if ( iLine == 6 ) {
887 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
888 readDbl(line, pos[1], fieldLen, _health) ||
889 readDbl(line, pos[2], fieldLen, _TGD ) ||
890 readDbl(line, pos[3], fieldLen, _IODC ) ) {
891 return;
892 }
893 }
894
895 else if ( iLine == 7 ) {
896 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
897 return;
898 }
899 readDbl(line, pos[1], fieldLen, _fitInterval); // _fitInterval optional
900 }
901 }
902
903 _ok = true;
904}
905
906// Constructor
907//////////////////////////////////////////////////////////////////////////////
908t_ephGlo::t_ephGlo(float rnxVersion, const QStringList& lines) {
909
910 const int nLines = 4;
911
912 _ok = false;
913
914 if (lines.size() != nLines) {
915 return;
916 }
917
918 // RINEX Format
919 // ------------
920 int fieldLen = 19;
921
922 int pos[4];
923 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
924 pos[1] = pos[0] + fieldLen;
925 pos[2] = pos[1] + fieldLen;
926 pos[3] = pos[2] + fieldLen;
927
928 // Read four lines
929 // ---------------
930 for (int iLine = 0; iLine < nLines; iLine++) {
931 QString line = lines[iLine];
932
933 if ( iLine == 0 ) {
934 QTextStream in(line.left(pos[1]).toAscii());
935
936 int year, month, day, hour, min;
937 double sec;
938
939 in >> _prn >> year >> month >> day >> hour >> min >> sec;
940
941 if (_prn.at(0) != 'R') {
942 _prn = QString("R%1").arg(_prn.toInt(), 2, 10, QLatin1Char('0'));
943 }
944
945 if (year < 80) {
946 year += 2000;
947 }
948 else if (year < 100) {
949 year += 1900;
950 }
951
952 _gps_utc = gnumleap(year, month, day);
953
954 _TOC.set(year, month, day, hour, min, sec);
955 _TOC = _TOC + _gps_utc;
956
957 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
958 readDbl(line, pos[2], fieldLen, _gamma) ||
959 readDbl(line, pos[3], fieldLen, _tki ) ) {
960 return;
961 }
962
963 _tau = -_tau;
964 }
965
966 else if ( iLine == 1 ) {
967 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
968 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
969 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
970 readDbl(line, pos[3], fieldLen, _health ) ) {
971 return;
972 }
973 }
974
975 else if ( iLine == 2 ) {
976 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
977 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
978 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
979 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
980 return;
981 }
982 }
983
984 else if ( iLine == 3 ) {
985 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
986 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
987 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
988 readDbl(line, pos[3], fieldLen, _E ) ) {
989 return;
990 }
991 }
992 }
993
994 // Initialize status vector
995 // ------------------------
996 _tt = _TOC;
997 _xv.ReSize(6);
998 _xv(1) = _x_pos * 1.e3;
999 _xv(2) = _y_pos * 1.e3;
1000 _xv(3) = _z_pos * 1.e3;
1001 _xv(4) = _x_velocity * 1.e3;
1002 _xv(5) = _y_velocity * 1.e3;
1003 _xv(6) = _z_velocity * 1.e3;
1004
1005 _ok = true;
1006}
1007
1008// Constructor
1009//////////////////////////////////////////////////////////////////////////////
1010t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
1011
1012 const int nLines = 8;
1013
1014 _ok = false;
1015
1016 if (lines.size() != nLines) {
1017 return;
1018 }
1019
1020 // RINEX Format
1021 // ------------
1022 int fieldLen = 19;
1023
1024 int pos[4];
1025 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1026 pos[1] = pos[0] + fieldLen;
1027 pos[2] = pos[1] + fieldLen;
1028 pos[3] = pos[2] + fieldLen;
1029
1030 // Read eight lines
1031 // ----------------
1032 for (int iLine = 0; iLine < nLines; iLine++) {
1033 QString line = lines[iLine];
1034
1035 if ( iLine == 0 ) {
1036 QTextStream in(line.left(pos[1]).toAscii());
1037
1038 int year, month, day, hour, min;
1039 double sec;
1040
1041 in >> _prn >> year >> month >> day >> hour >> min >> sec;
1042
1043 if (_prn.at(0) != 'E') {
1044 _prn = QString("E%1").arg(_prn.toInt(), 2, 10, QLatin1Char('0'));
1045 }
1046
1047 if (year < 80) {
1048 year += 2000;
1049 }
1050 else if (year < 100) {
1051 year += 1900;
1052 }
1053
1054 _TOC.set(year, month, day, hour, min, sec);
1055
1056 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1057 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1058 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
1059 return;
1060 }
1061 }
1062
1063 else if ( iLine == 1 ) {
1064 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
1065 readDbl(line, pos[1], fieldLen, _Crs ) ||
1066 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1067 readDbl(line, pos[3], fieldLen, _M0 ) ) {
1068 return;
1069 }
1070 }
1071
1072 else if ( iLine == 2 ) {
1073 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1074 readDbl(line, pos[1], fieldLen, _e ) ||
1075 readDbl(line, pos[2], fieldLen, _Cus ) ||
1076 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
1077 return;
1078 }
1079 }
1080
1081 else if ( iLine == 3 ) {
1082 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
1083 readDbl(line, pos[1], fieldLen, _Cic ) ||
1084 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1085 readDbl(line, pos[3], fieldLen, _Cis ) ) {
1086 return;
1087 }
1088 }
1089
1090 else if ( iLine == 4 ) {
1091 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1092 readDbl(line, pos[1], fieldLen, _Crc ) ||
1093 readDbl(line, pos[2], fieldLen, _omega ) ||
1094 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
1095 return;
1096 }
1097 }
1098
1099 else if ( iLine == 5 ) {
1100 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
1101 readDbl(line, pos[2], fieldLen, _TOEweek) ) {
1102 return;
1103 }
1104 }
1105
1106 else if ( iLine == 6 ) {
1107 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
1108 readDbl(line, pos[1], fieldLen, _E5aHS ) ||
1109 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
1110 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
1111 return;
1112 }
1113 }
1114
1115 else if ( iLine == 7 ) {
1116 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
1117 return;
1118 }
1119 }
1120 }
1121
1122 _ok = true;
1123}
1124
1125//
1126//////////////////////////////////////////////////////////////////////////////
1127QString t_eph::rinexDateStr(const bncTime& tt, const QString& prn,
1128 double version) {
1129
1130 QString datStr;
1131
1132 unsigned year, month, day, hour, min;
1133 double sec;
1134 tt.civil_date(year, month, day);
1135 tt.civil_time(hour, min, sec);
1136
1137 QTextStream out(&datStr);
1138
1139 if (version < 3.0) {
1140 QString prnHlp = prn.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
1141 out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
1142 .arg(year % 100, 2, 10, QChar('0'))
1143 .arg(month, 2)
1144 .arg(day, 2)
1145 .arg(hour, 2)
1146 .arg(min, 2)
1147 .arg(sec, 5, 'f',1);
1148 }
1149 else {
1150 out << prn << QString(" %1 %2 %3 %4 %5 %6")
1151 .arg(year, 4)
1152 .arg(month, 2, 10, QChar('0'))
1153 .arg(day, 2, 10, QChar('0'))
1154 .arg(hour, 2, 10, QChar('0'))
1155 .arg(min, 2, 10, QChar('0'))
1156 .arg(int(sec), 2, 10, QChar('0'));
1157 }
1158
1159 return datStr;
1160}
1161
1162// RINEX Format String
1163//////////////////////////////////////////////////////////////////////////////
1164QString t_ephGPS::toString(double version) const {
1165
1166 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1167
1168 QTextStream out(&rnxStr);
1169
1170 out << QString("%1%2%3\n")
1171 .arg(_clock_bias, 19, 'e', 12)
1172 .arg(_clock_drift, 19, 'e', 12)
1173 .arg(_clock_driftrate, 19, 'e', 12);
1174
1175 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1176
1177 out << QString(fmt)
1178 .arg(_IODE, 19, 'e', 12)
1179 .arg(_Crs, 19, 'e', 12)
1180 .arg(_Delta_n, 19, 'e', 12)
1181 .arg(_M0, 19, 'e', 12);
1182
1183 out << QString(fmt)
1184 .arg(_Cuc, 19, 'e', 12)
1185 .arg(_e, 19, 'e', 12)
1186 .arg(_Cus, 19, 'e', 12)
1187 .arg(_sqrt_A, 19, 'e', 12);
1188
1189 out << QString(fmt)
1190 .arg(_TOEsec, 19, 'e', 12)
1191 .arg(_Cic, 19, 'e', 12)
1192 .arg(_OMEGA0, 19, 'e', 12)
1193 .arg(_Cis, 19, 'e', 12);
1194
1195 out << QString(fmt)
1196 .arg(_i0, 19, 'e', 12)
1197 .arg(_Crc, 19, 'e', 12)
1198 .arg(_omega, 19, 'e', 12)
1199 .arg(_OMEGADOT, 19, 'e', 12);
1200
1201 out << QString(fmt)
1202 .arg(_IDOT, 19, 'e', 12)
1203 .arg(_L2Codes, 19, 'e', 12)
1204 .arg(_TOEweek, 19, 'e', 12)
1205 .arg(_L2PFlag, 19, 'e', 12);
1206
1207 out << QString(fmt)
1208 .arg(_ura, 19, 'e', 12)
1209 .arg(_health, 19, 'e', 12)
1210 .arg(_TGD, 19, 'e', 12)
1211 .arg(_IODC, 19, 'e', 12);
1212
1213 out << QString(fmt)
1214 .arg(_TOT, 19, 'e', 12)
1215 .arg(_fitInterval, 19, 'e', 12)
1216 .arg("", 19, QChar(' '))
1217 .arg("", 19, QChar(' '));
1218
1219 return rnxStr;
1220}
1221
1222// RINEX Format String
1223//////////////////////////////////////////////////////////////////////////////
1224QString t_ephGlo::toString(double version) const {
1225
1226 QString rnxStr = rinexDateStr(_TOC-_gps_utc, _prn, version);
1227
1228 QTextStream out(&rnxStr);
1229
1230 out << QString("%1%2%3\n")
1231 .arg(-_tau, 19, 'e', 12)
1232 .arg(_gamma, 19, 'e', 12)
1233 .arg(_tki, 19, 'e', 12);
1234
1235 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1236
1237 out << QString(fmt)
1238 .arg(_x_pos, 19, 'e', 12)
1239 .arg(_x_velocity, 19, 'e', 12)
1240 .arg(_x_acceleration, 19, 'e', 12)
1241 .arg(_health, 19, 'e', 12);
1242
1243 out << QString(fmt)
1244 .arg(_y_pos, 19, 'e', 12)
1245 .arg(_y_velocity, 19, 'e', 12)
1246 .arg(_y_acceleration, 19, 'e', 12)
1247 .arg(_frequency_number, 19, 'e', 12);
1248
1249 out << QString(fmt)
1250 .arg(_z_pos, 19, 'e', 12)
1251 .arg(_z_velocity, 19, 'e', 12)
1252 .arg(_z_acceleration, 19, 'e', 12)
1253 .arg(_E, 19, 'e', 12);
1254
1255 return rnxStr;
1256}
1257
1258// RINEX Format String
1259//////////////////////////////////////////////////////////////////////////////
1260QString t_ephGal::toString(double version) const {
1261
1262 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1263
1264 QTextStream out(&rnxStr);
1265
1266 out << QString("%1%2%3\n")
1267 .arg(_clock_bias, 19, 'e', 12)
1268 .arg(_clock_drift, 19, 'e', 12)
1269 .arg(_clock_driftrate, 19, 'e', 12);
1270
1271 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1272
1273 out << QString(fmt)
1274 .arg(_IODnav, 19, 'e', 12)
1275 .arg(_Crs, 19, 'e', 12)
1276 .arg(_Delta_n, 19, 'e', 12)
1277 .arg(_M0, 19, 'e', 12);
1278
1279 out << QString(fmt)
1280 .arg(_Cuc, 19, 'e', 12)
1281 .arg(_e, 19, 'e', 12)
1282 .arg(_Cus, 19, 'e', 12)
1283 .arg(_sqrt_A, 19, 'e', 12);
1284
1285 out << QString(fmt)
1286 .arg(_TOEsec, 19, 'e', 12)
1287 .arg(_Cic, 19, 'e', 12)
1288 .arg(_OMEGA0, 19, 'e', 12)
1289 .arg(_Cis, 19, 'e', 12);
1290
1291 out << QString(fmt)
1292 .arg(_i0, 19, 'e', 12)
1293 .arg(_Crc, 19, 'e', 12)
1294 .arg(_omega, 19, 'e', 12)
1295 .arg(_OMEGADOT, 19, 'e', 12);
1296
1297 int dataSource = 0;
1298 double HS = 0.0;
1299 if ( (_flags & GALEPHF_INAV) == GALEPHF_INAV ) {
1300 dataSource |= (1<<0);
1301 dataSource |= (1<<9);
1302 HS = _E5bHS;
1303 }
1304 else if ( (_flags & GALEPHF_FNAV) == GALEPHF_FNAV ) {
1305 dataSource |= (1<<1);
1306 dataSource |= (1<<8);
1307 HS = _E5aHS;
1308 }
1309 out << QString(fmt)
1310 .arg(_IDOT, 19, 'e', 12)
1311 .arg(double(dataSource), 19, 'e', 12)
1312 .arg(_TOEweek, 19, 'e', 12)
1313 .arg(0.0, 19, 'e', 12);
1314
1315 out << QString(fmt)
1316 .arg(_SISA, 19, 'e', 12)
1317 .arg(HS, 19, 'e', 12)
1318 .arg(_BGD_1_5A, 19, 'e', 12)
1319 .arg(_BGD_1_5B, 19, 'e', 12);
1320
1321 out << QString(fmt)
1322 .arg(_TOT, 19, 'e', 12)
1323 .arg("", 19, QChar(' '))
1324 .arg("", 19, QChar(' '))
1325 .arg("", 19, QChar(' '));
1326
1327 return rnxStr;
1328}
1329
Note: See TracBrowser for help on using the repository browser.