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