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