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

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

* empty log message *

File size: 19.2 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 unsigned char Array[67];
233 int size = RTCM3GPS(Array);
234 fwrite(Array,size, 1, stdout);
235}
236
237// Returns nearest integer value
238////////////////////////////////////////////////////////////////////////////
239static double NearestInt(double fl, double * remain)
240{
241 bool isneg = fl < 0.0;
242 double intval;
243 if(isneg) fl *= -1.0;
244 intval = (double)((unsigned long)(fl+0.5));
245 if(isneg) {fl *= -1.0; intval *= -1.0;}
246 if(remain)
247 *remain = fl-intval;
248 return intval;
249} /* NearestInt() */
250
251// Returns CRC24
252////////////////////////////////////////////////////////////////////////////
253static unsigned long CRC24(long size, const unsigned char *buf)
254{
255 unsigned long crc = 0;
256 int i;
257
258 while(size--)
259 {
260 crc ^= (*buf++) << (16);
261 for(i = 0; i < 8; i++)
262 {
263 crc <<= 1;
264 if(crc & 0x1000000)
265 crc ^= 0x01864cfb;
266 }
267 }
268 return crc;
269} /* CRC24 */
270
271// build up RTCM3 for GPS
272////////////////////////////////////////////////////////////////////////////
273
274#define GPSTOINT(type, value) static_cast<type>(NearestInt(value,0))
275
276#define GPSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
277 |(GPSTOINT(long long,b)&((1ULL<<a)-1)); \
278 numbits += (a); \
279 while(numbits >= 8) { \
280 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
281#define GPSADDBITSFLOAT(a,b,c) {long long i = GPSTOINT(long long,(b)/(c)); \
282 GPSADDBITS(a,i)};
283
284int t_ephGPS::RTCM3GPS(unsigned char *buffer)
285{
286
287 unsigned char *startbuffer = buffer;
288 buffer= buffer+3;
289 int size = 0;
290 int numbits = 0;
291 unsigned long long bitbuffer = 0;
292
293 GPSADDBITS(12, 1019)
294 GPSADDBITS(6,_prn.right((_prn.length()-1)).toInt())
295 GPSADDBITS(10, _GPSweek)
296 GPSADDBITS(4, _ura)
297 GPSADDBITS(2,_L2Codes)
298 GPSADDBITSFLOAT(14, _IDOT, PI/static_cast<double>(1<<30)
299 /static_cast<double>(1<<13))
300 GPSADDBITS(8, _IODE)
301 GPSADDBITS(16, static_cast<int>(_TOC)>>4)
302 GPSADDBITSFLOAT(8, _clock_driftrate, 1.0/static_cast<double>(1<<30)
303 /static_cast<double>(1<<25))
304 GPSADDBITSFLOAT(16, _clock_drift, 1.0/static_cast<double>(1<<30)
305 /static_cast<double>(1<<13))
306 GPSADDBITSFLOAT(22, _clock_bias, 1.0/static_cast<double>(1<<30)
307 /static_cast<double>(1<<1))
308 GPSADDBITS(10, _IODC)
309 GPSADDBITSFLOAT(16, _Crs, 1.0/static_cast<double>(1<<5))
310 GPSADDBITSFLOAT(16, _Delta_n, PI/static_cast<double>(1<<30)
311 /static_cast<double>(1<<13))
312 GPSADDBITSFLOAT(32, _M0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
313 GPSADDBITSFLOAT(16, _Cuc, 1.0/static_cast<double>(1<<29))
314 GPSADDBITSFLOAT(32, _e, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<3))
315 GPSADDBITSFLOAT(16, _Cus, 1.0/static_cast<double>(1<<29))
316 GPSADDBITSFLOAT(32, _sqrt_A, 1.0/static_cast<double>(1<<19))
317 GPSADDBITS(16, static_cast<int>(_TOE)>>4)
318 GPSADDBITSFLOAT(16, _Cic, 1.0/static_cast<double>(1<<29))
319 GPSADDBITSFLOAT(32, _OMEGA0, PI/static_cast<double>(1<<30)
320 /static_cast<double>(1<<1))
321 GPSADDBITSFLOAT(16, _Cis, 1.0/static_cast<double>(1<<29))
322 GPSADDBITSFLOAT(32, _i0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
323 GPSADDBITSFLOAT(16, _Crc, 1.0/static_cast<double>(1<<5))
324 GPSADDBITSFLOAT(32, _omega, PI/static_cast<double>(1<<30)
325 /static_cast<double>(1<<1))
326 GPSADDBITSFLOAT(24, _OMEGADOT, PI/static_cast<double>(1<<30)
327 /static_cast<double>(1<<13))
328 GPSADDBITSFLOAT(8, _TGD, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
329 GPSADDBITS(6, _health)
330 GPSADDBITS(1, _L2PFlag)
331 GPSADDBITS(1, 0) /* GPS fit interval */
332
333 startbuffer[0]=0xD3;
334 startbuffer[1]=(size >> 8);
335 startbuffer[2]=size;
336 unsigned long i = CRC24(size+3, startbuffer);
337 buffer[size++] = i >> 16;
338 buffer[size++] = i >> 8;
339 buffer[size++] = i;
340 size += 3;
341 return size;
342} /* RTCM3GPS */
343
344// Compute GPS Satellite Position
345////////////////////////////////////////////////////////////////////////////
346void t_ephGPS::position(int GPSweek, double GPSweeks, ColumnVector& xc,
347 ColumnVector& vv) const {
348
349 static const double secPerWeek = 7 * 86400.0;
350 static const double omegaEarth = 7292115.1467e-11;
351 static const double gmWGS = 398.6005e12;
352
353 if (xc.Nrows() < 4) {
354 xc.ReSize(4);
355 }
356 xc = 0.0;
357
358 if (vv.Nrows() < 3) {
359 vv.ReSize(3);
360 }
361 vv = 0.0;
362
363 double a0 = _sqrt_A * _sqrt_A;
364 if (a0 == 0) {
365 return;
366 }
367
368 double n0 = sqrt(gmWGS/(a0*a0*a0));
369 double tk = GPSweeks - _TOE;
370 if (GPSweek != _GPSweek) {
371 tk += (GPSweek - _GPSweek) * secPerWeek;
372 }
373 double n = n0 + _Delta_n;
374 double M = _M0 + n*tk;
375 double E = M;
376 double E_last;
377 do {
378 E_last = E;
379 E = M + _e*sin(E);
380 } while ( fabs(E-E_last)*a0 > 0.001 );
381 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
382 double u0 = v + _omega;
383 double sin2u0 = sin(2*u0);
384 double cos2u0 = cos(2*u0);
385 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
386 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
387 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
388 double xp = r*cos(u);
389 double yp = r*sin(u);
390 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
391 omegaEarth*_TOE;
392
393 double sinom = sin(OM);
394 double cosom = cos(OM);
395 double sini = sin(i);
396 double cosi = cos(i);
397 xc(1) = xp*cosom - yp*cosi*sinom;
398 xc(2) = xp*sinom + yp*cosi*cosom;
399 xc(3) = yp*sini;
400
401 double tc = GPSweeks - _TOC;
402 if (GPSweek != _GPSweek) {
403 tc += (GPSweek - _GPSweek) * secPerWeek;
404 }
405 xc(4) = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc
406 - 4.442807633e-10 * _e * sqrt(a0) *sin(E);
407
408 // Velocity
409 // --------
410 double tanv2 = tan(v/2);
411 double dEdM = 1 / (1 - _e*cos(E));
412 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
413 * dEdM * n;
414 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
415 double dotom = _OMEGADOT - omegaEarth;
416 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
417 double dotr = a0 * _e*sin(E) * dEdM * n
418 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
419 double dotx = dotr*cos(u) - r*sin(u)*dotu;
420 double doty = dotr*sin(u) + r*cos(u)*dotu;
421
422 vv(1) = cosom *dotx - cosi*sinom *doty // dX / dr
423 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
424 + yp*sini*sinom*doti; // dX / di
425
426 vv(2) = sinom *dotx + cosi*cosom *doty
427 + xp*cosom*dotom - yp*cosi*sinom*dotom
428 - yp*sini*cosom*doti;
429
430 vv(3) = sini *doty + yp*cosi *doti;
431}
432
433// Read Glonass Ephemeris
434////////////////////////////////////////////////////////////////////////////
435void t_ephGlo::read(const QStringList& lines) {
436
437 for (int ii = 1; ii <= lines.size(); ii++) {
438 QTextStream in(lines.at(ii-1).toAscii());
439
440 if (ii == 1) {
441 double year, month, day, hour, minute, second;
442 in >> _prn >> year >> month >> day >> hour >> minute >> second
443 >> _tau >> _gamma >> _tki;
444
445 _tau = -_tau;
446
447 if (year < 100) year += 2000;
448
449 QDateTime* dateTime = new QDateTime(QDate(int(year), int(month), int(day)),
450 QTime(int(hour), int(minute), int(second)), Qt::UTC);
451
452 GPSweekFromDateAndTime(*dateTime, _GPSweek, _GPSweeks);
453
454 delete dateTime;
455
456 //// beg test
457 //// _gps_utc = 14.0;
458 //// end test
459
460 _GPSweeks += _gps_utc;
461 }
462 else if (ii == 2) {
463 in >>_x_pos >> _x_velocity >> _x_acceleration >> _health;
464 }
465 else if (ii == 3) {
466 in >>_y_pos >> _y_velocity >> _y_acceleration >> _frequency_number;
467 }
468 else if (ii == 4) {
469 in >>_z_pos >> _z_velocity >> _z_acceleration >> _E;
470 }
471 }
472
473 // Initialize status vector
474 // ------------------------
475 _tt = _GPSweeks;
476
477 _xv(1) = _x_pos * 1.e3;
478 _xv(2) = _y_pos * 1.e3;
479 _xv(3) = _z_pos * 1.e3;
480 _xv(4) = _x_velocity * 1.e3;
481 _xv(5) = _y_velocity * 1.e3;
482 _xv(6) = _z_velocity * 1.e3;
483 unsigned char Array[51];
484 int size = RTCM3GLO(Array);
485 fwrite(Array,size, 1, stdout);
486}
487
488
489// build up RTCM3 for GLONASS
490////////////////////////////////////////////////////////////////////////////
491#define GLONASSTOINT(type, value) static_cast<type>(NearestInt(value,0))
492
493#define GLONASSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
494 |(GLONASSTOINT(long long,b)&((1ULL<<(a))-1)); \
495 numbits += (a); \
496 while(numbits >= 8) { \
497 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
498#define GLONASSADDBITSFLOATM(a,b,c) {int s; long long i; \
499 if(b < 0.0) \
500 { \
501 s = 1; \
502 i = GLONASSTOINT(long long,(-b)/(c)); \
503 if(!i) s = 0; \
504 } \
505 else \
506 { \
507 s = 0; \
508 i = GLONASSTOINT(long long,(b)/(c)); \
509 } \
510 GLONASSADDBITS(1,s) \
511 GLONASSADDBITS(a-1,i)}
512
513int t_ephGlo::RTCM3GLO(unsigned char *buffer)
514{
515
516 int size = 0;
517 int numbits = 0;
518 long long bitbuffer = 0;
519 unsigned char *startbuffer = buffer;
520 buffer= buffer+3;
521
522 GLONASSADDBITS(12, 1020)
523 GLONASSADDBITS(6, _prn.right((_prn.length()-1)).toInt())
524 GLONASSADDBITS(5, 7+_frequency_number)
525 GLONASSADDBITS(1, 0)
526 GLONASSADDBITS(1, 0)
527 GLONASSADDBITS(2, 0)
528 _tki=_tki+3*60*60;
529 GLONASSADDBITS(5, static_cast<int>(_tki)/(60*60))
530 GLONASSADDBITS(6, (static_cast<int>(_tki)/60)%60)
531 GLONASSADDBITS(1, (static_cast<int>(_tki)/30)%30)
532 GLONASSADDBITS(1, _health)
533 GLONASSADDBITS(1, 0)
534 unsigned long long timeofday = (static_cast<int>(_tt+3*60*60-_gps_utc)%86400);
535 GLONASSADDBITS(7, timeofday/60/15)
536 GLONASSADDBITSFLOATM(24, _x_velocity*1000, 1000.0/static_cast<double>(1<<20))
537 GLONASSADDBITSFLOATM(27, _x_pos*1000, 1000.0/static_cast<double>(1<<11))
538 GLONASSADDBITSFLOATM(5, _x_acceleration*1000, 1000.0/static_cast<double>(1<<30))
539 GLONASSADDBITSFLOATM(24, _y_velocity*1000, 1000.0/static_cast<double>(1<<20))
540 GLONASSADDBITSFLOATM(27, _y_pos*1000, 1000.0/static_cast<double>(1<<11))
541 GLONASSADDBITSFLOATM(5, _y_acceleration*1000, 1000.0/static_cast<double>(1<<30))
542 GLONASSADDBITSFLOATM(24, _z_velocity*1000, 1000.0/static_cast<double>(1<<20))
543 GLONASSADDBITSFLOATM(27,_z_pos*1000, 1000.0/static_cast<double>(1<<11))
544 GLONASSADDBITSFLOATM(5, _z_acceleration*1000, 1000.0/static_cast<double>(1<<30))
545 GLONASSADDBITS(1, 0)
546 GLONASSADDBITSFLOATM(11, _gamma, 1.0/static_cast<double>(1<<30)
547 /static_cast<double>(1<<10))
548 GLONASSADDBITS(2, 0) /* GLONASS-M P */
549 GLONASSADDBITS(1, 0) /* GLONASS-M ln(3) */
550 GLONASSADDBITSFLOATM(22, _tau, 1.0/static_cast<double>(1<<30))
551 GLONASSADDBITS(5, 0) /* GLONASS-M delta tau */
552 GLONASSADDBITS(5, _E)
553 GLONASSADDBITS(1, 0) /* GLONASS-M P4 */
554 GLONASSADDBITS(4, 0) /* GLONASS-M FT */
555 GLONASSADDBITS(11, 0) /* GLONASS-M NT */
556 GLONASSADDBITS(2, 0) /* GLONASS-M active? */
557 GLONASSADDBITS(1, 0) /* GLONASS additional data */
558 GLONASSADDBITS(11, 0) /* GLONASS NA */
559 GLONASSADDBITS(32, 0) /* GLONASS tau C */
560 GLONASSADDBITS(5, 0) /* GLONASS-M N4 */
561 GLONASSADDBITS(22, 0) /* GLONASS-M tau GPS */
562 GLONASSADDBITS(1, 0) /* GLONASS-M ln(5) */
563 GLONASSADDBITS(7, 0) /* Reserved */
564
565 startbuffer[0]=0xD3;
566 startbuffer[1]=(size >> 8);
567 startbuffer[2]=size;
568 unsigned long i = CRC24(size+3, startbuffer);
569 buffer[size++] = i >> 16;
570 buffer[size++] = i >> 8;
571 buffer[size++] = i;
572 size += 3;
573 return size;
574} /* RTCM3GLO */
575
576// Derivative of the state vector using a simple force model (static)
577////////////////////////////////////////////////////////////////////////////
578ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv) {
579
580 // State vector components
581 // -----------------------
582 ColumnVector rr = xv.rows(1,3);
583 ColumnVector vv = xv.rows(4,6);
584
585 // Acceleration
586 // ------------
587 static const double GM = 398.60044e12;
588 static const double AE = 6378136.0;
589 static const double OMEGA = 7292115.e-11;
590 static const double C20 = -1082.63e-6;
591
592 double rho = rr.norm_Frobenius();
593 double t1 = -GM/(rho*rho*rho);
594 double t2 = 3.0/2.0 * C20 * (GM*AE*AE) / (rho*rho*rho*rho*rho);
595 double t3 = OMEGA * OMEGA;
596 double t4 = 2.0 * OMEGA;
597 double z2 = rr(3) * rr(3);
598
599 // Vector of derivatives
600 // ---------------------
601 ColumnVector va(6);
602 va(1) = vv(1);
603 va(2) = vv(2);
604 va(3) = vv(3);
605 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2);
606 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1);
607 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3);
608
609 return va;
610}
611
612// Compute Glonass Satellite Position
613////////////////////////////////////////////////////////////////////////////
614void t_ephGlo::position(int GPSweek, double GPSweeks, ColumnVector& xc,
615 ColumnVector& vv) const {
616
617 static const double secPerWeek = 7 * 86400.0;
618 static const double nominalStep = 10.0;
619
620 double dtPos = GPSweeks - _tt;
621 if (GPSweek != _GPSweek) {
622 dtPos += (GPSweek - _GPSweek) * secPerWeek;
623 }
624
625 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
626 double step = dtPos / nSteps;
627
628 for (int ii = 1; ii <= nSteps; ii++) {
629 _xv = rungeKutta4(_tt, _xv, step, glo_deriv);
630 _tt += step;
631 }
632
633 // Position and Velocity
634 // ---------------------
635 xc(1) = _xv(1);
636 xc(2) = _xv(2);
637 xc(3) = _xv(3);
638
639 vv(1) = _xv(4);
640 vv(2) = _xv(5);
641 vv(3) = _xv(6);
642
643 // Clock Correction
644 // ----------------
645 double dtClk = GPSweeks - _GPSweeks;
646 if (GPSweek != _GPSweek) {
647 dtClk += (GPSweek - _GPSweek) * secPerWeek;
648 }
649 xc(4) = -_tau + _gamma * dtClk;
650}
651
652// Glonass IOD
653////////////////////////////////////////////////////////////////////////////
654int t_ephGlo::IOD() const {
655 //// return int(fmod(_GPSweeks,86400.0)) / 600;
656
657 //// unsigned int tb = int(fmod(_GPSweeks,86400.0)) * 1000; // msec of day
658 unsigned int tb = int(fmod(_GPSweeks,86400.0)); //sec of day
659
660 // 5 LSBs of iod are equal to 5 LSBs of tb, remaining bits are zero
661 // ----------------------------------------------------------------
662 const int shift = sizeof(tb) * 8 - 5;
663 unsigned int iod = tb << shift;
664 return (iod >> shift);
665}
Note: See TracBrowser for help on using the repository browser.