[1025] | 1 | #include <sstream>
|
---|
[2234] | 2 | #include <iostream>
|
---|
[1025] | 3 | #include <iomanip>
|
---|
[1239] | 4 | #include <cstring>
|
---|
[1025] | 5 |
|
---|
[2234] | 6 | #include <newmatio.h>
|
---|
| 7 |
|
---|
[1025] | 8 | #include "ephemeris.h"
|
---|
[2221] | 9 | #include "bncutils.h"
|
---|
[2285] | 10 | #include "bnctime.h"
|
---|
[5070] | 11 | #include "bnccore.h"
|
---|
[5839] | 12 | #include "bncutils.h"
|
---|
[6141] | 13 | #include "satObs.h"
|
---|
[6044] | 14 | #include "pppInclude.h"
|
---|
[6400] | 15 | #include "pppModel.h"
|
---|
[1025] | 16 |
|
---|
| 17 | using namespace std;
|
---|
| 18 |
|
---|
[5749] | 19 | // Constructor
|
---|
| 20 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 21 | t_eph::t_eph() {
|
---|
[6518] | 22 | _checkState = unchecked;
|
---|
| 23 | _orbCorr = 0;
|
---|
| 24 | _clkCorr = 0;
|
---|
[5749] | 25 | }
|
---|
| 26 |
|
---|
| 27 | //
|
---|
| 28 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6141] | 29 | void t_eph::setOrbCorr(const t_orbCorr* orbCorr) {
|
---|
[5749] | 30 | delete _orbCorr;
|
---|
[6141] | 31 | _orbCorr = new t_orbCorr(*orbCorr);
|
---|
[5749] | 32 | }
|
---|
| 33 |
|
---|
| 34 | //
|
---|
| 35 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6141] | 36 | void t_eph::setClkCorr(const t_clkCorr* clkCorr) {
|
---|
[5749] | 37 | delete _clkCorr;
|
---|
[6141] | 38 | _clkCorr = new t_clkCorr(*clkCorr);
|
---|
[5749] | 39 | }
|
---|
| 40 |
|
---|
| 41 | //
|
---|
| 42 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6109] | 43 | t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
|
---|
[6518] | 44 |
|
---|
| 45 | if (_checkState == bad) {
|
---|
| 46 | return failure;
|
---|
| 47 | }
|
---|
[6556] | 48 | const QVector<int> updateInt = QVector<int>() << 1 << 2 << 5 << 10 << 15 << 30
|
---|
| 49 | << 60 << 120 << 240 << 300 << 600
|
---|
| 50 | << 900 << 1800 << 3600 << 7200
|
---|
| 51 | << 10800;
|
---|
[5749] | 52 | xc.ReSize(4);
|
---|
| 53 | vv.ReSize(3);
|
---|
[6213] | 54 | if (position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data()) != success) {
|
---|
| 55 | return failure;
|
---|
| 56 | }
|
---|
[5789] | 57 | if (useCorr) {
|
---|
[5839] | 58 | if (_orbCorr && _clkCorr) {
|
---|
[5849] | 59 | double dtO = tt - _orbCorr->_time;
|
---|
[6556] | 60 | if (_orbCorr->_updateInt) {
|
---|
| 61 | dtO -= (0.5 * updateInt[_orbCorr->_updateInt]);
|
---|
| 62 | }
|
---|
[5839] | 63 | ColumnVector dx(3);
|
---|
[5849] | 64 | dx[0] = _orbCorr->_xr[0] + _orbCorr->_dotXr[0] * dtO;
|
---|
| 65 | dx[1] = _orbCorr->_xr[1] + _orbCorr->_dotXr[1] * dtO;
|
---|
| 66 | dx[2] = _orbCorr->_xr[2] + _orbCorr->_dotXr[2] * dtO;
|
---|
| 67 |
|
---|
[5839] | 68 | if (_orbCorr->_system == 'R') {
|
---|
[5849] | 69 | RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), dx, dx);
|
---|
[5839] | 70 | }
|
---|
[5849] | 71 |
|
---|
[5839] | 72 | xc[0] -= dx[0];
|
---|
| 73 | xc[1] -= dx[1];
|
---|
| 74 | xc[2] -= dx[2];
|
---|
[5849] | 75 |
|
---|
| 76 | double dtC = tt - _clkCorr->_time;
|
---|
[6556] | 77 | if (_clkCorr->_updateInt) {
|
---|
| 78 | dtC -= (0.5 * updateInt[_clkCorr->_updateInt]);
|
---|
| 79 | }
|
---|
[5849] | 80 | xc[3] += _clkCorr->_dClk + _clkCorr->_dotDClk * dtC + _clkCorr->_dotDotDClk * dtC * dtC;
|
---|
[5839] | 81 | }
|
---|
| 82 | else {
|
---|
| 83 | return failure;
|
---|
| 84 | }
|
---|
[5749] | 85 | }
|
---|
| 86 | return success;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[6801] | 89 | //
|
---|
| 90 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 91 | QString t_eph::rinexDateStr(const bncTime& tt, const t_prn& prn, double version) {
|
---|
| 92 | QString prnStr(prn.toString().c_str());
|
---|
| 93 | return rinexDateStr(tt, prnStr, version);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | //
|
---|
| 97 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 98 | QString t_eph::rinexDateStr(const bncTime& tt, const QString& prnStr, double version) {
|
---|
| 99 |
|
---|
| 100 | QString datStr;
|
---|
| 101 |
|
---|
| 102 | unsigned year, month, day, hour, min;
|
---|
| 103 | double sec;
|
---|
| 104 | tt.civil_date(year, month, day);
|
---|
| 105 | tt.civil_time(hour, min, sec);
|
---|
| 106 |
|
---|
| 107 | QTextStream out(&datStr);
|
---|
| 108 |
|
---|
| 109 | if (version < 3.0) {
|
---|
| 110 | QString prnHlp = prnStr.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
|
---|
| 111 | out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
|
---|
| 112 | .arg(year % 100, 2, 10, QChar('0'))
|
---|
| 113 | .arg(month, 2)
|
---|
| 114 | .arg(day, 2)
|
---|
| 115 | .arg(hour, 2)
|
---|
| 116 | .arg(min, 2)
|
---|
| 117 | .arg(sec, 5, 'f',1);
|
---|
| 118 | }
|
---|
| 119 | else {
|
---|
| 120 | out << prnStr << QString(" %1 %2 %3 %4 %5 %6")
|
---|
| 121 | .arg(year, 4)
|
---|
| 122 | .arg(month, 2, 10, QChar('0'))
|
---|
| 123 | .arg(day, 2, 10, QChar('0'))
|
---|
| 124 | .arg(hour, 2, 10, QChar('0'))
|
---|
| 125 | .arg(min, 2, 10, QChar('0'))
|
---|
| 126 | .arg(int(sec), 2, 10, QChar('0'));
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | return datStr;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | // Constructor
|
---|
| 133 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 134 | t_ephGPS::t_ephGPS(float rnxVersion, const QStringList& lines) {
|
---|
| 135 |
|
---|
| 136 | const int nLines = 8;
|
---|
| 137 |
|
---|
| 138 | if (lines.size() != nLines) {
|
---|
| 139 | _checkState = bad;
|
---|
| 140 | return;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | // RINEX Format
|
---|
| 144 | // ------------
|
---|
| 145 | int fieldLen = 19;
|
---|
| 146 |
|
---|
| 147 | int pos[4];
|
---|
| 148 | pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
|
---|
| 149 | pos[1] = pos[0] + fieldLen;
|
---|
| 150 | pos[2] = pos[1] + fieldLen;
|
---|
| 151 | pos[3] = pos[2] + fieldLen;
|
---|
| 152 |
|
---|
| 153 | // Read eight lines
|
---|
| 154 | // ----------------
|
---|
| 155 | for (int iLine = 0; iLine < nLines; iLine++) {
|
---|
| 156 | QString line = lines[iLine];
|
---|
| 157 |
|
---|
| 158 | if ( iLine == 0 ) {
|
---|
| 159 | QTextStream in(line.left(pos[1]).toAscii());
|
---|
| 160 |
|
---|
| 161 | int year, month, day, hour, min;
|
---|
| 162 | double sec;
|
---|
| 163 |
|
---|
| 164 | QString prnStr;
|
---|
| 165 | in >> prnStr >> year >> month >> day >> hour >> min >> sec;
|
---|
| 166 | if (prnStr.at(0) == 'G') {
|
---|
| 167 | _prn.set('G', prnStr.mid(1).toInt());
|
---|
| 168 | }
|
---|
| 169 | else if (prnStr.at(0) == 'J') {
|
---|
| 170 | _prn.set('J', prnStr.mid(1).toInt());
|
---|
| 171 | }
|
---|
| 172 | else {
|
---|
| 173 | _prn.set('G', prnStr.toInt());
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | if (year < 80) {
|
---|
| 177 | year += 2000;
|
---|
| 178 | }
|
---|
| 179 | else if (year < 100) {
|
---|
| 180 | year += 1900;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | _TOC.set(year, month, day, hour, min, sec);
|
---|
| 184 |
|
---|
| 185 | if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
|
---|
| 186 | readDbl(line, pos[2], fieldLen, _clock_drift ) ||
|
---|
| 187 | readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
|
---|
| 188 | _checkState = bad;
|
---|
| 189 | return;
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | else if ( iLine == 1 ) {
|
---|
| 194 | if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
|
---|
| 195 | readDbl(line, pos[1], fieldLen, _Crs ) ||
|
---|
| 196 | readDbl(line, pos[2], fieldLen, _Delta_n) ||
|
---|
| 197 | readDbl(line, pos[3], fieldLen, _M0 ) ) {
|
---|
| 198 | _checkState = bad;
|
---|
| 199 | return;
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | else if ( iLine == 2 ) {
|
---|
| 204 | if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
|
---|
| 205 | readDbl(line, pos[1], fieldLen, _e ) ||
|
---|
| 206 | readDbl(line, pos[2], fieldLen, _Cus ) ||
|
---|
| 207 | readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
|
---|
| 208 | _checkState = bad;
|
---|
| 209 | return;
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | else if ( iLine == 3 ) {
|
---|
| 214 | if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
|
---|
| 215 | readDbl(line, pos[1], fieldLen, _Cic ) ||
|
---|
| 216 | readDbl(line, pos[2], fieldLen, _OMEGA0) ||
|
---|
| 217 | readDbl(line, pos[3], fieldLen, _Cis ) ) {
|
---|
| 218 | _checkState = bad;
|
---|
| 219 | return;
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | else if ( iLine == 4 ) {
|
---|
| 224 | if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
|
---|
| 225 | readDbl(line, pos[1], fieldLen, _Crc ) ||
|
---|
| 226 | readDbl(line, pos[2], fieldLen, _omega ) ||
|
---|
| 227 | readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
|
---|
| 228 | _checkState = bad;
|
---|
| 229 | return;
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | else if ( iLine == 5 ) {
|
---|
| 234 | if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
|
---|
| 235 | readDbl(line, pos[1], fieldLen, _L2Codes) ||
|
---|
| 236 | readDbl(line, pos[2], fieldLen, _TOEweek ) ||
|
---|
| 237 | readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
|
---|
| 238 | _checkState = bad;
|
---|
| 239 | return;
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | else if ( iLine == 6 ) {
|
---|
| 244 | if ( readDbl(line, pos[0], fieldLen, _ura ) ||
|
---|
| 245 | readDbl(line, pos[1], fieldLen, _health) ||
|
---|
| 246 | readDbl(line, pos[2], fieldLen, _TGD ) ||
|
---|
| 247 | readDbl(line, pos[3], fieldLen, _IODC ) ) {
|
---|
| 248 | _checkState = bad;
|
---|
| 249 | return;
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | else if ( iLine == 7 ) {
|
---|
| 254 | if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
|
---|
| 255 | _checkState = bad;
|
---|
| 256 | return;
|
---|
| 257 | }
|
---|
| 258 | readDbl(line, pos[1], fieldLen, _fitInterval); // _fitInterval optional
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[2222] | 263 | // Compute GPS Satellite Position (virtual)
|
---|
[1025] | 264 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6213] | 265 | t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
|
---|
[1025] | 266 |
|
---|
[6518] | 267 | if (_checkState == bad) {
|
---|
| 268 | return failure;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
[1098] | 271 | static const double omegaEarth = 7292115.1467e-11;
|
---|
[5277] | 272 | static const double gmGRS = 398.6005e12;
|
---|
[1025] | 273 |
|
---|
| 274 | memset(xc, 0, 4*sizeof(double));
|
---|
| 275 | memset(vv, 0, 3*sizeof(double));
|
---|
| 276 |
|
---|
| 277 | double a0 = _sqrt_A * _sqrt_A;
|
---|
| 278 | if (a0 == 0) {
|
---|
[6213] | 279 | return failure;
|
---|
[1025] | 280 | }
|
---|
| 281 |
|
---|
[5277] | 282 | double n0 = sqrt(gmGRS/(a0*a0*a0));
|
---|
[4018] | 283 |
|
---|
| 284 | bncTime tt(GPSweek, GPSweeks);
|
---|
[4543] | 285 | double tk = tt - bncTime(int(_TOEweek), _TOEsec);
|
---|
[4018] | 286 |
|
---|
[1025] | 287 | double n = n0 + _Delta_n;
|
---|
| 288 | double M = _M0 + n*tk;
|
---|
| 289 | double E = M;
|
---|
| 290 | double E_last;
|
---|
| 291 | do {
|
---|
| 292 | E_last = E;
|
---|
| 293 | E = M + _e*sin(E);
|
---|
| 294 | } while ( fabs(E-E_last)*a0 > 0.001 );
|
---|
| 295 | double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
|
---|
| 296 | double u0 = v + _omega;
|
---|
| 297 | double sin2u0 = sin(2*u0);
|
---|
| 298 | double cos2u0 = cos(2*u0);
|
---|
| 299 | double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
|
---|
| 300 | double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
|
---|
| 301 | double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
|
---|
| 302 | double xp = r*cos(u);
|
---|
| 303 | double yp = r*sin(u);
|
---|
| 304 | double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
|
---|
[4018] | 305 | omegaEarth*_TOEsec;
|
---|
[1025] | 306 |
|
---|
| 307 | double sinom = sin(OM);
|
---|
| 308 | double cosom = cos(OM);
|
---|
| 309 | double sini = sin(i);
|
---|
| 310 | double cosi = cos(i);
|
---|
| 311 | xc[0] = xp*cosom - yp*cosi*sinom;
|
---|
| 312 | xc[1] = xp*sinom + yp*cosi*cosom;
|
---|
| 313 | xc[2] = yp*sini;
|
---|
| 314 |
|
---|
[4018] | 315 | double tc = tt - _TOC;
|
---|
[2429] | 316 | xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
|
---|
[1025] | 317 |
|
---|
| 318 | // Velocity
|
---|
| 319 | // --------
|
---|
| 320 | double tanv2 = tan(v/2);
|
---|
| 321 | double dEdM = 1 / (1 - _e*cos(E));
|
---|
| 322 | double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
|
---|
| 323 | * dEdM * n;
|
---|
| 324 | double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
|
---|
| 325 | double dotom = _OMEGADOT - omegaEarth;
|
---|
| 326 | double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
|
---|
| 327 | double dotr = a0 * _e*sin(E) * dEdM * n
|
---|
| 328 | + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
|
---|
| 329 | double dotx = dotr*cos(u) - r*sin(u)*dotu;
|
---|
| 330 | double doty = dotr*sin(u) + r*cos(u)*dotu;
|
---|
| 331 |
|
---|
| 332 | vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
|
---|
| 333 | - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
|
---|
| 334 | + yp*sini*sinom*doti; // dX / di
|
---|
| 335 |
|
---|
| 336 | vv[1] = sinom *dotx + cosi*cosom *doty
|
---|
| 337 | + xp*cosom*dotom - yp*cosi*sinom*dotom
|
---|
| 338 | - yp*sini*cosom*doti;
|
---|
| 339 |
|
---|
| 340 | vv[2] = sini *doty + yp*cosi *doti;
|
---|
[2429] | 341 |
|
---|
| 342 | // Relativistic Correction
|
---|
| 343 | // -----------------------
|
---|
| 344 | xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
|
---|
[6213] | 345 |
|
---|
| 346 | return success;
|
---|
[1025] | 347 | }
|
---|
| 348 |
|
---|
[6801] | 349 | // RINEX Format String
|
---|
| 350 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 351 | QString t_ephGPS::toString(double version) const {
|
---|
[2221] | 352 |
|
---|
[6801] | 353 | QString rnxStr = rinexDateStr(_TOC, _prn, version);
|
---|
[2221] | 354 |
|
---|
[6801] | 355 | QTextStream out(&rnxStr);
|
---|
[2221] | 356 |
|
---|
[6801] | 357 | out << QString("%1%2%3\n")
|
---|
| 358 | .arg(_clock_bias, 19, 'e', 12)
|
---|
| 359 | .arg(_clock_drift, 19, 'e', 12)
|
---|
| 360 | .arg(_clock_driftrate, 19, 'e', 12);
|
---|
[2221] | 361 |
|
---|
[6801] | 362 | QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
|
---|
[2221] | 363 |
|
---|
[6801] | 364 | out << QString(fmt)
|
---|
| 365 | .arg(_IODE, 19, 'e', 12)
|
---|
| 366 | .arg(_Crs, 19, 'e', 12)
|
---|
| 367 | .arg(_Delta_n, 19, 'e', 12)
|
---|
| 368 | .arg(_M0, 19, 'e', 12);
|
---|
| 369 |
|
---|
| 370 | out << QString(fmt)
|
---|
| 371 | .arg(_Cuc, 19, 'e', 12)
|
---|
| 372 | .arg(_e, 19, 'e', 12)
|
---|
| 373 | .arg(_Cus, 19, 'e', 12)
|
---|
| 374 | .arg(_sqrt_A, 19, 'e', 12);
|
---|
| 375 |
|
---|
| 376 | out << QString(fmt)
|
---|
| 377 | .arg(_TOEsec, 19, 'e', 12)
|
---|
| 378 | .arg(_Cic, 19, 'e', 12)
|
---|
| 379 | .arg(_OMEGA0, 19, 'e', 12)
|
---|
| 380 | .arg(_Cis, 19, 'e', 12);
|
---|
| 381 |
|
---|
| 382 | out << QString(fmt)
|
---|
| 383 | .arg(_i0, 19, 'e', 12)
|
---|
| 384 | .arg(_Crc, 19, 'e', 12)
|
---|
| 385 | .arg(_omega, 19, 'e', 12)
|
---|
| 386 | .arg(_OMEGADOT, 19, 'e', 12);
|
---|
| 387 |
|
---|
| 388 | out << QString(fmt)
|
---|
| 389 | .arg(_IDOT, 19, 'e', 12)
|
---|
| 390 | .arg(_L2Codes, 19, 'e', 12)
|
---|
| 391 | .arg(_TOEweek, 19, 'e', 12)
|
---|
| 392 | .arg(_L2PFlag, 19, 'e', 12);
|
---|
| 393 |
|
---|
| 394 | out << QString(fmt)
|
---|
| 395 | .arg(_ura, 19, 'e', 12)
|
---|
| 396 | .arg(_health, 19, 'e', 12)
|
---|
| 397 | .arg(_TGD, 19, 'e', 12)
|
---|
| 398 | .arg(_IODC, 19, 'e', 12);
|
---|
| 399 |
|
---|
| 400 | out << QString(fmt)
|
---|
| 401 | .arg(_TOT, 19, 'e', 12)
|
---|
| 402 | .arg(_fitInterval, 19, 'e', 12)
|
---|
| 403 | .arg("", 19, QChar(' '))
|
---|
| 404 | .arg("", 19, QChar(' '));
|
---|
| 405 |
|
---|
| 406 | return rnxStr;
|
---|
[2221] | 407 | }
|
---|
| 408 |
|
---|
[6801] | 409 | // Constructor
|
---|
| 410 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 411 | t_ephGlo::t_ephGlo(float rnxVersion, const QStringList& lines) {
|
---|
[2221] | 412 |
|
---|
[6801] | 413 | const int nLines = 4;
|
---|
| 414 |
|
---|
| 415 | if (lines.size() != nLines) {
|
---|
| 416 | _checkState = bad;
|
---|
| 417 | return;
|
---|
[6518] | 418 | }
|
---|
| 419 |
|
---|
[6801] | 420 | // RINEX Format
|
---|
| 421 | // ------------
|
---|
| 422 | int fieldLen = 19;
|
---|
[2221] | 423 |
|
---|
[6801] | 424 | int pos[4];
|
---|
| 425 | pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
|
---|
| 426 | pos[1] = pos[0] + fieldLen;
|
---|
| 427 | pos[2] = pos[1] + fieldLen;
|
---|
| 428 | pos[3] = pos[2] + fieldLen;
|
---|
[2221] | 429 |
|
---|
[6801] | 430 | // Read four lines
|
---|
| 431 | // ---------------
|
---|
| 432 | for (int iLine = 0; iLine < nLines; iLine++) {
|
---|
| 433 | QString line = lines[iLine];
|
---|
[2221] | 434 |
|
---|
[6801] | 435 | if ( iLine == 0 ) {
|
---|
| 436 | QTextStream in(line.left(pos[1]).toAscii());
|
---|
[6213] | 437 |
|
---|
[6801] | 438 | int year, month, day, hour, min;
|
---|
| 439 | double sec;
|
---|
[2221] | 440 |
|
---|
[6801] | 441 | QString prnStr;
|
---|
| 442 | in >> prnStr >> year >> month >> day >> hour >> min >> sec;
|
---|
| 443 | if (prnStr.at(0) == 'R') {
|
---|
| 444 | _prn.set('R', prnStr.mid(1).toInt());
|
---|
| 445 | }
|
---|
| 446 | else {
|
---|
| 447 | _prn.set('R', prnStr.toInt());
|
---|
| 448 | }
|
---|
[2221] | 449 |
|
---|
[6801] | 450 | if (year < 80) {
|
---|
| 451 | year += 2000;
|
---|
| 452 | }
|
---|
| 453 | else if (year < 100) {
|
---|
| 454 | year += 1900;
|
---|
| 455 | }
|
---|
[2221] | 456 |
|
---|
[6801] | 457 | _gps_utc = gnumleap(year, month, day);
|
---|
[2221] | 458 |
|
---|
[6801] | 459 | _TOC.set(year, month, day, hour, min, sec);
|
---|
| 460 | _TOC = _TOC + _gps_utc;
|
---|
[6213] | 461 |
|
---|
[6801] | 462 | if ( readDbl(line, pos[1], fieldLen, _tau ) ||
|
---|
| 463 | readDbl(line, pos[2], fieldLen, _gamma) ||
|
---|
| 464 | readDbl(line, pos[3], fieldLen, _tki ) ) {
|
---|
| 465 | _checkState = bad;
|
---|
| 466 | return;
|
---|
| 467 | }
|
---|
[2221] | 468 |
|
---|
[6801] | 469 | _tau = -_tau;
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | else if ( iLine == 1 ) {
|
---|
| 473 | if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
|
---|
| 474 | readDbl(line, pos[1], fieldLen, _x_velocity ) ||
|
---|
| 475 | readDbl(line, pos[2], fieldLen, _x_acceleration) ||
|
---|
| 476 | readDbl(line, pos[3], fieldLen, _health ) ) {
|
---|
| 477 | _checkState = bad;
|
---|
| 478 | return;
|
---|
| 479 | }
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | else if ( iLine == 2 ) {
|
---|
| 483 | if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
|
---|
| 484 | readDbl(line, pos[1], fieldLen, _y_velocity ) ||
|
---|
| 485 | readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
|
---|
| 486 | readDbl(line, pos[3], fieldLen, _frequency_number) ) {
|
---|
| 487 | _checkState = bad;
|
---|
| 488 | return;
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | else if ( iLine == 3 ) {
|
---|
| 493 | if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
|
---|
| 494 | readDbl(line, pos[1], fieldLen, _z_velocity ) ||
|
---|
| 495 | readDbl(line, pos[2], fieldLen, _z_acceleration) ||
|
---|
| 496 | readDbl(line, pos[3], fieldLen, _E ) ) {
|
---|
| 497 | _checkState = bad;
|
---|
| 498 | return;
|
---|
| 499 | }
|
---|
| 500 | }
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | // Initialize status vector
|
---|
| 504 | // ------------------------
|
---|
| 505 | _tt = _TOC;
|
---|
| 506 | _xv.ReSize(6);
|
---|
| 507 | _xv(1) = _x_pos * 1.e3;
|
---|
| 508 | _xv(2) = _y_pos * 1.e3;
|
---|
| 509 | _xv(3) = _z_pos * 1.e3;
|
---|
| 510 | _xv(4) = _x_velocity * 1.e3;
|
---|
| 511 | _xv(5) = _y_velocity * 1.e3;
|
---|
| 512 | _xv(6) = _z_velocity * 1.e3;
|
---|
[2221] | 513 | }
|
---|
| 514 |
|
---|
[6801] | 515 | // Compute Glonass Satellite Position (virtual)
|
---|
[2771] | 516 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6801] | 517 | t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
|
---|
[2771] | 518 |
|
---|
[6518] | 519 | if (_checkState == bad) {
|
---|
| 520 | return failure;
|
---|
| 521 | }
|
---|
| 522 |
|
---|
[6801] | 523 | static const double nominalStep = 10.0;
|
---|
[2771] | 524 |
|
---|
| 525 | memset(xc, 0, 4*sizeof(double));
|
---|
| 526 | memset(vv, 0, 3*sizeof(double));
|
---|
| 527 |
|
---|
[6801] | 528 | double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
|
---|
| 529 |
|
---|
| 530 | if (fabs(dtPos) > 24*3600.0) {
|
---|
[6213] | 531 | return failure;
|
---|
[2771] | 532 | }
|
---|
| 533 |
|
---|
[6801] | 534 | int nSteps = int(fabs(dtPos) / nominalStep) + 1;
|
---|
| 535 | double step = dtPos / nSteps;
|
---|
[4018] | 536 |
|
---|
[6801] | 537 | double acc[3];
|
---|
| 538 | acc[0] = _x_acceleration * 1.e3;
|
---|
| 539 | acc[1] = _y_acceleration * 1.e3;
|
---|
| 540 | acc[2] = _z_acceleration * 1.e3;
|
---|
| 541 | for (int ii = 1; ii <= nSteps; ii++) {
|
---|
| 542 | _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
|
---|
| 543 | _tt = _tt + step;
|
---|
| 544 | }
|
---|
[4018] | 545 |
|
---|
[6801] | 546 | // Position and Velocity
|
---|
| 547 | // ---------------------
|
---|
| 548 | xc[0] = _xv(1);
|
---|
| 549 | xc[1] = _xv(2);
|
---|
| 550 | xc[2] = _xv(3);
|
---|
[2771] | 551 |
|
---|
[6801] | 552 | vv[0] = _xv(4);
|
---|
| 553 | vv[1] = _xv(5);
|
---|
| 554 | vv[2] = _xv(6);
|
---|
[2771] | 555 |
|
---|
[6801] | 556 | // Clock Correction
|
---|
| 557 | // ----------------
|
---|
| 558 | double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
|
---|
| 559 | xc[3] = -_tau + _gamma * dtClk;
|
---|
[2771] | 560 |
|
---|
[6213] | 561 | return success;
|
---|
[2771] | 562 | }
|
---|
| 563 |
|
---|
[6801] | 564 | // RINEX Format String
|
---|
[3659] | 565 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6801] | 566 | QString t_ephGlo::toString(double version) const {
|
---|
[3664] | 567 |
|
---|
[6801] | 568 | QString rnxStr = rinexDateStr(_TOC-_gps_utc, _prn, version);
|
---|
[3699] | 569 |
|
---|
[6801] | 570 | QTextStream out(&rnxStr);
|
---|
[3664] | 571 |
|
---|
[6801] | 572 | out << QString("%1%2%3\n")
|
---|
| 573 | .arg(-_tau, 19, 'e', 12)
|
---|
| 574 | .arg(_gamma, 19, 'e', 12)
|
---|
| 575 | .arg(_tki, 19, 'e', 12);
|
---|
[3668] | 576 |
|
---|
[6801] | 577 | QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
|
---|
[3664] | 578 |
|
---|
[6801] | 579 | out << QString(fmt)
|
---|
| 580 | .arg(_x_pos, 19, 'e', 12)
|
---|
| 581 | .arg(_x_velocity, 19, 'e', 12)
|
---|
| 582 | .arg(_x_acceleration, 19, 'e', 12)
|
---|
| 583 | .arg(_health, 19, 'e', 12);
|
---|
[3664] | 584 |
|
---|
[6801] | 585 | out << QString(fmt)
|
---|
| 586 | .arg(_y_pos, 19, 'e', 12)
|
---|
| 587 | .arg(_y_velocity, 19, 'e', 12)
|
---|
| 588 | .arg(_y_acceleration, 19, 'e', 12)
|
---|
| 589 | .arg(_frequency_number, 19, 'e', 12);
|
---|
[3666] | 590 |
|
---|
[6801] | 591 | out << QString(fmt)
|
---|
| 592 | .arg(_z_pos, 19, 'e', 12)
|
---|
| 593 | .arg(_z_velocity, 19, 'e', 12)
|
---|
| 594 | .arg(_z_acceleration, 19, 'e', 12)
|
---|
| 595 | .arg(_E, 19, 'e', 12);
|
---|
[3666] | 596 |
|
---|
[6801] | 597 | return rnxStr;
|
---|
[3659] | 598 | }
|
---|
| 599 |
|
---|
[6801] | 600 | // Derivative of the state vector using a simple force model (static)
|
---|
| 601 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 602 | ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
|
---|
| 603 | double* acc) {
|
---|
[3659] | 604 |
|
---|
[6801] | 605 | // State vector components
|
---|
| 606 | // -----------------------
|
---|
| 607 | ColumnVector rr = xv.rows(1,3);
|
---|
| 608 | ColumnVector vv = xv.rows(4,6);
|
---|
[3699] | 609 |
|
---|
[6801] | 610 | // Acceleration
|
---|
[3699] | 611 | // ------------
|
---|
[6801] | 612 | static const double gmWGS = 398.60044e12;
|
---|
| 613 | static const double AE = 6378136.0;
|
---|
| 614 | static const double OMEGA = 7292115.e-11;
|
---|
| 615 | static const double C20 = -1082.6257e-6;
|
---|
[3699] | 616 |
|
---|
[6801] | 617 | double rho = rr.norm_Frobenius();
|
---|
| 618 | double t1 = -gmWGS/(rho*rho*rho);
|
---|
| 619 | double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
|
---|
| 620 | double t3 = OMEGA * OMEGA;
|
---|
| 621 | double t4 = 2.0 * OMEGA;
|
---|
| 622 | double z2 = rr(3) * rr(3);
|
---|
[3699] | 623 |
|
---|
[6801] | 624 | // Vector of derivatives
|
---|
| 625 | // ---------------------
|
---|
| 626 | ColumnVector va(6);
|
---|
| 627 | va(1) = vv(1);
|
---|
| 628 | va(2) = vv(2);
|
---|
| 629 | va(3) = vv(3);
|
---|
| 630 | va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
|
---|
| 631 | va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
|
---|
| 632 | va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
|
---|
[3699] | 633 |
|
---|
[6801] | 634 | return va;
|
---|
| 635 | }
|
---|
[3699] | 636 |
|
---|
[6801] | 637 | // IOD of Glonass Ephemeris (virtual)
|
---|
| 638 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 639 | int t_ephGlo::IOD() const {
|
---|
| 640 | bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
|
---|
| 641 | return int(tMoscow.daysec() / 900);
|
---|
[3659] | 642 | }
|
---|
| 643 |
|
---|
| 644 | // Constructor
|
---|
| 645 | //////////////////////////////////////////////////////////////////////////////
|
---|
[4891] | 646 | t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
|
---|
[6809] | 647 | int year, month, day, hour, min;
|
---|
| 648 | double sec;
|
---|
| 649 | QString prnStr;
|
---|
[4891] | 650 | const int nLines = 8;
|
---|
| 651 | if (lines.size() != nLines) {
|
---|
[6518] | 652 | _checkState = bad;
|
---|
[4891] | 653 | return;
|
---|
| 654 | }
|
---|
| 655 |
|
---|
| 656 | // RINEX Format
|
---|
| 657 | // ------------
|
---|
| 658 | int fieldLen = 19;
|
---|
[6792] | 659 | double SVhealth = 0.0;
|
---|
| 660 | double datasource = 0.0;
|
---|
[6798] | 661 |
|
---|
[4891] | 662 | int pos[4];
|
---|
| 663 | pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
|
---|
| 664 | pos[1] = pos[0] + fieldLen;
|
---|
| 665 | pos[2] = pos[1] + fieldLen;
|
---|
| 666 | pos[3] = pos[2] + fieldLen;
|
---|
| 667 |
|
---|
| 668 | // Read eight lines
|
---|
| 669 | // ----------------
|
---|
| 670 | for (int iLine = 0; iLine < nLines; iLine++) {
|
---|
| 671 | QString line = lines[iLine];
|
---|
| 672 |
|
---|
| 673 | if ( iLine == 0 ) {
|
---|
| 674 | QTextStream in(line.left(pos[1]).toAscii());
|
---|
| 675 |
|
---|
[5776] | 676 | in >> prnStr >> year >> month >> day >> hour >> min >> sec;
|
---|
[4891] | 677 | if (year < 80) {
|
---|
| 678 | year += 2000;
|
---|
| 679 | }
|
---|
| 680 | else if (year < 100) {
|
---|
| 681 | year += 1900;
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | _TOC.set(year, month, day, hour, min, sec);
|
---|
| 685 |
|
---|
| 686 | if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
|
---|
| 687 | readDbl(line, pos[2], fieldLen, _clock_drift ) ||
|
---|
| 688 | readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
|
---|
[6518] | 689 | _checkState = bad;
|
---|
[4891] | 690 | return;
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | else if ( iLine == 1 ) {
|
---|
| 695 | if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
|
---|
| 696 | readDbl(line, pos[1], fieldLen, _Crs ) ||
|
---|
| 697 | readDbl(line, pos[2], fieldLen, _Delta_n) ||
|
---|
| 698 | readDbl(line, pos[3], fieldLen, _M0 ) ) {
|
---|
[6518] | 699 | _checkState = bad;
|
---|
[4891] | 700 | return;
|
---|
| 701 | }
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | else if ( iLine == 2 ) {
|
---|
| 705 | if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
|
---|
| 706 | readDbl(line, pos[1], fieldLen, _e ) ||
|
---|
| 707 | readDbl(line, pos[2], fieldLen, _Cus ) ||
|
---|
| 708 | readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
|
---|
[6518] | 709 | _checkState = bad;
|
---|
[4891] | 710 | return;
|
---|
| 711 | }
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | else if ( iLine == 3 ) {
|
---|
| 715 | if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
|
---|
| 716 | readDbl(line, pos[1], fieldLen, _Cic ) ||
|
---|
| 717 | readDbl(line, pos[2], fieldLen, _OMEGA0) ||
|
---|
| 718 | readDbl(line, pos[3], fieldLen, _Cis ) ) {
|
---|
[6518] | 719 | _checkState = bad;
|
---|
[4891] | 720 | return;
|
---|
| 721 | }
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | else if ( iLine == 4 ) {
|
---|
| 725 | if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
|
---|
| 726 | readDbl(line, pos[1], fieldLen, _Crc ) ||
|
---|
| 727 | readDbl(line, pos[2], fieldLen, _omega ) ||
|
---|
| 728 | readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
|
---|
[6518] | 729 | _checkState = bad;
|
---|
[4891] | 730 | return;
|
---|
| 731 | }
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | else if ( iLine == 5 ) {
|
---|
[6792] | 735 | if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
|
---|
| 736 | readDbl(line, pos[1], fieldLen, datasource) ||
|
---|
| 737 | readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
|
---|
[6518] | 738 | _checkState = bad;
|
---|
[4891] | 739 | return;
|
---|
[6792] | 740 | } else {
|
---|
| 741 | if (int(datasource) & (1<<8)) {
|
---|
[6812] | 742 | _fnav = true;
|
---|
| 743 | _inav = false;
|
---|
[6792] | 744 | } else if (int(datasource) & (1<<9)) {
|
---|
[6812] | 745 | _fnav = false;
|
---|
| 746 | _inav = true;
|
---|
[6792] | 747 | }
|
---|
[4891] | 748 | }
|
---|
| 749 | }
|
---|
| 750 |
|
---|
| 751 | else if ( iLine == 6 ) {
|
---|
| 752 | if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
|
---|
[6792] | 753 | readDbl(line, pos[1], fieldLen, SVhealth) ||
|
---|
[4891] | 754 | readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
|
---|
| 755 | readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
|
---|
[6518] | 756 | _checkState = bad;
|
---|
[4891] | 757 | return;
|
---|
[6792] | 758 | } else {
|
---|
| 759 | // Bit 0
|
---|
[6812] | 760 | _e1DataInValid = (int(SVhealth) & (1<<0));
|
---|
[6792] | 761 | // Bit 1-2
|
---|
[6802] | 762 | _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
|
---|
[6792] | 763 | // Bit 3
|
---|
[6812] | 764 | _e5aDataInValid = (int(SVhealth) & (1<<3));
|
---|
[6792] | 765 | // Bit 4-5
|
---|
[6802] | 766 | _E5aHS = double((int(SVhealth) >> 4) & 0x3);
|
---|
[6792] | 767 | // Bit 6
|
---|
[6812] | 768 | _e5bDataInValid = (int(SVhealth) & (1<<6));
|
---|
[6792] | 769 | // Bit 7-8
|
---|
[6802] | 770 | _E5bHS = double((int(SVhealth) >> 7) & 0x3);
|
---|
[6809] | 771 |
|
---|
| 772 | if (prnStr.at(0) == 'E') {
|
---|
[6812] | 773 | _prn.set('E', prnStr.mid(1,2).toInt(), _inav ? 1 : 0);
|
---|
[6809] | 774 | }
|
---|
[4891] | 775 | }
|
---|
| 776 | }
|
---|
| 777 |
|
---|
| 778 | else if ( iLine == 7 ) {
|
---|
| 779 | if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
|
---|
[6518] | 780 | _checkState = bad;
|
---|
[4891] | 781 | return;
|
---|
| 782 | }
|
---|
| 783 | }
|
---|
| 784 | }
|
---|
[3659] | 785 | }
|
---|
[4013] | 786 |
|
---|
[6801] | 787 | // Compute Galileo Satellite Position (virtual)
|
---|
| 788 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 789 | t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
|
---|
[4013] | 790 |
|
---|
[6801] | 791 | if (_checkState == bad) {
|
---|
| 792 | return failure;
|
---|
| 793 | }
|
---|
[4013] | 794 |
|
---|
[6801] | 795 | static const double omegaEarth = 7292115.1467e-11;
|
---|
| 796 | static const double gmWGS = 398.60044e12;
|
---|
[4023] | 797 |
|
---|
[6801] | 798 | memset(xc, 0, 4*sizeof(double));
|
---|
| 799 | memset(vv, 0, 3*sizeof(double));
|
---|
[4023] | 800 |
|
---|
[6801] | 801 | double a0 = _sqrt_A * _sqrt_A;
|
---|
| 802 | if (a0 == 0) {
|
---|
| 803 | return failure;
|
---|
| 804 | }
|
---|
[4023] | 805 |
|
---|
[6801] | 806 | double n0 = sqrt(gmWGS/(a0*a0*a0));
|
---|
[4023] | 807 |
|
---|
[6801] | 808 | bncTime tt(GPSweek, GPSweeks);
|
---|
| 809 | double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
|
---|
[4023] | 810 |
|
---|
[6801] | 811 | double n = n0 + _Delta_n;
|
---|
| 812 | double M = _M0 + n*tk;
|
---|
| 813 | double E = M;
|
---|
| 814 | double E_last;
|
---|
| 815 | do {
|
---|
| 816 | E_last = E;
|
---|
| 817 | E = M + _e*sin(E);
|
---|
| 818 | } while ( fabs(E-E_last)*a0 > 0.001 );
|
---|
| 819 | double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
|
---|
| 820 | double u0 = v + _omega;
|
---|
| 821 | double sin2u0 = sin(2*u0);
|
---|
| 822 | double cos2u0 = cos(2*u0);
|
---|
| 823 | double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
|
---|
| 824 | double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
|
---|
| 825 | double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
|
---|
| 826 | double xp = r*cos(u);
|
---|
| 827 | double yp = r*sin(u);
|
---|
| 828 | double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
|
---|
| 829 | omegaEarth*_TOEsec;
|
---|
[4023] | 830 |
|
---|
[6801] | 831 | double sinom = sin(OM);
|
---|
| 832 | double cosom = cos(OM);
|
---|
| 833 | double sini = sin(i);
|
---|
| 834 | double cosi = cos(i);
|
---|
| 835 | xc[0] = xp*cosom - yp*cosi*sinom;
|
---|
| 836 | xc[1] = xp*sinom + yp*cosi*cosom;
|
---|
| 837 | xc[2] = yp*sini;
|
---|
[4023] | 838 |
|
---|
[6801] | 839 | double tc = tt - _TOC;
|
---|
| 840 | xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
|
---|
[4023] | 841 |
|
---|
[6801] | 842 | // Velocity
|
---|
| 843 | // --------
|
---|
| 844 | double tanv2 = tan(v/2);
|
---|
| 845 | double dEdM = 1 / (1 - _e*cos(E));
|
---|
| 846 | double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
|
---|
| 847 | * dEdM * n;
|
---|
| 848 | double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
|
---|
| 849 | double dotom = _OMEGADOT - omegaEarth;
|
---|
| 850 | double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
|
---|
| 851 | double dotr = a0 * _e*sin(E) * dEdM * n
|
---|
| 852 | + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
|
---|
| 853 | double dotx = dotr*cos(u) - r*sin(u)*dotu;
|
---|
| 854 | double doty = dotr*sin(u) + r*cos(u)*dotu;
|
---|
[4023] | 855 |
|
---|
[6801] | 856 | vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
|
---|
| 857 | - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
|
---|
| 858 | + yp*sini*sinom*doti; // dX / di
|
---|
| 859 |
|
---|
| 860 | vv[1] = sinom *dotx + cosi*cosom *doty
|
---|
| 861 | + xp*cosom*dotom - yp*cosi*sinom*dotom
|
---|
| 862 | - yp*sini*cosom*doti;
|
---|
| 863 |
|
---|
| 864 | vv[2] = sini *doty + yp*cosi *doti;
|
---|
| 865 |
|
---|
| 866 | // Relativistic Correction
|
---|
| 867 | // -----------------------
|
---|
| 868 | // xc(4) -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
|
---|
| 869 | xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
|
---|
| 870 |
|
---|
| 871 | return success;
|
---|
[4023] | 872 | }
|
---|
| 873 |
|
---|
| 874 | // RINEX Format String
|
---|
| 875 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 876 | QString t_ephGal::toString(double version) const {
|
---|
| 877 |
|
---|
[4029] | 878 | QString rnxStr = rinexDateStr(_TOC, _prn, version);
|
---|
[4023] | 879 |
|
---|
| 880 | QTextStream out(&rnxStr);
|
---|
| 881 |
|
---|
| 882 | out << QString("%1%2%3\n")
|
---|
| 883 | .arg(_clock_bias, 19, 'e', 12)
|
---|
| 884 | .arg(_clock_drift, 19, 'e', 12)
|
---|
| 885 | .arg(_clock_driftrate, 19, 'e', 12);
|
---|
| 886 |
|
---|
| 887 | QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
|
---|
| 888 |
|
---|
| 889 | out << QString(fmt)
|
---|
| 890 | .arg(_IODnav, 19, 'e', 12)
|
---|
| 891 | .arg(_Crs, 19, 'e', 12)
|
---|
| 892 | .arg(_Delta_n, 19, 'e', 12)
|
---|
| 893 | .arg(_M0, 19, 'e', 12);
|
---|
| 894 |
|
---|
| 895 | out << QString(fmt)
|
---|
| 896 | .arg(_Cuc, 19, 'e', 12)
|
---|
| 897 | .arg(_e, 19, 'e', 12)
|
---|
| 898 | .arg(_Cus, 19, 'e', 12)
|
---|
| 899 | .arg(_sqrt_A, 19, 'e', 12);
|
---|
| 900 |
|
---|
| 901 | out << QString(fmt)
|
---|
| 902 | .arg(_TOEsec, 19, 'e', 12)
|
---|
| 903 | .arg(_Cic, 19, 'e', 12)
|
---|
| 904 | .arg(_OMEGA0, 19, 'e', 12)
|
---|
| 905 | .arg(_Cis, 19, 'e', 12);
|
---|
| 906 |
|
---|
| 907 | out << QString(fmt)
|
---|
| 908 | .arg(_i0, 19, 'e', 12)
|
---|
| 909 | .arg(_Crc, 19, 'e', 12)
|
---|
| 910 | .arg(_omega, 19, 'e', 12)
|
---|
| 911 | .arg(_OMEGADOT, 19, 'e', 12);
|
---|
| 912 |
|
---|
[6792] | 913 | int dataSource = 0;
|
---|
| 914 | int SVhealth = 0;
|
---|
| 915 | double BGD_1_5A = _BGD_1_5A;
|
---|
| 916 | double BGD_1_5B = _BGD_1_5B;
|
---|
[6812] | 917 | if (_fnav) {
|
---|
[6792] | 918 | dataSource |= (1<<1);
|
---|
| 919 | dataSource |= (1<<8);
|
---|
| 920 | BGD_1_5B = 0.0;
|
---|
| 921 | // SVhealth
|
---|
| 922 | // Bit 3 : E5a DVS
|
---|
[6812] | 923 | if (_e5aDataInValid) {
|
---|
[6792] | 924 | SVhealth |= (1<<3);
|
---|
| 925 | }
|
---|
| 926 | // Bit 4-5: E5a HS
|
---|
| 927 | if (_E5aHS == 1.0) {
|
---|
| 928 | SVhealth |= (1<<4);
|
---|
| 929 | }
|
---|
| 930 | else if (_E5aHS == 2.0) {
|
---|
| 931 | SVhealth |= (1<<5);
|
---|
| 932 | }
|
---|
| 933 | else if (_E5aHS == 3.0) {
|
---|
| 934 | SVhealth |= (1<<4);
|
---|
| 935 | SVhealth |= (1<<5);
|
---|
| 936 | }
|
---|
| 937 | }
|
---|
[6812] | 938 | else if(_inav) {
|
---|
[6803] | 939 | // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
|
---|
| 940 | // and RNXv3.03 says both can be set if the navigation messages were merged
|
---|
[5539] | 941 | dataSource |= (1<<0);
|
---|
[6792] | 942 | dataSource |= (1<<2);
|
---|
[5540] | 943 | dataSource |= (1<<9);
|
---|
[6792] | 944 | // SVhealth
|
---|
| 945 | // Bit 0 : E1-B DVS
|
---|
[6812] | 946 | if (_e1DataInValid) {
|
---|
[6792] | 947 | SVhealth |= (1<<0);
|
---|
| 948 | }
|
---|
| 949 | // Bit 1-2: E1-B HS
|
---|
| 950 | if (_E1_bHS == 1.0) {
|
---|
| 951 | SVhealth |= (1<<1);
|
---|
| 952 | }
|
---|
| 953 | else if (_E1_bHS == 2.0) {
|
---|
| 954 | SVhealth |= (1<<2);
|
---|
| 955 | }
|
---|
[6803] | 956 | else if (_E1_bHS == 3.0) {
|
---|
[6792] | 957 | SVhealth |= (1<<1);
|
---|
| 958 | SVhealth |= (1<<2);
|
---|
| 959 | }
|
---|
[6802] | 960 | // Bit 3 : E5a DVS
|
---|
[6812] | 961 | if (_e5aDataInValid) {
|
---|
[6802] | 962 | SVhealth |= (1<<3);
|
---|
| 963 | }
|
---|
| 964 | // Bit 4-5: E5a HS
|
---|
| 965 | if (_E5aHS == 1.0) {
|
---|
| 966 | SVhealth |= (1<<4);
|
---|
| 967 | }
|
---|
| 968 | else if (_E5aHS == 2.0) {
|
---|
| 969 | SVhealth |= (1<<5);
|
---|
| 970 | }
|
---|
[6803] | 971 | else if (_E5aHS == 3.0) {
|
---|
[6802] | 972 | SVhealth |= (1<<4);
|
---|
| 973 | SVhealth |= (1<<5);
|
---|
| 974 | }
|
---|
[6792] | 975 | // Bit 6 : E5b DVS
|
---|
[6812] | 976 | if (_e5bDataInValid) {
|
---|
[6792] | 977 | SVhealth |= (1<<6);
|
---|
| 978 | }
|
---|
| 979 | // Bit 7-8: E5b HS
|
---|
| 980 | if (_E5bHS == 1.0) {
|
---|
| 981 | SVhealth |= (1<<7);
|
---|
| 982 | }
|
---|
| 983 | else if (_E5bHS == 2.0) {
|
---|
| 984 | SVhealth |= (1<<8);
|
---|
| 985 | }
|
---|
[6803] | 986 | else if (_E5bHS == 3.0) {
|
---|
[6792] | 987 | SVhealth |= (1<<7);
|
---|
| 988 | SVhealth |= (1<<8);
|
---|
| 989 | }
|
---|
[5539] | 990 | }
|
---|
[6792] | 991 |
|
---|
[4023] | 992 | out << QString(fmt)
|
---|
[5532] | 993 | .arg(_IDOT, 19, 'e', 12)
|
---|
| 994 | .arg(double(dataSource), 19, 'e', 12)
|
---|
| 995 | .arg(_TOEweek, 19, 'e', 12)
|
---|
| 996 | .arg(0.0, 19, 'e', 12);
|
---|
[4023] | 997 |
|
---|
| 998 | out << QString(fmt)
|
---|
[6798] | 999 | .arg(_SISA, 19, 'e', 12)
|
---|
[6792] | 1000 | .arg(double(SVhealth), 19, 'e', 12)
|
---|
| 1001 | .arg(BGD_1_5A, 19, 'e', 12)
|
---|
| 1002 | .arg(BGD_1_5B, 19, 'e', 12);
|
---|
[4023] | 1003 |
|
---|
| 1004 | out << QString(fmt)
|
---|
| 1005 | .arg(_TOT, 19, 'e', 12)
|
---|
[4024] | 1006 | .arg("", 19, QChar(' '))
|
---|
| 1007 | .arg("", 19, QChar(' '))
|
---|
| 1008 | .arg("", 19, QChar(' '));
|
---|
[4023] | 1009 |
|
---|
| 1010 | return rnxStr;
|
---|
| 1011 | }
|
---|
| 1012 |
|
---|
[6385] | 1013 | // Constructor
|
---|
| 1014 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6390] | 1015 | t_ephSBAS::t_ephSBAS(float rnxVersion, const QStringList& lines) {
|
---|
| 1016 |
|
---|
| 1017 | const int nLines = 4;
|
---|
| 1018 |
|
---|
| 1019 | if (lines.size() != nLines) {
|
---|
[6518] | 1020 | _checkState = bad;
|
---|
[6390] | 1021 | return;
|
---|
| 1022 | }
|
---|
| 1023 |
|
---|
| 1024 | // RINEX Format
|
---|
| 1025 | // ------------
|
---|
| 1026 | int fieldLen = 19;
|
---|
| 1027 |
|
---|
| 1028 | int pos[4];
|
---|
| 1029 | pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
|
---|
| 1030 | pos[1] = pos[0] + fieldLen;
|
---|
| 1031 | pos[2] = pos[1] + fieldLen;
|
---|
| 1032 | pos[3] = pos[2] + fieldLen;
|
---|
| 1033 |
|
---|
| 1034 | // Read four lines
|
---|
| 1035 | // ---------------
|
---|
| 1036 | for (int iLine = 0; iLine < nLines; iLine++) {
|
---|
| 1037 | QString line = lines[iLine];
|
---|
| 1038 |
|
---|
| 1039 | if ( iLine == 0 ) {
|
---|
| 1040 | QTextStream in(line.left(pos[1]).toAscii());
|
---|
| 1041 |
|
---|
| 1042 | int year, month, day, hour, min;
|
---|
| 1043 | double sec;
|
---|
| 1044 |
|
---|
| 1045 | QString prnStr;
|
---|
| 1046 | in >> prnStr >> year >> month >> day >> hour >> min >> sec;
|
---|
| 1047 | if (prnStr.at(0) == 'S') {
|
---|
| 1048 | _prn.set('S', prnStr.mid(1).toInt());
|
---|
| 1049 | }
|
---|
| 1050 | else {
|
---|
| 1051 | _prn.set('S', prnStr.toInt());
|
---|
| 1052 | }
|
---|
| 1053 |
|
---|
| 1054 | if (year < 80) {
|
---|
| 1055 | year += 2000;
|
---|
| 1056 | }
|
---|
| 1057 | else if (year < 100) {
|
---|
| 1058 | year += 1900;
|
---|
| 1059 | }
|
---|
| 1060 |
|
---|
| 1061 | _TOC.set(year, month, day, hour, min, sec);
|
---|
| 1062 |
|
---|
| 1063 | if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
|
---|
| 1064 | readDbl(line, pos[2], fieldLen, _agf1 ) ||
|
---|
| 1065 | readDbl(line, pos[3], fieldLen, _TOW ) ) {
|
---|
[6518] | 1066 | _checkState = bad;
|
---|
[6390] | 1067 | return;
|
---|
| 1068 | }
|
---|
| 1069 | }
|
---|
| 1070 |
|
---|
| 1071 | else if ( iLine == 1 ) {
|
---|
| 1072 | if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
|
---|
| 1073 | readDbl(line, pos[1], fieldLen, _x_velocity ) ||
|
---|
| 1074 | readDbl(line, pos[2], fieldLen, _x_acceleration) ||
|
---|
| 1075 | readDbl(line, pos[3], fieldLen, _health ) ) {
|
---|
[6518] | 1076 | _checkState = bad;
|
---|
[6390] | 1077 | return;
|
---|
| 1078 | }
|
---|
| 1079 | }
|
---|
| 1080 |
|
---|
| 1081 | else if ( iLine == 2 ) {
|
---|
| 1082 | if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
|
---|
| 1083 | readDbl(line, pos[1], fieldLen, _y_velocity ) ||
|
---|
| 1084 | readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
|
---|
| 1085 | readDbl(line, pos[3], fieldLen, _ura ) ) {
|
---|
[6518] | 1086 | _checkState = bad;
|
---|
[6390] | 1087 | return;
|
---|
| 1088 | }
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
| 1091 | else if ( iLine == 3 ) {
|
---|
[6536] | 1092 | double iodn;
|
---|
[6390] | 1093 | if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
|
---|
| 1094 | readDbl(line, pos[1], fieldLen, _z_velocity ) ||
|
---|
| 1095 | readDbl(line, pos[2], fieldLen, _z_acceleration) ||
|
---|
[6536] | 1096 | readDbl(line, pos[3], fieldLen, iodn ) ) {
|
---|
[6518] | 1097 | _checkState = bad;
|
---|
[6390] | 1098 | return;
|
---|
[6536] | 1099 | _IODN = int(iodn);
|
---|
[6390] | 1100 | }
|
---|
| 1101 | }
|
---|
| 1102 | }
|
---|
| 1103 |
|
---|
| 1104 | _x_pos *= 1.e3;
|
---|
| 1105 | _y_pos *= 1.e3;
|
---|
| 1106 | _z_pos *= 1.e3;
|
---|
| 1107 | _x_velocity *= 1.e3;
|
---|
| 1108 | _y_velocity *= 1.e3;
|
---|
| 1109 | _z_velocity *= 1.e3;
|
---|
| 1110 | _x_acceleration *= 1.e3;
|
---|
| 1111 | _y_acceleration *= 1.e3;
|
---|
| 1112 | _z_acceleration *= 1.e3;
|
---|
[6385] | 1113 | }
|
---|
| 1114 |
|
---|
| 1115 | // Compute SBAS Satellite Position (virtual)
|
---|
| 1116 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1117 | t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
|
---|
[6386] | 1118 |
|
---|
[6518] | 1119 | if (_checkState == bad) {
|
---|
| 1120 | return failure;
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
[6386] | 1123 | bncTime tt(GPSweek, GPSweeks);
|
---|
| 1124 | double dt = tt - _TOC;
|
---|
| 1125 |
|
---|
| 1126 | xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
|
---|
| 1127 | xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
|
---|
| 1128 | xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
|
---|
| 1129 |
|
---|
| 1130 | vv[0] = _x_velocity + _x_acceleration * dt;
|
---|
| 1131 | vv[1] = _y_velocity + _y_acceleration * dt;
|
---|
| 1132 | vv[2] = _z_velocity + _z_acceleration * dt;
|
---|
| 1133 |
|
---|
| 1134 | xc[3] = _agf0 + _agf1 * dt;
|
---|
| 1135 |
|
---|
| 1136 | return success;
|
---|
[6385] | 1137 | }
|
---|
| 1138 |
|
---|
| 1139 | // RINEX Format String
|
---|
| 1140 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6388] | 1141 | QString t_ephSBAS::toString(double version) const {
|
---|
| 1142 |
|
---|
| 1143 | QString rnxStr = rinexDateStr(_TOC, _prn, version);
|
---|
| 1144 |
|
---|
| 1145 | QTextStream out(&rnxStr);
|
---|
| 1146 |
|
---|
| 1147 | out << QString("%1%2%3\n")
|
---|
[6390] | 1148 | .arg(_agf0, 19, 'e', 12)
|
---|
| 1149 | .arg(_agf1, 19, 'e', 12)
|
---|
| 1150 | .arg(_TOW, 19, 'e', 12);
|
---|
[6388] | 1151 |
|
---|
| 1152 | QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
|
---|
| 1153 |
|
---|
| 1154 | out << QString(fmt)
|
---|
| 1155 | .arg(1.e-3*_x_pos, 19, 'e', 12)
|
---|
| 1156 | .arg(1.e-3*_x_velocity, 19, 'e', 12)
|
---|
| 1157 | .arg(1.e-3*_x_acceleration, 19, 'e', 12)
|
---|
[6390] | 1158 | .arg(_health, 19, 'e', 12);
|
---|
[6388] | 1159 |
|
---|
| 1160 | out << QString(fmt)
|
---|
| 1161 | .arg(1.e-3*_y_pos, 19, 'e', 12)
|
---|
| 1162 | .arg(1.e-3*_y_velocity, 19, 'e', 12)
|
---|
| 1163 | .arg(1.e-3*_y_acceleration, 19, 'e', 12)
|
---|
[6390] | 1164 | .arg(_ura, 19, 'e', 12);
|
---|
[6388] | 1165 |
|
---|
| 1166 | out << QString(fmt)
|
---|
| 1167 | .arg(1.e-3*_z_pos, 19, 'e', 12)
|
---|
| 1168 | .arg(1.e-3*_z_velocity, 19, 'e', 12)
|
---|
| 1169 | .arg(1.e-3*_z_acceleration, 19, 'e', 12)
|
---|
[6536] | 1170 | .arg(double(_IODN), 19, 'e', 12);
|
---|
[6388] | 1171 |
|
---|
| 1172 | return rnxStr;
|
---|
[6385] | 1173 | }
|
---|
[6400] | 1174 |
|
---|
| 1175 | // Constructor
|
---|
| 1176 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6600] | 1177 | t_ephBDS::t_ephBDS(float rnxVersion, const QStringList& lines) {
|
---|
[6400] | 1178 |
|
---|
| 1179 | const int nLines = 8;
|
---|
| 1180 |
|
---|
| 1181 | if (lines.size() != nLines) {
|
---|
[6518] | 1182 | _checkState = bad;
|
---|
[6400] | 1183 | return;
|
---|
| 1184 | }
|
---|
| 1185 |
|
---|
| 1186 | // RINEX Format
|
---|
| 1187 | // ------------
|
---|
| 1188 | int fieldLen = 19;
|
---|
| 1189 |
|
---|
| 1190 | int pos[4];
|
---|
| 1191 | pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
|
---|
| 1192 | pos[1] = pos[0] + fieldLen;
|
---|
| 1193 | pos[2] = pos[1] + fieldLen;
|
---|
| 1194 | pos[3] = pos[2] + fieldLen;
|
---|
| 1195 |
|
---|
| 1196 | // Read eight lines
|
---|
| 1197 | // ----------------
|
---|
| 1198 | for (int iLine = 0; iLine < nLines; iLine++) {
|
---|
| 1199 | QString line = lines[iLine];
|
---|
| 1200 |
|
---|
| 1201 | if ( iLine == 0 ) {
|
---|
| 1202 | QTextStream in(line.left(pos[1]).toAscii());
|
---|
| 1203 |
|
---|
| 1204 | int year, month, day, hour, min;
|
---|
| 1205 | double sec;
|
---|
| 1206 |
|
---|
| 1207 | QString prnStr;
|
---|
| 1208 | in >> prnStr >> year >> month >> day >> hour >> min >> sec;
|
---|
| 1209 | if (prnStr.at(0) == 'C') {
|
---|
| 1210 | _prn.set('C', prnStr.mid(1).toInt());
|
---|
| 1211 | }
|
---|
| 1212 | else {
|
---|
| 1213 | _prn.set('C', prnStr.toInt());
|
---|
| 1214 | }
|
---|
| 1215 |
|
---|
| 1216 | if (year < 80) {
|
---|
| 1217 | year += 2000;
|
---|
| 1218 | }
|
---|
| 1219 | else if (year < 100) {
|
---|
| 1220 | year += 1900;
|
---|
| 1221 | }
|
---|
| 1222 |
|
---|
[6812] | 1223 | _TOC.setBDS(year, month, day, hour, min, sec);
|
---|
[6400] | 1224 |
|
---|
| 1225 | if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
|
---|
| 1226 | readDbl(line, pos[2], fieldLen, _clock_drift ) ||
|
---|
| 1227 | readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
|
---|
[6518] | 1228 | _checkState = bad;
|
---|
[6400] | 1229 | return;
|
---|
| 1230 | }
|
---|
| 1231 | }
|
---|
| 1232 |
|
---|
| 1233 | else if ( iLine == 1 ) {
|
---|
| 1234 | double aode;
|
---|
| 1235 | if ( readDbl(line, pos[0], fieldLen, aode ) ||
|
---|
| 1236 | readDbl(line, pos[1], fieldLen, _Crs ) ||
|
---|
| 1237 | readDbl(line, pos[2], fieldLen, _Delta_n) ||
|
---|
| 1238 | readDbl(line, pos[3], fieldLen, _M0 ) ) {
|
---|
[6518] | 1239 | _checkState = bad;
|
---|
[6400] | 1240 | return;
|
---|
| 1241 | }
|
---|
| 1242 | _AODE = int(aode);
|
---|
| 1243 | }
|
---|
| 1244 |
|
---|
| 1245 | else if ( iLine == 2 ) {
|
---|
| 1246 | if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
|
---|
| 1247 | readDbl(line, pos[1], fieldLen, _e ) ||
|
---|
| 1248 | readDbl(line, pos[2], fieldLen, _Cus ) ||
|
---|
| 1249 | readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
|
---|
[6518] | 1250 | _checkState = bad;
|
---|
[6400] | 1251 | return;
|
---|
| 1252 | }
|
---|
| 1253 | }
|
---|
| 1254 |
|
---|
| 1255 | else if ( iLine == 3 ) {
|
---|
[6812] | 1256 | if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
|
---|
[6400] | 1257 | readDbl(line, pos[1], fieldLen, _Cic ) ||
|
---|
| 1258 | readDbl(line, pos[2], fieldLen, _OMEGA0) ||
|
---|
| 1259 | readDbl(line, pos[3], fieldLen, _Cis ) ) {
|
---|
[6518] | 1260 | _checkState = bad;
|
---|
[6400] | 1261 | return;
|
---|
| 1262 | }
|
---|
| 1263 | }
|
---|
| 1264 |
|
---|
| 1265 | else if ( iLine == 4 ) {
|
---|
| 1266 | if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
|
---|
| 1267 | readDbl(line, pos[1], fieldLen, _Crc ) ||
|
---|
| 1268 | readDbl(line, pos[2], fieldLen, _omega ) ||
|
---|
| 1269 | readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
|
---|
[6518] | 1270 | _checkState = bad;
|
---|
[6400] | 1271 | return;
|
---|
| 1272 | }
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
| 1275 | else if ( iLine == 5 ) {
|
---|
| 1276 | if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
|
---|
[6812] | 1277 | readDbl(line, pos[2], fieldLen, _TOEweek)) {
|
---|
[6518] | 1278 | _checkState = bad;
|
---|
[6400] | 1279 | return;
|
---|
| 1280 | }
|
---|
| 1281 | }
|
---|
| 1282 |
|
---|
| 1283 | else if ( iLine == 6 ) {
|
---|
| 1284 | double SatH1;
|
---|
[6755] | 1285 | if ( readDbl(line, pos[0], fieldLen, _URA ) ||
|
---|
| 1286 | readDbl(line, pos[1], fieldLen, SatH1) ||
|
---|
[6400] | 1287 | readDbl(line, pos[2], fieldLen, _TGD1) ||
|
---|
| 1288 | readDbl(line, pos[3], fieldLen, _TGD2) ) {
|
---|
[6518] | 1289 | _checkState = bad;
|
---|
[6400] | 1290 | return;
|
---|
| 1291 | }
|
---|
| 1292 | _SatH1 = int(SatH1);
|
---|
| 1293 | }
|
---|
| 1294 |
|
---|
| 1295 | else if ( iLine == 7 ) {
|
---|
| 1296 | double aodc;
|
---|
[6812] | 1297 | if ( readDbl(line, pos[0], fieldLen, _TOT) ||
|
---|
[6400] | 1298 | readDbl(line, pos[1], fieldLen, aodc) ) {
|
---|
[6518] | 1299 | _checkState = bad;
|
---|
[6400] | 1300 | return;
|
---|
| 1301 | }
|
---|
[6812] | 1302 | if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
|
---|
| 1303 | _TOT = _TOEsec;
|
---|
[6400] | 1304 | }
|
---|
| 1305 | _AODC = int(aodc);
|
---|
| 1306 | }
|
---|
| 1307 | }
|
---|
| 1308 |
|
---|
| 1309 | // remark: actually should be computed from second_tot
|
---|
| 1310 | // but it seems to be unreliable in RINEX files
|
---|
[6812] | 1311 | _TOT = _TOC.bdssec();
|
---|
[6400] | 1312 | }
|
---|
| 1313 |
|
---|
[6601] | 1314 | // Compute BDS Satellite Position (virtual)
|
---|
[6400] | 1315 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6600] | 1316 | t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
|
---|
[6400] | 1317 |
|
---|
[6518] | 1318 | if (_checkState == bad) {
|
---|
| 1319 | return failure;
|
---|
| 1320 | }
|
---|
| 1321 |
|
---|
[6602] | 1322 | static const double gmBDS = 398.6004418e12;
|
---|
| 1323 | static const double omegaBDS = 7292115.0000e-11;
|
---|
[6400] | 1324 |
|
---|
| 1325 | xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
|
---|
| 1326 | vv[0] = vv[1] = vv[2] = 0.0;
|
---|
| 1327 |
|
---|
| 1328 | bncTime tt(GPSweek, GPSweeks);
|
---|
| 1329 |
|
---|
| 1330 | if (_sqrt_A == 0) {
|
---|
| 1331 | return failure;
|
---|
| 1332 | }
|
---|
| 1333 | double a0 = _sqrt_A * _sqrt_A;
|
---|
| 1334 |
|
---|
[6602] | 1335 | double n0 = sqrt(gmBDS/(a0*a0*a0));
|
---|
[6400] | 1336 | double tk = tt - _TOE;
|
---|
| 1337 | double n = n0 + _Delta_n;
|
---|
| 1338 | double M = _M0 + n*tk;
|
---|
| 1339 | double E = M;
|
---|
| 1340 | double E_last;
|
---|
| 1341 | int nLoop = 0;
|
---|
| 1342 | do {
|
---|
| 1343 | E_last = E;
|
---|
| 1344 | E = M + _e*sin(E);
|
---|
| 1345 |
|
---|
| 1346 | if (++nLoop == 100) {
|
---|
| 1347 | return failure;
|
---|
| 1348 | }
|
---|
| 1349 | } while ( fabs(E-E_last)*a0 > 0.001 );
|
---|
| 1350 |
|
---|
| 1351 | double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
|
---|
| 1352 | double u0 = v + _omega;
|
---|
| 1353 | double sin2u0 = sin(2*u0);
|
---|
| 1354 | double cos2u0 = cos(2*u0);
|
---|
| 1355 | double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
|
---|
| 1356 | double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
|
---|
| 1357 | double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
|
---|
| 1358 | double xp = r*cos(u);
|
---|
| 1359 | double yp = r*sin(u);
|
---|
| 1360 | double toesec = (_TOE.gpssec() - 14.0);
|
---|
| 1361 |
|
---|
| 1362 | double sinom = 0;
|
---|
| 1363 | double cosom = 0;
|
---|
| 1364 | double sini = 0;
|
---|
| 1365 | double cosi = 0;
|
---|
| 1366 |
|
---|
| 1367 | const double iMaxGEO = 10.0 / 180.0 * M_PI;
|
---|
| 1368 |
|
---|
| 1369 | // MEO/IGSO satellite
|
---|
| 1370 | // ------------------
|
---|
| 1371 | if (_i0 > iMaxGEO) {
|
---|
[6602] | 1372 | double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
|
---|
[6400] | 1373 |
|
---|
| 1374 | sinom = sin(OM);
|
---|
| 1375 | cosom = cos(OM);
|
---|
| 1376 | sini = sin(i);
|
---|
| 1377 | cosi = cos(i);
|
---|
| 1378 |
|
---|
| 1379 | xc[0] = xp*cosom - yp*cosi*sinom;
|
---|
| 1380 | xc[1] = xp*sinom + yp*cosi*cosom;
|
---|
| 1381 | xc[2] = yp*sini;
|
---|
| 1382 | }
|
---|
| 1383 |
|
---|
| 1384 | // GEO satellite
|
---|
| 1385 | // -------------
|
---|
| 1386 | else {
|
---|
[6602] | 1387 | double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
|
---|
| 1388 | double ll = omegaBDS*tk;
|
---|
[6400] | 1389 |
|
---|
| 1390 | sinom = sin(OM);
|
---|
| 1391 | cosom = cos(OM);
|
---|
| 1392 | sini = sin(i);
|
---|
| 1393 | cosi = cos(i);
|
---|
| 1394 |
|
---|
| 1395 | double xx = xp*cosom - yp*cosi*sinom;
|
---|
| 1396 | double yy = xp*sinom + yp*cosi*cosom;
|
---|
| 1397 | double zz = yp*sini;
|
---|
| 1398 |
|
---|
| 1399 | Matrix R1 = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
|
---|
| 1400 | Matrix R2 = BNC_PPP::t_astro::rotZ(ll);
|
---|
| 1401 |
|
---|
| 1402 | ColumnVector X1(3); X1 << xx << yy << zz;
|
---|
| 1403 | ColumnVector X2 = R2*R1*X1;
|
---|
| 1404 |
|
---|
| 1405 | xc[0] = X2(1);
|
---|
| 1406 | xc[1] = X2(2);
|
---|
| 1407 | xc[2] = X2(3);
|
---|
| 1408 | }
|
---|
| 1409 |
|
---|
| 1410 | double tc = tt - _TOC;
|
---|
| 1411 | xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc
|
---|
| 1412 | - 4.442807633e-10 * _e * sqrt(a0) *sin(E);
|
---|
| 1413 |
|
---|
| 1414 | // Velocity
|
---|
| 1415 | // --------
|
---|
| 1416 | double tanv2 = tan(v/2);
|
---|
| 1417 | double dEdM = 1 / (1 - _e*cos(E));
|
---|
| 1418 | double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
|
---|
| 1419 | / (1 + tanv2*tanv2) * dEdM * n;
|
---|
| 1420 | double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
|
---|
| 1421 | double dotom = _OMEGADOT - t_CST::omega;
|
---|
| 1422 | double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
|
---|
| 1423 | double dotr = a0 * _e*sin(E) * dEdM * n
|
---|
| 1424 | + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
|
---|
| 1425 | double dotx = dotr*cos(u) - r*sin(u)*dotu;
|
---|
| 1426 | double doty = dotr*sin(u) + r*cos(u)*dotu;
|
---|
| 1427 |
|
---|
| 1428 | vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
|
---|
| 1429 | - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
|
---|
| 1430 | + yp*sini*sinom*doti; // dX / di
|
---|
| 1431 |
|
---|
| 1432 | vv[1] = sinom *dotx + cosi*cosom *doty
|
---|
| 1433 | + xp*cosom*dotom - yp*cosi*sinom*dotom
|
---|
| 1434 | - yp*sini*cosom*doti;
|
---|
| 1435 |
|
---|
| 1436 | vv[2] = sini *doty + yp*cosi *doti;
|
---|
| 1437 |
|
---|
| 1438 | // dotC = _clock_drift + _clock_driftrate*tc
|
---|
| 1439 | // - 4.442807633e-10*_e*sqrt(a0)*cos(E) * dEdM * n;
|
---|
| 1440 |
|
---|
| 1441 | return success;
|
---|
| 1442 | }
|
---|
| 1443 |
|
---|
| 1444 | // RINEX Format String
|
---|
| 1445 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6600] | 1446 | QString t_ephBDS::toString(double version) const {
|
---|
[6400] | 1447 |
|
---|
[6812] | 1448 | QString rnxStr = rinexDateStr(_TOC-14.0, _prn, version);
|
---|
[6400] | 1449 |
|
---|
| 1450 | QTextStream out(&rnxStr);
|
---|
| 1451 |
|
---|
| 1452 | out << QString("%1%2%3\n")
|
---|
| 1453 | .arg(_clock_bias, 19, 'e', 12)
|
---|
| 1454 | .arg(_clock_drift, 19, 'e', 12)
|
---|
| 1455 | .arg(_clock_driftrate, 19, 'e', 12);
|
---|
| 1456 |
|
---|
| 1457 | QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
|
---|
| 1458 |
|
---|
| 1459 | out << QString(fmt)
|
---|
| 1460 | .arg(double(_AODE), 19, 'e', 12)
|
---|
| 1461 | .arg(_Crs, 19, 'e', 12)
|
---|
| 1462 | .arg(_Delta_n, 19, 'e', 12)
|
---|
| 1463 | .arg(_M0, 19, 'e', 12);
|
---|
| 1464 |
|
---|
| 1465 | out << QString(fmt)
|
---|
| 1466 | .arg(_Cuc, 19, 'e', 12)
|
---|
| 1467 | .arg(_e, 19, 'e', 12)
|
---|
| 1468 | .arg(_Cus, 19, 'e', 12)
|
---|
| 1469 | .arg(_sqrt_A, 19, 'e', 12);
|
---|
| 1470 |
|
---|
[6812] | 1471 | double toes = _TOEsec;
|
---|
[6755] | 1472 | if (!toes) { // RTCM stream input
|
---|
[6812] | 1473 | toes = _TOE.bdssec();
|
---|
[6755] | 1474 | }
|
---|
[6400] | 1475 | out << QString(fmt)
|
---|
[6755] | 1476 | .arg(toes, 19, 'e', 12)
|
---|
| 1477 | .arg(_Cic, 19, 'e', 12)
|
---|
| 1478 | .arg(_OMEGA0, 19, 'e', 12)
|
---|
| 1479 | .arg(_Cis, 19, 'e', 12);
|
---|
[6400] | 1480 |
|
---|
| 1481 | out << QString(fmt)
|
---|
| 1482 | .arg(_i0, 19, 'e', 12)
|
---|
| 1483 | .arg(_Crc, 19, 'e', 12)
|
---|
| 1484 | .arg(_omega, 19, 'e', 12)
|
---|
| 1485 | .arg(_OMEGADOT, 19, 'e', 12);
|
---|
| 1486 |
|
---|
| 1487 | out << QString(fmt)
|
---|
[6756] | 1488 | .arg(_IDOT, 19, 'e', 12)
|
---|
| 1489 | .arg(0.0, 19, 'e', 12)
|
---|
[6812] | 1490 | .arg(double(_TOE.bdsw()), 19, 'e', 12)
|
---|
[6756] | 1491 | .arg(0.0, 19, 'e', 12);
|
---|
[6400] | 1492 |
|
---|
| 1493 | out << QString(fmt)
|
---|
[6798] | 1494 | .arg(_URA, 19, 'e', 12)
|
---|
[6400] | 1495 | .arg(double(_SatH1), 19, 'e', 12)
|
---|
| 1496 | .arg(_TGD1, 19, 'e', 12)
|
---|
| 1497 | .arg(_TGD2, 19, 'e', 12);
|
---|
| 1498 |
|
---|
[6812] | 1499 | double tots = _TOT;
|
---|
[6755] | 1500 | if (!tots) { // RTCM stream input
|
---|
[6812] | 1501 | tots = _TOE.bdssec();
|
---|
[6755] | 1502 | }
|
---|
[6400] | 1503 | out << QString(fmt)
|
---|
[6792] | 1504 | .arg(tots, 19, 'e', 12)
|
---|
[6755] | 1505 | .arg(double(_AODC), 19, 'e', 12)
|
---|
| 1506 | .arg("", 19, QChar(' '))
|
---|
| 1507 | .arg("", 19, QChar(' '));
|
---|
[6400] | 1508 | return rnxStr;
|
---|
| 1509 | }
|
---|