source: ntrip/trunk/BNS/bnseph.cpp@ 1879

Last change on this file since 1879 was 1867, checked in by mervart, 15 years ago

* empty log message *

File size: 19.0 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
5 * Class: bnseph
6 *
7 * Purpose: Retrieve broadcast ephemeris from BNC
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Mar-2008
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18
19#include "bnseph.h"
20#include "bnsutils.h"
21#include "bnssettings.h"
22
23#define PI 3.1415926535898
24
25using namespace std;
26
27// Constructor
28////////////////////////////////////////////////////////////////////////////
29t_bnseph::t_bnseph(QObject* parent) : QThread(parent) {
30
31 this->setTerminationEnabled(true);
32
33 _socket = 0;
34
35 bnsSettings settings;
36
37 QIODevice::OpenMode oMode;
38 if (Qt::CheckState(settings.value("fileAppend").toInt()) == Qt::Checked) {
39 oMode = QIODevice::WriteOnly | QIODevice::Unbuffered | QIODevice::Append;
40 }
41 else {
42 oMode = QIODevice::WriteOnly | QIODevice::Unbuffered;
43 }
44
45 // Echo ephemeris into a file
46 // ---------------------------
47 QString echoFileName = settings.value("ephEcho").toString();
48 if (echoFileName.isEmpty()) {
49 _echoFile = 0;
50 _echoStream = 0;
51 }
52 else {
53 _echoFile = new QFile(echoFileName);
54 if (_echoFile->open(oMode)) {
55 _echoStream = new QTextStream(_echoFile);
56 }
57 else {
58 _echoStream = 0;
59 }
60 }
61}
62
63// Destructor
64////////////////////////////////////////////////////////////////////////////
65t_bnseph::~t_bnseph() {
66 delete _socket;
67 delete _echoStream;
68 delete _echoFile;
69}
70
71// Connect the Socket
72////////////////////////////////////////////////////////////////////////////
73void t_bnseph::reconnect() {
74
75 delete _socket;
76
77 bnsSettings settings;
78 QString host = settings.value("ephHost").toString();
79 if (host.isEmpty()) {
80 host = "localhost";
81 }
82 int port = settings.value("ephPort").toInt();
83
84 _socket = new QTcpSocket();
85 _socket->connectToHost(host, port);
86
87 const int timeOut = 10*1000; // 10 seconds
88 if (!_socket->waitForConnected(timeOut)) {
89// emit(newMessage("bnseph::run Connect Timeout"));
90 emit(newMessage("Ephemeris server: Connection timeout")); // weber
91 msleep(1000);
92 }
93}
94
95// Start
96////////////////////////////////////////////////////////////////////////////
97void t_bnseph::run() {
98
99//emit(newMessage("bnseph::run Start"));
100 emit(newMessage("Ephemeris server: Connection opened")); // weber
101
102 while (true) {
103 if (_socket == 0 || _socket->state() != QAbstractSocket::ConnectedState) {
104 reconnect();
105 }
106 if (_socket && _socket->state() == QAbstractSocket::ConnectedState) {
107 readEph();
108 }
109 else {
110 msleep(10);
111 }
112 }
113}
114
115// Read One Ephemeris
116////////////////////////////////////////////////////////////////////////////
117void t_bnseph::readEph() {
118
119 int nBytes = 0;
120 t_eph* eph = 0;
121
122 QByteArray line = waitForLine(_socket);
123
124 if (line.isEmpty()) {
125 return;
126 }
127
128 if (_echoStream) {
129 *_echoStream << line;
130 _echoStream->flush();
131 }
132
133 nBytes += line.length();
134
135 QTextStream in(line);
136 QString prn;
137
138 in >> prn;
139
140 int numlines = 0;
141 if (prn.indexOf('R') != -1) {
142 eph = new t_ephGlo();
143 numlines = 4;
144 }
145 else {
146 eph = new t_ephGPS();
147 numlines = 8;
148 }
149
150 QStringList lines;
151 lines << line;
152
153 for (int ii = 2; ii <= numlines; ii++) {
154 QByteArray line = waitForLine(_socket);
155 if (line.isEmpty()) {
156 delete eph;
157 return;
158 }
159
160 if (_echoStream) {
161 *_echoStream << line;
162 _echoStream->flush();
163 }
164
165 nBytes += line.length();
166 lines << line;
167 }
168
169 eph->read(lines);
170
171 emit(newEph(eph, nBytes));
172}
173
174// Compare Time
175////////////////////////////////////////////////////////////////////////////
176bool t_eph::isNewerThan(const t_eph* eph) const {
177 if (_GPSweek > eph->_GPSweek ||
178 (_GPSweek == eph->_GPSweek && _GPSweeks > eph->_GPSweeks)) {
179 return true;
180 }
181 else {
182 return false;
183 }
184}
185
186// Read GPS Ephemeris
187////////////////////////////////////////////////////////////////////////////
188void t_ephGPS::read(const QStringList& lines) {
189
190 for (int ii = 1; ii <= lines.size(); ii++) {
191 QTextStream in(lines.at(ii-1).toAscii());
192
193 if (ii == 1) {
194 double year, month, day, hour, minute, second;
195 in >> _prn >> year >> month >> day >> hour >> minute >> second
196 >> _clock_bias >> _clock_drift >> _clock_driftrate;
197
198 if (year < 100) year += 2000;
199
200 QDateTime* dateTime = new QDateTime(QDate(int(year), int(month), int(day)),
201 QTime(int(hour), int(minute), int(second)), Qt::UTC);
202
203 GPSweekFromDateAndTime(*dateTime, _GPSweek, _GPSweeks);
204
205 delete dateTime;
206
207 _TOC = _GPSweeks;
208 }
209 else if (ii == 2) {
210 in >> _IODE >> _Crs >> _Delta_n >> _M0;
211 }
212 else if (ii == 3) {
213 in >> _Cuc >> _e >> _Cus >> _sqrt_A;
214 }
215 else if (ii == 4) {
216 in >> _TOE >> _Cic >> _OMEGA0 >> _Cis;
217 }
218 else if (ii == 5) {
219 in >> _i0 >> _Crc >> _omega >> _OMEGADOT;
220 }
221 else if (ii == 6) {
222 double GPSweek;
223 in >> _IDOT >> _L2Codes >> GPSweek >> _L2PFlag;
224 }
225 else if (ii == 7) {
226 in >> _ura >> _health >> _TGD >> _IODC;
227 }
228 else if (ii == 8) {
229 in >> _TOW;
230 }
231 }
232}
233
234// Returns nearest integer value
235////////////////////////////////////////////////////////////////////////////
236static double NearestInt(double fl, double * remain)
237{
238 bool isneg = fl < 0.0;
239 double intval;
240 if(isneg) fl *= -1.0;
241 intval = (double)((unsigned long)(fl+0.5));
242 if(isneg) {fl *= -1.0; intval *= -1.0;}
243 if(remain)
244 *remain = fl-intval;
245 return intval;
246} /* NearestInt() */
247
248// Returns CRC24
249////////////////////////////////////////////////////////////////////////////
250static unsigned long CRC24(long size, const unsigned char *buf)
251{
252 unsigned long crc = 0;
253 int i;
254
255 while(size--)
256 {
257 crc ^= (*buf++) << (16);
258 for(i = 0; i < 8; i++)
259 {
260 crc <<= 1;
261 if(crc & 0x1000000)
262 crc ^= 0x01864cfb;
263 }
264 }
265 return crc;
266} /* CRC24 */
267
268// build up RTCM3 for GPS
269////////////////////////////////////////////////////////////////////////////
270
271#define GPSTOINT(type, value) static_cast<type>(NearestInt(value,0))
272
273#define GPSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
274 |(GPSTOINT(long long,b)&((1ULL<<a)-1)); \
275 numbits += (a); \
276 while(numbits >= 8) { \
277 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
278#define GPSADDBITSFLOAT(a,b,c) {long long i = GPSTOINT(long long,(b)/(c)); \
279 GPSADDBITS(a,i)};
280
281int t_ephGPS::RTCM3(unsigned char *buffer)
282{
283
284 unsigned char *startbuffer = buffer;
285 buffer= buffer+3;
286 int size = 0;
287 int numbits = 0;
288 unsigned long long bitbuffer = 0;
289
290 GPSADDBITS(12, 1019)
291 GPSADDBITS(6,_prn.right((_prn.length()-1)).toInt())
292 GPSADDBITS(10, _GPSweek)
293 GPSADDBITS(4, _ura)
294 GPSADDBITS(2,_L2Codes)
295 GPSADDBITSFLOAT(14, _IDOT, PI/static_cast<double>(1<<30)
296 /static_cast<double>(1<<13))
297 GPSADDBITS(8, _IODE)
298 GPSADDBITS(16, static_cast<int>(_TOC)>>4)
299 GPSADDBITSFLOAT(8, _clock_driftrate, 1.0/static_cast<double>(1<<30)
300 /static_cast<double>(1<<25))
301 GPSADDBITSFLOAT(16, _clock_drift, 1.0/static_cast<double>(1<<30)
302 /static_cast<double>(1<<13))
303 GPSADDBITSFLOAT(22, _clock_bias, 1.0/static_cast<double>(1<<30)
304 /static_cast<double>(1<<1))
305 GPSADDBITS(10, _IODC)
306 GPSADDBITSFLOAT(16, _Crs, 1.0/static_cast<double>(1<<5))
307 GPSADDBITSFLOAT(16, _Delta_n, PI/static_cast<double>(1<<30)
308 /static_cast<double>(1<<13))
309 GPSADDBITSFLOAT(32, _M0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
310 GPSADDBITSFLOAT(16, _Cuc, 1.0/static_cast<double>(1<<29))
311 GPSADDBITSFLOAT(32, _e, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<3))
312 GPSADDBITSFLOAT(16, _Cus, 1.0/static_cast<double>(1<<29))
313 GPSADDBITSFLOAT(32, _sqrt_A, 1.0/static_cast<double>(1<<19))
314 GPSADDBITS(16, static_cast<int>(_TOE)>>4)
315 GPSADDBITSFLOAT(16, _Cic, 1.0/static_cast<double>(1<<29))
316 GPSADDBITSFLOAT(32, _OMEGA0, PI/static_cast<double>(1<<30)
317 /static_cast<double>(1<<1))
318 GPSADDBITSFLOAT(16, _Cis, 1.0/static_cast<double>(1<<29))
319 GPSADDBITSFLOAT(32, _i0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
320 GPSADDBITSFLOAT(16, _Crc, 1.0/static_cast<double>(1<<5))
321 GPSADDBITSFLOAT(32, _omega, PI/static_cast<double>(1<<30)
322 /static_cast<double>(1<<1))
323 GPSADDBITSFLOAT(24, _OMEGADOT, PI/static_cast<double>(1<<30)
324 /static_cast<double>(1<<13))
325 GPSADDBITSFLOAT(8, _TGD, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
326 GPSADDBITS(6, _health)
327 GPSADDBITS(1, _L2PFlag)
328 GPSADDBITS(1, 0) /* GPS fit interval */
329
330 startbuffer[0]=0xD3;
331 startbuffer[1]=(size >> 8);
332 startbuffer[2]=size;
333 unsigned long i = CRC24(size+3, startbuffer);
334 buffer[size++] = i >> 16;
335 buffer[size++] = i >> 8;
336 buffer[size++] = i;
337 size += 3;
338 return size;
339}
340
341// Compute GPS Satellite Position
342////////////////////////////////////////////////////////////////////////////
343void t_ephGPS::position(int GPSweek, double GPSweeks, ColumnVector& xc,
344 ColumnVector& vv) const {
345
346 static const double secPerWeek = 7 * 86400.0;
347 static const double omegaEarth = 7292115.1467e-11;
348 static const double gmWGS = 398.6005e12;
349
350 if (xc.Nrows() < 4) {
351 xc.ReSize(4);
352 }
353 xc = 0.0;
354
355 if (vv.Nrows() < 3) {
356 vv.ReSize(3);
357 }
358 vv = 0.0;
359
360 double a0 = _sqrt_A * _sqrt_A;
361 if (a0 == 0) {
362 return;
363 }
364
365 double n0 = sqrt(gmWGS/(a0*a0*a0));
366 double tk = GPSweeks - _TOE;
367 if (GPSweek != _GPSweek) {
368 tk += (GPSweek - _GPSweek) * secPerWeek;
369 }
370 double n = n0 + _Delta_n;
371 double M = _M0 + n*tk;
372 double E = M;
373 double E_last;
374 do {
375 E_last = E;
376 E = M + _e*sin(E);
377 } while ( fabs(E-E_last)*a0 > 0.001 );
378 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
379 double u0 = v + _omega;
380 double sin2u0 = sin(2*u0);
381 double cos2u0 = cos(2*u0);
382 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
383 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
384 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
385 double xp = r*cos(u);
386 double yp = r*sin(u);
387 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
388 omegaEarth*_TOE;
389
390 double sinom = sin(OM);
391 double cosom = cos(OM);
392 double sini = sin(i);
393 double cosi = cos(i);
394 xc(1) = xp*cosom - yp*cosi*sinom;
395 xc(2) = xp*sinom + yp*cosi*cosom;
396 xc(3) = yp*sini;
397
398 double tc = GPSweeks - _TOC;
399 if (GPSweek != _GPSweek) {
400 tc += (GPSweek - _GPSweek) * secPerWeek;
401 }
402 xc(4) = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc
403 - 4.442807633e-10 * _e * sqrt(a0) *sin(E);
404
405 // Velocity
406 // --------
407 double tanv2 = tan(v/2);
408 double dEdM = 1 / (1 - _e*cos(E));
409 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
410 * dEdM * n;
411 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
412 double dotom = _OMEGADOT - omegaEarth;
413 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
414 double dotr = a0 * _e*sin(E) * dEdM * n
415 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
416 double dotx = dotr*cos(u) - r*sin(u)*dotu;
417 double doty = dotr*sin(u) + r*cos(u)*dotu;
418
419 vv(1) = cosom *dotx - cosi*sinom *doty // dX / dr
420 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
421 + yp*sini*sinom*doti; // dX / di
422
423 vv(2) = sinom *dotx + cosi*cosom *doty
424 + xp*cosom*dotom - yp*cosi*sinom*dotom
425 - yp*sini*cosom*doti;
426
427 vv(3) = sini *doty + yp*cosi *doti;
428}
429
430// Read Glonass Ephemeris
431////////////////////////////////////////////////////////////////////////////
432void t_ephGlo::read(const QStringList& lines) {
433
434 for (int ii = 1; ii <= lines.size(); ii++) {
435 QTextStream in(lines.at(ii-1).toAscii());
436
437 if (ii == 1) {
438 double year, month, day, hour, minute, second;
439 in >> _prn >> year >> month >> day >> hour >> minute >> second
440 >> _tau >> _gamma >> _tki;
441
442 _tau = -_tau;
443
444 if (year < 100) year += 2000;
445
446 QDateTime* dateTime = new QDateTime(QDate(int(year), int(month), int(day)),
447 QTime(int(hour), int(minute), int(second)), Qt::UTC);
448
449 GPSweekFromDateAndTime(*dateTime, _GPSweek, _GPSweeks);
450
451 delete dateTime;
452
453 //// beg test
454 //// _gps_utc = 14.0;
455 //// end test
456
457 _GPSweeks += _gps_utc;
458 }
459 else if (ii == 2) {
460 in >>_x_pos >> _x_velocity >> _x_acceleration >> _health;
461 }
462 else if (ii == 3) {
463 in >>_y_pos >> _y_velocity >> _y_acceleration >> _frequency_number;
464 }
465 else if (ii == 4) {
466 in >>_z_pos >> _z_velocity >> _z_acceleration >> _E;
467 }
468 }
469
470 // Initialize status vector
471 // ------------------------
472 _tt = _GPSweeks;
473
474 _xv(1) = _x_pos * 1.e3;
475 _xv(2) = _y_pos * 1.e3;
476 _xv(3) = _z_pos * 1.e3;
477 _xv(4) = _x_velocity * 1.e3;
478 _xv(5) = _y_velocity * 1.e3;
479 _xv(6) = _z_velocity * 1.e3;
480}
481
482
483// build up RTCM3 for GLONASS
484////////////////////////////////////////////////////////////////////////////
485#define GLONASSTOINT(type, value) static_cast<type>(NearestInt(value,0))
486
487#define GLONASSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
488 |(GLONASSTOINT(long long,b)&((1ULL<<(a))-1)); \
489 numbits += (a); \
490 while(numbits >= 8) { \
491 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
492#define GLONASSADDBITSFLOATM(a,b,c) {int s; long long i; \
493 if(b < 0.0) \
494 { \
495 s = 1; \
496 i = GLONASSTOINT(long long,(-b)/(c)); \
497 if(!i) s = 0; \
498 } \
499 else \
500 { \
501 s = 0; \
502 i = GLONASSTOINT(long long,(b)/(c)); \
503 } \
504 GLONASSADDBITS(1,s) \
505 GLONASSADDBITS(a-1,i)}
506
507int t_ephGlo::RTCM3(unsigned char *buffer)
508{
509
510 int size = 0;
511 int numbits = 0;
512 long long bitbuffer = 0;
513 unsigned char *startbuffer = buffer;
514 buffer= buffer+3;
515
516 GLONASSADDBITS(12, 1020)
517 GLONASSADDBITS(6, _prn.right((_prn.length()-1)).toInt())
518 GLONASSADDBITS(5, 7+_frequency_number)
519 GLONASSADDBITS(1, 0)
520 GLONASSADDBITS(1, 0)
521 GLONASSADDBITS(2, 0)
522 _tki=_tki+3*60*60;
523 GLONASSADDBITS(5, static_cast<int>(_tki)/(60*60))
524 GLONASSADDBITS(6, (static_cast<int>(_tki)/60)%60)
525 GLONASSADDBITS(1, (static_cast<int>(_tki)/30)%30)
526 GLONASSADDBITS(1, _health)
527 GLONASSADDBITS(1, 0)
528 unsigned long long timeofday = (static_cast<int>(_tt+3*60*60-_gps_utc)%86400);
529 GLONASSADDBITS(7, timeofday/60/15)
530 GLONASSADDBITSFLOATM(24, _x_velocity*1000, 1000.0/static_cast<double>(1<<20))
531 GLONASSADDBITSFLOATM(27, _x_pos*1000, 1000.0/static_cast<double>(1<<11))
532 GLONASSADDBITSFLOATM(5, _x_acceleration*1000, 1000.0/static_cast<double>(1<<30))
533 GLONASSADDBITSFLOATM(24, _y_velocity*1000, 1000.0/static_cast<double>(1<<20))
534 GLONASSADDBITSFLOATM(27, _y_pos*1000, 1000.0/static_cast<double>(1<<11))
535 GLONASSADDBITSFLOATM(5, _y_acceleration*1000, 1000.0/static_cast<double>(1<<30))
536 GLONASSADDBITSFLOATM(24, _z_velocity*1000, 1000.0/static_cast<double>(1<<20))
537 GLONASSADDBITSFLOATM(27,_z_pos*1000, 1000.0/static_cast<double>(1<<11))
538 GLONASSADDBITSFLOATM(5, _z_acceleration*1000, 1000.0/static_cast<double>(1<<30))
539 GLONASSADDBITS(1, 0)
540 GLONASSADDBITSFLOATM(11, _gamma, 1.0/static_cast<double>(1<<30)
541 /static_cast<double>(1<<10))
542 GLONASSADDBITS(2, 0) /* GLONASS-M P */
543 GLONASSADDBITS(1, 0) /* GLONASS-M ln(3) */
544 GLONASSADDBITSFLOATM(22, _tau, 1.0/static_cast<double>(1<<30))
545 GLONASSADDBITS(5, 0) /* GLONASS-M delta tau */
546 GLONASSADDBITS(5, _E)
547 GLONASSADDBITS(1, 0) /* GLONASS-M P4 */
548 GLONASSADDBITS(4, 0) /* GLONASS-M FT */
549 GLONASSADDBITS(11, 0) /* GLONASS-M NT */
550 GLONASSADDBITS(2, 0) /* GLONASS-M active? */
551 GLONASSADDBITS(1, 0) /* GLONASS additional data */
552 GLONASSADDBITS(11, 0) /* GLONASS NA */
553 GLONASSADDBITS(32, 0) /* GLONASS tau C */
554 GLONASSADDBITS(5, 0) /* GLONASS-M N4 */
555 GLONASSADDBITS(22, 0) /* GLONASS-M tau GPS */
556 GLONASSADDBITS(1, 0) /* GLONASS-M ln(5) */
557 GLONASSADDBITS(7, 0) /* Reserved */
558
559 startbuffer[0]=0xD3;
560 startbuffer[1]=(size >> 8);
561 startbuffer[2]=size;
562 unsigned long i = CRC24(size+3, startbuffer);
563 buffer[size++] = i >> 16;
564 buffer[size++] = i >> 8;
565 buffer[size++] = i;
566 size += 3;
567 return size;
568}
569
570// Derivative of the state vector using a simple force model (static)
571////////////////////////////////////////////////////////////////////////////
572ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv) {
573
574 // State vector components
575 // -----------------------
576 ColumnVector rr = xv.rows(1,3);
577 ColumnVector vv = xv.rows(4,6);
578
579 // Acceleration
580 // ------------
581 static const double GM = 398.60044e12;
582 static const double AE = 6378136.0;
583 static const double OMEGA = 7292115.e-11;
584 static const double C20 = -1082.63e-6;
585
586 double rho = rr.norm_Frobenius();
587 double t1 = -GM/(rho*rho*rho);
588 double t2 = 3.0/2.0 * C20 * (GM*AE*AE) / (rho*rho*rho*rho*rho);
589 double t3 = OMEGA * OMEGA;
590 double t4 = 2.0 * OMEGA;
591 double z2 = rr(3) * rr(3);
592
593 // Vector of derivatives
594 // ---------------------
595 ColumnVector va(6);
596 va(1) = vv(1);
597 va(2) = vv(2);
598 va(3) = vv(3);
599 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2);
600 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1);
601 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3);
602
603 return va;
604}
605
606// Compute Glonass Satellite Position
607////////////////////////////////////////////////////////////////////////////
608void t_ephGlo::position(int GPSweek, double GPSweeks, ColumnVector& xc,
609 ColumnVector& vv) const {
610
611 static const double secPerWeek = 7 * 86400.0;
612 static const double nominalStep = 10.0;
613
614 double dtPos = GPSweeks - _tt;
615 if (GPSweek != _GPSweek) {
616 dtPos += (GPSweek - _GPSweek) * secPerWeek;
617 }
618
619 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
620 double step = dtPos / nSteps;
621
622 for (int ii = 1; ii <= nSteps; ii++) {
623 _xv = rungeKutta4(_tt, _xv, step, glo_deriv);
624 _tt += step;
625 }
626
627 // Position and Velocity
628 // ---------------------
629 xc(1) = _xv(1);
630 xc(2) = _xv(2);
631 xc(3) = _xv(3);
632
633 vv(1) = _xv(4);
634 vv(2) = _xv(5);
635 vv(3) = _xv(6);
636
637 // Clock Correction
638 // ----------------
639 double dtClk = GPSweeks - _GPSweeks;
640 if (GPSweek != _GPSweek) {
641 dtClk += (GPSweek - _GPSweek) * secPerWeek;
642 }
643 xc(4) = -_tau + _gamma * dtClk;
644}
645
646// Glonass IOD
647////////////////////////////////////////////////////////////////////////////
648int t_ephGlo::IOD() const {
649 //// return int(fmod(_GPSweeks,86400.0)) / 600;
650
651 //// unsigned int tb = int(fmod(_GPSweeks,86400.0)) * 1000; // msec of day
652 unsigned int tb = int(fmod(_GPSweeks,86400.0)); //sec of day
653
654 // 5 LSBs of iod are equal to 5 LSBs of tb, remaining bits are zero
655 // ----------------------------------------------------------------
656 const int shift = sizeof(tb) * 8 - 5;
657 unsigned int iod = tb << shift;
658 return (iod >> shift);
659}
Note: See TracBrowser for help on using the repository browser.