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

Last change on this file since 2014 was 2014, checked in by mervart, 14 years ago

* empty log message *

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