[2035] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncPPPclient
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Precise Point Positioning
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 21-Nov-2009
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[2249] | 41 | #include <newmatio.h>
|
---|
[2238] | 42 | #include <iomanip>
|
---|
[2549] | 43 | #include <sstream>
|
---|
[2238] | 44 |
|
---|
[2035] | 45 | #include "bncpppclient.h"
|
---|
[2113] | 46 | #include "bncapp.h"
|
---|
[2043] | 47 | #include "bncutils.h"
|
---|
[2044] | 48 | #include "bncconst.h"
|
---|
[2058] | 49 | #include "bncmodel.h"
|
---|
[2226] | 50 | #include "bncsettings.h"
|
---|
[2035] | 51 |
|
---|
| 52 | extern "C" {
|
---|
| 53 | #include "clock_orbit_rtcm.h"
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | using namespace std;
|
---|
| 57 |
|
---|
| 58 | // Constructor
|
---|
| 59 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 60 | bncPPPclient::bncPPPclient(QByteArray staID) {
|
---|
[2113] | 61 |
|
---|
[2226] | 62 | bncSettings settings;
|
---|
| 63 |
|
---|
| 64 | if ( Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
|
---|
| 65 | _useGlonass = true;
|
---|
| 66 | }
|
---|
| 67 | else {
|
---|
| 68 | _useGlonass = false;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[2357] | 71 | if (settings.value("pppSPP").toString() == "PPP") {
|
---|
| 72 | _pppMode = true;
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
| 75 | _pppMode = false;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[2548] | 78 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 79 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 80 |
|
---|
[2113] | 81 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
[2585] | 82 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
[2548] | 83 |
|
---|
[2224] | 84 | connect(((bncApp*)qApp), SIGNAL(newEphGlonass(glonassephemeris)),
|
---|
[2585] | 85 | this, SLOT(slotNewEphGlonass(glonassephemeris)));
|
---|
[2548] | 86 |
|
---|
[2113] | 87 | connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
|
---|
[2585] | 88 | this, SLOT(slotNewCorrections(QList<QString>)));
|
---|
[2113] | 89 |
|
---|
[2039] | 90 | _staID = staID;
|
---|
| 91 | _epoData = 0;
|
---|
[2113] | 92 | _model = new bncModel(staID);
|
---|
[2182] | 93 | connect(_model, SIGNAL(newNMEAstr(QByteArray)),
|
---|
| 94 | this, SIGNAL(newNMEAstr(QByteArray)));
|
---|
[2035] | 95 | }
|
---|
| 96 |
|
---|
| 97 | // Destructor
|
---|
| 98 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 99 | bncPPPclient::~bncPPPclient() {
|
---|
[2058] | 100 | delete _model;
|
---|
[2039] | 101 | delete _epoData;
|
---|
[2575] | 102 | QMapIterator<QString, t_ephPair*> it(_eph);
|
---|
[2035] | 103 | while (it.hasNext()) {
|
---|
| 104 | it.next();
|
---|
| 105 | delete it.value();
|
---|
| 106 | }
|
---|
| 107 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
| 108 | while (ic.hasNext()) {
|
---|
| 109 | ic.next();
|
---|
| 110 | delete ic.value();
|
---|
| 111 | }
|
---|
[2274] | 112 | QMapIterator<QString, t_bias*> ib(_bias);
|
---|
| 113 | while (ib.hasNext()) {
|
---|
| 114 | ib.next();
|
---|
| 115 | delete ib.value();
|
---|
| 116 | }
|
---|
[2035] | 117 | }
|
---|
| 118 |
|
---|
| 119 | //
|
---|
| 120 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 121 | void bncPPPclient::putNewObs(p_obs pp) {
|
---|
[2037] | 122 | QMutexLocker locker(&_mutex);
|
---|
[2051] | 123 |
|
---|
[2037] | 124 | t_obsInternal* obs = &(pp->_o);
|
---|
[2051] | 125 |
|
---|
[2226] | 126 | if (obs->satSys != 'G' && !_useGlonass) {
|
---|
[2225] | 127 | return;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[2051] | 130 | t_satData* satData = new t_satData();
|
---|
| 131 |
|
---|
[2274] | 132 | // Satellite Number
|
---|
| 133 | // ----------------
|
---|
| 134 | if (obs->satSys == 'G') {
|
---|
| 135 | QString prn = QString("G%1").arg(obs->satNum, 2, 10, QChar('0'));
|
---|
| 136 | satData->prn = prn;
|
---|
| 137 | }
|
---|
| 138 | else if (obs->satSys == 'R') {
|
---|
| 139 | QString prn = QString("R%1").arg(obs->satNum, 2, 10, QChar('0'));
|
---|
| 140 | satData->prn = prn;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[2505] | 143 | // Check Slips
|
---|
| 144 | // -----------
|
---|
| 145 | slipInfo& sInfo = _slips[satData->prn];
|
---|
| 146 | if ( sInfo.slipCntL1 == obs->slip_cnt_L1 &&
|
---|
| 147 | sInfo.slipCntL2 == obs->slip_cnt_L2 ) {
|
---|
| 148 | satData->slipFlag = false;
|
---|
| 149 | }
|
---|
| 150 | else {
|
---|
| 151 | satData->slipFlag = true;
|
---|
| 152 | }
|
---|
| 153 | sInfo.slipCntL1 = obs->slip_cnt_L1;
|
---|
| 154 | sInfo.slipCntL2 = obs->slip_cnt_L2;
|
---|
| 155 |
|
---|
[2274] | 156 | // Handle Code Biases
|
---|
| 157 | // ------------------
|
---|
| 158 | t_bias* bb = 0;
|
---|
| 159 | if (_bias.contains(satData->prn)) {
|
---|
| 160 | bb = _bias.value(satData->prn);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[2051] | 163 | // Set Code Observations
|
---|
| 164 | // ---------------------
|
---|
| 165 | if (obs->P1) {
|
---|
[2426] | 166 | satData->P1 = obs->P1 + (bb ? bb->p1 : 0.0);
|
---|
[2051] | 167 | satData->codeTypeF1 = t_satData::P_CODE;
|
---|
| 168 | }
|
---|
| 169 | else if (obs->C1) {
|
---|
[2426] | 170 | satData->P1 = obs->C1 + (bb ? bb->c1 : 0.0);
|
---|
[2051] | 171 | satData->codeTypeF1 = t_satData::C_CODE;
|
---|
| 172 | }
|
---|
| 173 | else {
|
---|
| 174 | delete satData;
|
---|
| 175 | return;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | if (obs->P2) {
|
---|
[2426] | 179 | satData->P2 = obs->P2 + (bb ? bb->p2 : 0.0);
|
---|
[2051] | 180 | satData->codeTypeF2 = t_satData::P_CODE;
|
---|
| 181 | }
|
---|
| 182 | else if (obs->C2) {
|
---|
[2317] | 183 | satData->P2 = obs->C2;
|
---|
[2051] | 184 | satData->codeTypeF2 = t_satData::C_CODE;
|
---|
| 185 | }
|
---|
| 186 | else {
|
---|
| 187 | delete satData;
|
---|
| 188 | return;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[2228] | 191 | double f1 = t_CST::freq1;
|
---|
| 192 | double f2 = t_CST::freq2;
|
---|
| 193 |
|
---|
[2229] | 194 | if (obs->satSys == 'R') {
|
---|
| 195 | f1 = 1602000000.0 + 562500.0 * obs->slot;
|
---|
| 196 | f2 = 1246000000.0 + 437500.0 * obs->slot;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[2228] | 199 | // Ionosphere-Free Combination
|
---|
| 200 | // ---------------------------
|
---|
| 201 | double c1 = f1 * f1 / (f1 * f1 - f2 * f2);
|
---|
| 202 | double c2 = - f2 * f2 / (f1 * f1 - f2 * f2);
|
---|
| 203 |
|
---|
[2051] | 204 | satData->P3 = c1 * satData->P1 + c2 * satData->P2;
|
---|
| 205 |
|
---|
| 206 | // Set Phase Observations
|
---|
| 207 | // ----------------------
|
---|
| 208 | if (obs->L1 && obs->L2) {
|
---|
[2228] | 209 | satData->L1 = obs->L1 * t_CST::c / f1;
|
---|
| 210 | satData->L2 = obs->L2 * t_CST::c / f2;
|
---|
[2051] | 211 | }
|
---|
| 212 | else {
|
---|
| 213 | delete satData;
|
---|
| 214 | return;
|
---|
| 215 | }
|
---|
| 216 | satData->L3 = c1 * satData->L1 + c2 * satData->L2;
|
---|
| 217 |
|
---|
[2583] | 218 | // Set Ionosphere-Free Wavelength
|
---|
| 219 | // ------------------------------
|
---|
| 220 | satData->lambda3 = c1 * t_CST::c / f1 + c2 * t_CST::c / f2;
|
---|
| 221 |
|
---|
[2051] | 222 | // Add new Satellite to the epoch
|
---|
| 223 | // ------------------------------
|
---|
[2123] | 224 | bncTime tt(obs->GPSWeek, obs->GPSWeeks);
|
---|
[2037] | 225 |
|
---|
[2039] | 226 | if (!_epoData) {
|
---|
| 227 | _epoData = new t_epoData();
|
---|
| 228 | _epoData->tt = tt;
|
---|
[2037] | 229 | }
|
---|
[2039] | 230 | else if (tt != _epoData->tt) {
|
---|
[2037] | 231 | processEpoch();
|
---|
[2039] | 232 | delete _epoData;
|
---|
| 233 | _epoData = new t_epoData();
|
---|
| 234 | _epoData->tt = tt;
|
---|
[2037] | 235 | }
|
---|
[2039] | 236 |
|
---|
[2231] | 237 | if (obs->satSys == 'G') {
|
---|
[2274] | 238 | _epoData->satDataGPS[satData->prn] = satData;
|
---|
[2231] | 239 | }
|
---|
| 240 | else if (obs->satSys == 'R') {
|
---|
[2274] | 241 | _epoData->satDataGlo[satData->prn] = satData;
|
---|
[2231] | 242 | }
|
---|
[2035] | 243 | }
|
---|
| 244 |
|
---|
| 245 | //
|
---|
| 246 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 247 | void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
| 248 | QMutexLocker locker(&_mutex);
|
---|
| 249 |
|
---|
| 250 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
---|
| 251 |
|
---|
| 252 | if (_eph.contains(prn)) {
|
---|
[2637] | 253 | //// t_ephGPS* eLast = static_cast<t_ephGPS*>(_eph.value(prn)->last);
|
---|
| 254 | //// if ( (eLast->GPSweek() < gpseph.GPSweek) ||
|
---|
| 255 | //// (eLast->GPSweek() == gpseph.GPSweek &&
|
---|
| 256 | //// eLast->TOC() < gpseph.TOC) ) {
|
---|
| 257 | if (true) { // simply take the last one
|
---|
[2576] | 258 | delete static_cast<t_ephGPS*>(_eph.value(prn)->prev);
|
---|
| 259 | _eph.value(prn)->prev = _eph.value(prn)->last;
|
---|
| 260 | _eph.value(prn)->last = new t_ephGPS();
|
---|
| 261 | static_cast<t_ephGPS*>(_eph.value(prn)->last)->set(&gpseph);
|
---|
[2040] | 262 | }
|
---|
[2035] | 263 | }
|
---|
| 264 | else {
|
---|
[2575] | 265 | t_ephGPS* eLast = new t_ephGPS();
|
---|
| 266 | eLast->set(&gpseph);
|
---|
| 267 | _eph.insert(prn, new t_ephPair());
|
---|
| 268 | _eph[prn]->last = eLast;
|
---|
[2035] | 269 | }
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | //
|
---|
| 273 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2224] | 274 | void bncPPPclient::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
| 275 | QMutexLocker locker(&_mutex);
|
---|
| 276 |
|
---|
| 277 | QString prn = QString("R%1").arg(gloeph.almanac_number, 2, 10, QChar('0'));
|
---|
| 278 |
|
---|
| 279 | if (_eph.contains(prn)) {
|
---|
[2268] | 280 | int ww = gloeph.GPSWeek;
|
---|
| 281 | int tow = gloeph.GPSTOW;
|
---|
| 282 | updatetime(&ww, &tow, gloeph.tb*1000, 0); // Moscow -> GPS
|
---|
[2637] | 283 | //// t_ephGlo* eLast = static_cast<t_ephGlo*>(_eph.value(prn)->last);
|
---|
| 284 | //// if (eLast->GPSweek() < ww ||
|
---|
| 285 | //// (eLast->GPSweek() == ww && eLast->GPSweeks() < tow)) {
|
---|
| 286 | if (true) { // simply take the last one
|
---|
[2576] | 287 | delete static_cast<t_ephGlo*>(_eph.value(prn)->prev);
|
---|
| 288 | _eph.value(prn)->prev = _eph.value(prn)->last;
|
---|
| 289 | _eph.value(prn)->last = new t_ephGlo();
|
---|
| 290 | static_cast<t_ephGlo*>(_eph.value(prn)->last)->set(&gloeph);
|
---|
[2224] | 291 | }
|
---|
| 292 | }
|
---|
| 293 | else {
|
---|
[2575] | 294 | t_ephGlo* eLast = new t_ephGlo();
|
---|
| 295 | eLast->set(&gloeph);
|
---|
| 296 | _eph.insert(prn, new t_ephPair());
|
---|
| 297 | _eph[prn]->last = eLast;
|
---|
[2224] | 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | //
|
---|
| 302 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2035] | 303 | void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
|
---|
| 304 | QMutexLocker locker(&_mutex);
|
---|
[2069] | 305 |
|
---|
| 306 | if (corrList.size() == 0) {
|
---|
| 307 | return;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | // Remove All Corrections
|
---|
| 311 | // ----------------------
|
---|
| 312 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
| 313 | while (ic.hasNext()) {
|
---|
| 314 | ic.next();
|
---|
| 315 | delete ic.value();
|
---|
| 316 | }
|
---|
| 317 | _corr.clear();
|
---|
| 318 |
|
---|
[2035] | 319 | QListIterator<QString> it(corrList);
|
---|
| 320 | while (it.hasNext()) {
|
---|
| 321 | QTextStream in(it.next().toAscii());
|
---|
| 322 | int messageType;
|
---|
| 323 | int updateInterval;
|
---|
| 324 | int GPSweek;
|
---|
| 325 | double GPSweeks;
|
---|
| 326 | QString prn;
|
---|
| 327 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
| 328 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
[2207] | 329 | messageType == COTYPE_GLONASSCOMBINED ||
|
---|
| 330 | messageType == COTYPE_GPSORBIT ||
|
---|
| 331 | messageType == COTYPE_GPSCLOCK ||
|
---|
| 332 | messageType == COTYPE_GLONASSORBIT ||
|
---|
| 333 | messageType == COTYPE_GLONASSCLOCK ) {
|
---|
| 334 |
|
---|
[2035] | 335 | t_corr* cc = 0;
|
---|
| 336 | if (_corr.contains(prn)) {
|
---|
| 337 | cc = _corr.value(prn);
|
---|
| 338 | }
|
---|
| 339 | else {
|
---|
| 340 | cc = new t_corr();
|
---|
| 341 | _corr[prn] = cc;
|
---|
| 342 | }
|
---|
[2207] | 343 |
|
---|
[2035] | 344 | cc->tt.set(GPSweek, GPSweeks);
|
---|
[2207] | 345 |
|
---|
| 346 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
| 347 | messageType == COTYPE_GLONASSCOMBINED ) {
|
---|
[2366] | 348 | cc->rao.ReSize(3); cc->rao = 0.0;
|
---|
| 349 | cc->dotRao.ReSize(3); cc->dotRao = 0.0;
|
---|
| 350 | cc->dotDotRao.ReSize(3); cc->dotDotRao = 0.0;
|
---|
| 351 | cc->dClk = 0.0;
|
---|
| 352 | cc->dotDClk = 0.0;
|
---|
| 353 | cc->dotDotDClk = 0.0;
|
---|
| 354 | in >> cc->iod
|
---|
| 355 | >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2]
|
---|
| 356 | >> cc->dotDClk >> cc->dotRao[0] >> cc->dotRao[1] >> cc->dotRao[2]
|
---|
| 357 | >> cc->dotDotDClk >> cc->dotDotRao[0] >> cc->dotDotRao[1] >> cc->dotDotRao[2];
|
---|
| 358 | cc->dClk /= t_CST::c;
|
---|
| 359 | cc->dotDClk /= t_CST::c;
|
---|
| 360 | cc->dotDotDClk /= t_CST::c;
|
---|
[2208] | 361 | cc->raoSet = true;
|
---|
| 362 | cc->dClkSet = true;
|
---|
[2207] | 363 | }
|
---|
| 364 | else if ( messageType == COTYPE_GPSORBIT ||
|
---|
| 365 | messageType == COTYPE_GLONASSORBIT ) {
|
---|
[2366] | 366 | cc->rao.ReSize(3); cc->rao = 0.0;
|
---|
| 367 | cc->dotRao.ReSize(3); cc->dotRao = 0.0;
|
---|
| 368 | cc->dotDotRao.ReSize(3); cc->dotDotRao = 0.0;
|
---|
| 369 | in >> cc->iod
|
---|
| 370 | >> cc->rao[0] >> cc->rao[1] >> cc->rao[2]
|
---|
| 371 | >> cc->dotRao[0] >> cc->dotRao[1] >> cc->dotRao[2]
|
---|
| 372 | >> cc->dotDotRao[0] >> cc->dotDotRao[1] >> cc->dotDotRao[2];
|
---|
[2208] | 373 | cc->raoSet = true;
|
---|
[2207] | 374 | }
|
---|
| 375 | else if ( messageType == COTYPE_GPSCLOCK ||
|
---|
| 376 | messageType == COTYPE_GLONASSCLOCK ) {
|
---|
| 377 | int dummyIOD;
|
---|
[2366] | 378 | cc->dClk = 0.0;
|
---|
| 379 | cc->dotDClk = 0.0;
|
---|
| 380 | cc->dotDotDClk = 0.0;
|
---|
| 381 | in >> dummyIOD >> cc->dClk >> cc->dotDClk >> cc->dotDotDClk;
|
---|
| 382 | cc->dClk /= t_CST::c;
|
---|
| 383 | cc->dotDClk /= t_CST::c;
|
---|
| 384 | cc->dotDotDClk /= t_CST::c;
|
---|
[2208] | 385 | cc->dClkSet = true;
|
---|
[2207] | 386 | }
|
---|
[2035] | 387 | }
|
---|
[2317] | 388 | else if ( messageType == BTYPE_GPS ) {
|
---|
[2274] | 389 |
|
---|
| 390 | t_bias* bb = 0;
|
---|
| 391 | if (_bias.contains(prn)) {
|
---|
[2341] | 392 | bb = _bias.value(prn);
|
---|
[2274] | 393 | }
|
---|
| 394 | else {
|
---|
| 395 | bb = new t_bias();
|
---|
| 396 | _bias[prn] = bb;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | bb->tt.set(GPSweek, GPSweeks);
|
---|
| 400 |
|
---|
| 401 | int numBiases;
|
---|
| 402 | in >> numBiases;
|
---|
| 403 | for (int ii = 0; ii < numBiases; ++ii) {
|
---|
| 404 | int bType;
|
---|
| 405 | double bValue;
|
---|
| 406 | in >> bType >> bValue;
|
---|
[2426] | 407 | if (bType == CODETYPEGPS_L1_Z) {
|
---|
[2429] | 408 | bb->p1 = bValue;
|
---|
[2274] | 409 | }
|
---|
[2426] | 410 | else if (bType == CODETYPEGPS_L1_CA) {
|
---|
[2429] | 411 | bb->c1 = bValue;
|
---|
[2426] | 412 | }
|
---|
[2365] | 413 | else if (bType == CODETYPEGPS_L2_Z) {
|
---|
[2429] | 414 | bb->p2 = bValue;
|
---|
[2274] | 415 | }
|
---|
| 416 | }
|
---|
| 417 | }
|
---|
[2035] | 418 | }
|
---|
[2208] | 419 |
|
---|
| 420 | QMutableMapIterator<QString, t_corr*> im(_corr);
|
---|
| 421 | while (im.hasNext()) {
|
---|
| 422 | im.next();
|
---|
| 423 | t_corr* cc = im.value();
|
---|
| 424 | if (!cc->ready()) {
|
---|
| 425 | delete cc;
|
---|
| 426 | im.remove();
|
---|
| 427 | }
|
---|
| 428 | }
|
---|
[2035] | 429 | }
|
---|
| 430 |
|
---|
| 431 | // Satellite Position
|
---|
| 432 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2123] | 433 | t_irc bncPPPclient::getSatPos(const bncTime& tt, const QString& prn,
|
---|
[2357] | 434 | ColumnVector& xc, ColumnVector& vv) {
|
---|
[2035] | 435 |
|
---|
[2576] | 436 | const double MAXAGE = 120.0;
|
---|
[2041] | 437 |
|
---|
[2035] | 438 | if (_eph.contains(prn)) {
|
---|
[2040] | 439 |
|
---|
[2357] | 440 | if (_pppMode) {
|
---|
[2068] | 441 | if (_corr.contains(prn)) {
|
---|
| 442 | t_corr* cc = _corr.value(prn);
|
---|
[2576] | 443 | if (tt - cc->tt < MAXAGE) {
|
---|
| 444 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 445 | t_eph* ePrev = _eph.value(prn)->prev;
|
---|
| 446 | if (eLast && eLast->IOD() == cc->iod) {
|
---|
| 447 | eLast->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
| 448 | applyCorr(tt, cc, xc, vv);
|
---|
| 449 | return success;
|
---|
| 450 | }
|
---|
| 451 | else if (ePrev && ePrev->IOD() == cc->iod) {
|
---|
| 452 | ePrev->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
| 453 | applyCorr(tt, cc, xc, vv);
|
---|
| 454 | return success;
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
[2041] | 457 | }
|
---|
[2040] | 458 | }
|
---|
[2576] | 459 |
|
---|
| 460 | else {
|
---|
| 461 | t_eph* ee = _eph.value(prn)->last;
|
---|
| 462 | ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
| 463 | return success;
|
---|
| 464 | }
|
---|
[2035] | 465 | }
|
---|
| 466 |
|
---|
| 467 | return failure;
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | //
|
---|
| 471 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2296] | 472 | void bncPPPclient::applyCorr(const bncTime& tt, const t_corr* cc,
|
---|
| 473 | ColumnVector& xc, ColumnVector& vv) {
|
---|
[2043] | 474 | ColumnVector dx(3);
|
---|
[2041] | 475 |
|
---|
[2367] | 476 | double dt = tt - cc->tt;
|
---|
| 477 | ColumnVector raoHlp = cc->rao + cc->dotRao * dt + cc->dotDotRao * dt * dt;
|
---|
[2296] | 478 |
|
---|
| 479 | RSW_to_XYZ(xc.Rows(1,3), vv, raoHlp, dx);
|
---|
| 480 |
|
---|
[2414] | 481 | xc[0] -= dx[0];
|
---|
| 482 | xc[1] -= dx[1];
|
---|
| 483 | xc[2] -= dx[2];
|
---|
[2417] | 484 | xc[3] += cc->dClk + cc->dotDClk * dt + cc->dotDotDClk * dt * dt;
|
---|
[2041] | 485 | }
|
---|
| 486 |
|
---|
[2049] | 487 | // Correct Time of Transmission
|
---|
| 488 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2240] | 489 | t_irc bncPPPclient::cmpToT(t_satData* satData) {
|
---|
[2049] | 490 |
|
---|
[2051] | 491 | double prange = satData->P3;
|
---|
[2049] | 492 | if (prange == 0.0) {
|
---|
| 493 | return failure;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | double clkSat = 0.0;
|
---|
| 497 | for (int ii = 1; ii <= 10; ii++) {
|
---|
| 498 |
|
---|
[2123] | 499 | bncTime ToT = _epoData->tt - prange / t_CST::c - clkSat;
|
---|
[2049] | 500 |
|
---|
| 501 | ColumnVector xc(4);
|
---|
| 502 | ColumnVector vv(3);
|
---|
[2357] | 503 | if (getSatPos(ToT, satData->prn, xc, vv) != success) {
|
---|
[2049] | 504 | return failure;
|
---|
| 505 | }
|
---|
| 506 |
|
---|
| 507 | double clkSatOld = clkSat;
|
---|
[2050] | 508 | clkSat = xc(4);
|
---|
[2049] | 509 |
|
---|
| 510 | if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
|
---|
| 511 | satData->xx = xc.Rows(1,3);
|
---|
| 512 | satData->vv = vv;
|
---|
[2050] | 513 | satData->clk = clkSat * t_CST::c;
|
---|
[2049] | 514 | return success;
|
---|
| 515 | }
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | return failure;
|
---|
| 519 | }
|
---|
| 520 |
|
---|
[2041] | 521 | //
|
---|
| 522 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2035] | 523 | void bncPPPclient::processEpoch() {
|
---|
| 524 |
|
---|
[2053] | 525 | // Data Pre-Processing
|
---|
| 526 | // -------------------
|
---|
[2231] | 527 | QMutableMapIterator<QString, t_satData*> iGPS(_epoData->satDataGPS);
|
---|
| 528 | while (iGPS.hasNext()) {
|
---|
| 529 | iGPS.next();
|
---|
| 530 | QString prn = iGPS.key();
|
---|
| 531 | t_satData* satData = iGPS.value();
|
---|
[2049] | 532 |
|
---|
[2240] | 533 | if (cmpToT(satData) != success) {
|
---|
[2049] | 534 | delete satData;
|
---|
[2231] | 535 | iGPS.remove();
|
---|
[2049] | 536 | continue;
|
---|
| 537 | }
|
---|
[2053] | 538 | }
|
---|
[2035] | 539 |
|
---|
[2231] | 540 | QMutableMapIterator<QString, t_satData*> iGlo(_epoData->satDataGlo);
|
---|
| 541 | while (iGlo.hasNext()) {
|
---|
| 542 | iGlo.next();
|
---|
| 543 | QString prn = iGlo.key();
|
---|
| 544 | t_satData* satData = iGlo.value();
|
---|
| 545 |
|
---|
[2240] | 546 | if (cmpToT(satData) != success) {
|
---|
[2231] | 547 | delete satData;
|
---|
| 548 | iGlo.remove();
|
---|
| 549 | continue;
|
---|
| 550 | }
|
---|
| 551 | }
|
---|
| 552 |
|
---|
[2060] | 553 | // Filter Solution
|
---|
| 554 | // ---------------
|
---|
[2143] | 555 | if (_model->update(_epoData) == success) {
|
---|
[2145] | 556 | emit newPosition(_model->time(), _model->x(), _model->y(), _model->z());
|
---|
[2060] | 557 | }
|
---|
[2035] | 558 | }
|
---|
[2049] | 559 |
|
---|