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

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