[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>
|
---|
| 43 |
|
---|
[2035] | 44 | #include "bncpppclient.h"
|
---|
[2113] | 45 | #include "bncapp.h"
|
---|
[2043] | 46 | #include "bncutils.h"
|
---|
[2044] | 47 | #include "bncconst.h"
|
---|
[2058] | 48 | #include "bncmodel.h"
|
---|
[2226] | 49 | #include "bncsettings.h"
|
---|
[2035] | 50 |
|
---|
| 51 | extern "C" {
|
---|
| 52 | #include "clock_orbit_rtcm.h"
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | using namespace std;
|
---|
| 56 |
|
---|
| 57 | // Constructor
|
---|
| 58 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 59 | bncPPPclient::bncPPPclient(QByteArray staID) {
|
---|
[2113] | 60 |
|
---|
[2226] | 61 | bncSettings settings;
|
---|
| 62 |
|
---|
| 63 | if ( Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
|
---|
| 64 | _useGlonass = true;
|
---|
| 65 | }
|
---|
| 66 | else {
|
---|
| 67 | _useGlonass = false;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[2113] | 70 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
| 71 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
[2224] | 72 | connect(((bncApp*)qApp), SIGNAL(newEphGlonass(glonassephemeris)),
|
---|
| 73 | this, SLOT(slotNewEphGlonass(glonassephemeris)));
|
---|
[2113] | 74 | connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
|
---|
| 75 | this, SLOT(slotNewCorrections(QList<QString>)));
|
---|
| 76 |
|
---|
[2039] | 77 | _staID = staID;
|
---|
| 78 | _epoData = 0;
|
---|
[2113] | 79 | _model = new bncModel(staID);
|
---|
[2182] | 80 | connect(_model, SIGNAL(newNMEAstr(QByteArray)),
|
---|
| 81 | this, SIGNAL(newNMEAstr(QByteArray)));
|
---|
[2035] | 82 | }
|
---|
| 83 |
|
---|
| 84 | // Destructor
|
---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 86 | bncPPPclient::~bncPPPclient() {
|
---|
[2058] | 87 | delete _model;
|
---|
[2039] | 88 | delete _epoData;
|
---|
[2035] | 89 | QMapIterator<QString, t_eph*> it(_eph);
|
---|
| 90 | while (it.hasNext()) {
|
---|
| 91 | it.next();
|
---|
| 92 | delete it.value();
|
---|
| 93 | }
|
---|
| 94 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
| 95 | while (ic.hasNext()) {
|
---|
| 96 | ic.next();
|
---|
| 97 | delete ic.value();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | //
|
---|
| 102 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 103 | void bncPPPclient::putNewObs(p_obs pp) {
|
---|
[2037] | 104 | QMutexLocker locker(&_mutex);
|
---|
[2051] | 105 |
|
---|
[2037] | 106 | t_obsInternal* obs = &(pp->_o);
|
---|
[2051] | 107 |
|
---|
[2226] | 108 | if (obs->satSys != 'G' && !_useGlonass) {
|
---|
[2225] | 109 | return;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[2051] | 112 | t_satData* satData = new t_satData();
|
---|
| 113 |
|
---|
| 114 | // Set Code Observations
|
---|
| 115 | // ---------------------
|
---|
| 116 | if (obs->P1) {
|
---|
| 117 | satData->P1 = obs->P1;
|
---|
| 118 | satData->codeTypeF1 = t_satData::P_CODE;
|
---|
| 119 | }
|
---|
| 120 | else if (obs->C1) {
|
---|
| 121 | satData->P1 = obs->C1;
|
---|
| 122 | satData->codeTypeF1 = t_satData::C_CODE;
|
---|
| 123 | }
|
---|
| 124 | else {
|
---|
| 125 | delete satData;
|
---|
| 126 | return;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | if (obs->P2) {
|
---|
| 130 | satData->P2 = obs->P2;
|
---|
| 131 | satData->codeTypeF2 = t_satData::P_CODE;
|
---|
| 132 | }
|
---|
| 133 | else if (obs->C2) {
|
---|
| 134 | satData->P2 = obs->C2;
|
---|
| 135 | satData->codeTypeF2 = t_satData::C_CODE;
|
---|
| 136 | }
|
---|
| 137 | else {
|
---|
| 138 | delete satData;
|
---|
| 139 | return;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[2228] | 142 | double f1 = t_CST::freq1;
|
---|
| 143 | double f2 = t_CST::freq2;
|
---|
| 144 |
|
---|
[2229] | 145 | if (obs->satSys == 'R') {
|
---|
| 146 | f1 = 1602000000.0 + 562500.0 * obs->slot;
|
---|
| 147 | f2 = 1246000000.0 + 437500.0 * obs->slot;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[2228] | 150 | // Ionosphere-Free Combination
|
---|
| 151 | // ---------------------------
|
---|
| 152 | double c1 = f1 * f1 / (f1 * f1 - f2 * f2);
|
---|
| 153 | double c2 = - f2 * f2 / (f1 * f1 - f2 * f2);
|
---|
| 154 |
|
---|
[2051] | 155 | satData->P3 = c1 * satData->P1 + c2 * satData->P2;
|
---|
| 156 |
|
---|
| 157 | // Set Phase Observations
|
---|
| 158 | // ----------------------
|
---|
| 159 | if (obs->L1 && obs->L2) {
|
---|
[2228] | 160 | satData->L1 = obs->L1 * t_CST::c / f1;
|
---|
| 161 | satData->L2 = obs->L2 * t_CST::c / f2;
|
---|
[2051] | 162 | }
|
---|
| 163 | else {
|
---|
| 164 | delete satData;
|
---|
| 165 | return;
|
---|
| 166 | }
|
---|
| 167 | satData->L3 = c1 * satData->L1 + c2 * satData->L2;
|
---|
| 168 |
|
---|
| 169 | // Add new Satellite to the epoch
|
---|
| 170 | // ------------------------------
|
---|
[2123] | 171 | bncTime tt(obs->GPSWeek, obs->GPSWeeks);
|
---|
[2037] | 172 |
|
---|
[2039] | 173 | if (!_epoData) {
|
---|
| 174 | _epoData = new t_epoData();
|
---|
| 175 | _epoData->tt = tt;
|
---|
[2037] | 176 | }
|
---|
[2039] | 177 | else if (tt != _epoData->tt) {
|
---|
[2037] | 178 | processEpoch();
|
---|
[2039] | 179 | delete _epoData;
|
---|
| 180 | _epoData = new t_epoData();
|
---|
| 181 | _epoData->tt = tt;
|
---|
[2037] | 182 | }
|
---|
[2039] | 183 |
|
---|
[2231] | 184 | if (obs->satSys == 'G') {
|
---|
[2232] | 185 | QString prn = QString("G%1").arg(obs->satNum, 2, 10, QChar('0'));
|
---|
[2240] | 186 | satData->prn = prn;
|
---|
[2231] | 187 | _epoData->satDataGPS[prn] = satData;
|
---|
| 188 | }
|
---|
| 189 | else if (obs->satSys == 'R') {
|
---|
[2232] | 190 | QString prn = QString("R%1").arg(obs->satNum, 2, 10, QChar('0'));
|
---|
[2240] | 191 | satData->prn = prn;
|
---|
[2231] | 192 | _epoData->satDataGlo[prn] = satData;
|
---|
| 193 | }
|
---|
[2233] | 194 |
|
---|
[2035] | 195 | }
|
---|
| 196 |
|
---|
| 197 | //
|
---|
| 198 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 199 | void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
| 200 | QMutexLocker locker(&_mutex);
|
---|
| 201 |
|
---|
| 202 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
---|
| 203 |
|
---|
| 204 | if (_eph.contains(prn)) {
|
---|
[2040] | 205 | t_ephGPS* ee = static_cast<t_ephGPS*>(_eph.value(prn));
|
---|
| 206 | if ( (ee->GPSweek() < gpseph.GPSweek) ||
|
---|
| 207 | (ee->GPSweek() == gpseph.GPSweek &&
|
---|
| 208 | ee->TOC() < gpseph.TOC) ) {
|
---|
| 209 | ee->set(&gpseph);
|
---|
| 210 | }
|
---|
[2035] | 211 | }
|
---|
| 212 | else {
|
---|
| 213 | t_ephGPS* ee = new t_ephGPS();
|
---|
| 214 | ee->set(&gpseph);
|
---|
| 215 | _eph[prn] = ee;
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | //
|
---|
| 220 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2224] | 221 | void bncPPPclient::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
| 222 | QMutexLocker locker(&_mutex);
|
---|
| 223 |
|
---|
| 224 | QString prn = QString("R%1").arg(gloeph.almanac_number, 2, 10, QChar('0'));
|
---|
| 225 |
|
---|
| 226 | if (_eph.contains(prn)) {
|
---|
| 227 | t_ephGlo* ee = static_cast<t_ephGlo*>(_eph.value(prn));
|
---|
| 228 | if ( (ee->GPSweek() < gloeph.GPSWeek) ||
|
---|
| 229 | (ee->GPSweek() == gloeph.GPSWeek &&
|
---|
| 230 | ee->GPSweeks() < gloeph.GPSTOW) ) {
|
---|
| 231 | ee->set(&gloeph);
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 | else {
|
---|
| 235 | t_ephGlo* ee = new t_ephGlo();
|
---|
| 236 | ee->set(&gloeph);
|
---|
| 237 | _eph[prn] = ee;
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | //
|
---|
| 242 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2035] | 243 | void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
|
---|
| 244 | QMutexLocker locker(&_mutex);
|
---|
[2069] | 245 |
|
---|
| 246 | if (corrList.size() == 0) {
|
---|
| 247 | return;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | // Remove All Corrections
|
---|
| 251 | // ----------------------
|
---|
| 252 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
| 253 | while (ic.hasNext()) {
|
---|
| 254 | ic.next();
|
---|
| 255 | delete ic.value();
|
---|
| 256 | }
|
---|
| 257 | _corr.clear();
|
---|
| 258 |
|
---|
[2035] | 259 | QListIterator<QString> it(corrList);
|
---|
| 260 | while (it.hasNext()) {
|
---|
| 261 | QTextStream in(it.next().toAscii());
|
---|
| 262 | int messageType;
|
---|
| 263 | int updateInterval;
|
---|
| 264 | int GPSweek;
|
---|
| 265 | double GPSweeks;
|
---|
| 266 | QString prn;
|
---|
| 267 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
| 268 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
[2207] | 269 | messageType == COTYPE_GLONASSCOMBINED ||
|
---|
| 270 | messageType == COTYPE_GPSORBIT ||
|
---|
| 271 | messageType == COTYPE_GPSCLOCK ||
|
---|
| 272 | messageType == COTYPE_GLONASSORBIT ||
|
---|
| 273 | messageType == COTYPE_GLONASSCLOCK ) {
|
---|
| 274 |
|
---|
[2035] | 275 | t_corr* cc = 0;
|
---|
| 276 | if (_corr.contains(prn)) {
|
---|
| 277 | cc = _corr.value(prn);
|
---|
| 278 | }
|
---|
| 279 | else {
|
---|
| 280 | cc = new t_corr();
|
---|
| 281 | _corr[prn] = cc;
|
---|
| 282 | }
|
---|
[2207] | 283 |
|
---|
[2035] | 284 | cc->tt.set(GPSweek, GPSweeks);
|
---|
[2207] | 285 |
|
---|
| 286 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
| 287 | messageType == COTYPE_GLONASSCOMBINED ) {
|
---|
| 288 | cc->rao.ReSize(3);
|
---|
| 289 | in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
|
---|
| 290 | cc->dClk /= t_CST::c;
|
---|
[2208] | 291 | cc->raoSet = true;
|
---|
| 292 | cc->dClkSet = true;
|
---|
[2207] | 293 | }
|
---|
| 294 | else if ( messageType == COTYPE_GPSORBIT ||
|
---|
| 295 | messageType == COTYPE_GLONASSORBIT ) {
|
---|
| 296 | cc->rao.ReSize(3);
|
---|
| 297 | in >> cc->iod >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
|
---|
[2208] | 298 | cc->raoSet = true;
|
---|
[2207] | 299 | }
|
---|
| 300 | else if ( messageType == COTYPE_GPSCLOCK ||
|
---|
| 301 | messageType == COTYPE_GLONASSCLOCK ) {
|
---|
| 302 | int dummyIOD;
|
---|
| 303 | in >> dummyIOD >> cc->dClk;
|
---|
| 304 | cc->dClk /= t_CST::c;
|
---|
[2208] | 305 | cc->dClkSet = true;
|
---|
[2207] | 306 | }
|
---|
[2035] | 307 | }
|
---|
| 308 | }
|
---|
[2208] | 309 |
|
---|
| 310 | QMutableMapIterator<QString, t_corr*> im(_corr);
|
---|
| 311 | while (im.hasNext()) {
|
---|
| 312 | im.next();
|
---|
| 313 | t_corr* cc = im.value();
|
---|
| 314 | if (!cc->ready()) {
|
---|
| 315 | delete cc;
|
---|
| 316 | im.remove();
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
[2035] | 319 | }
|
---|
| 320 |
|
---|
| 321 | // Satellite Position
|
---|
| 322 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2123] | 323 | t_irc bncPPPclient::getSatPos(const bncTime& tt, const QString& prn,
|
---|
[2041] | 324 | ColumnVector& xc, ColumnVector& vv, bool& corr) {
|
---|
[2035] | 325 |
|
---|
[2241] | 326 | const bool CORR_REQUIRED = true;
|
---|
[2067] | 327 | const double MAXAGE = 120.0;
|
---|
[2041] | 328 |
|
---|
| 329 | corr = false;
|
---|
| 330 |
|
---|
[2035] | 331 | if (_eph.contains(prn)) {
|
---|
[2040] | 332 | t_eph* ee = _eph.value(prn);
|
---|
| 333 | ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
| 334 |
|
---|
[2247] | 335 | if (CORR_REQUIRED) {
|
---|
[2068] | 336 | if (_corr.contains(prn)) {
|
---|
| 337 | t_corr* cc = _corr.value(prn);
|
---|
| 338 | if (ee->IOD() == cc->iod && (tt - cc->tt) < MAXAGE) {
|
---|
| 339 | corr = true;
|
---|
| 340 | applyCorr(cc, xc, vv);
|
---|
| 341 | return success;
|
---|
| 342 | }
|
---|
[2041] | 343 | }
|
---|
[2068] | 344 | return failure;
|
---|
[2040] | 345 | }
|
---|
[2068] | 346 |
|
---|
[2035] | 347 | return success;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | return failure;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | //
|
---|
| 354 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2041] | 355 | void bncPPPclient::applyCorr(const t_corr* cc, ColumnVector& xc,
|
---|
| 356 | ColumnVector& vv) {
|
---|
[2043] | 357 | ColumnVector dx(3);
|
---|
| 358 | RSW_to_XYZ(xc.Rows(1,3), vv, cc->rao, dx);
|
---|
[2041] | 359 |
|
---|
[2107] | 360 | xc[0] -= dx[0];
|
---|
| 361 | xc[1] -= dx[1];
|
---|
| 362 | xc[2] -= dx[2];
|
---|
| 363 | xc[3] -= cc->dClk;
|
---|
[2068] | 364 |
|
---|
| 365 | // Relativistic Correction
|
---|
| 366 | // -----------------------
|
---|
| 367 | xc[3] -= 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c ;
|
---|
[2041] | 368 | }
|
---|
| 369 |
|
---|
[2049] | 370 | // Correct Time of Transmission
|
---|
| 371 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2240] | 372 | t_irc bncPPPclient::cmpToT(t_satData* satData) {
|
---|
[2049] | 373 |
|
---|
[2051] | 374 | double prange = satData->P3;
|
---|
[2049] | 375 | if (prange == 0.0) {
|
---|
| 376 | return failure;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | double clkSat = 0.0;
|
---|
| 380 | for (int ii = 1; ii <= 10; ii++) {
|
---|
| 381 |
|
---|
[2123] | 382 | bncTime ToT = _epoData->tt - prange / t_CST::c - clkSat;
|
---|
[2049] | 383 |
|
---|
| 384 | ColumnVector xc(4);
|
---|
| 385 | ColumnVector vv(3);
|
---|
| 386 | bool corr = false;
|
---|
[2240] | 387 | if (getSatPos(ToT, satData->prn, xc, vv, corr) != success) {
|
---|
[2049] | 388 | return failure;
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | double clkSatOld = clkSat;
|
---|
[2050] | 392 | clkSat = xc(4);
|
---|
[2049] | 393 |
|
---|
| 394 | if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
|
---|
| 395 | satData->xx = xc.Rows(1,3);
|
---|
| 396 | satData->vv = vv;
|
---|
[2050] | 397 | satData->clk = clkSat * t_CST::c;
|
---|
[2049] | 398 | satData->clkCorr = corr;
|
---|
| 399 | return success;
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | return failure;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[2041] | 406 | //
|
---|
| 407 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2035] | 408 | void bncPPPclient::processEpoch() {
|
---|
| 409 |
|
---|
[2053] | 410 | // Data Pre-Processing
|
---|
| 411 | // -------------------
|
---|
[2231] | 412 | QMutableMapIterator<QString, t_satData*> iGPS(_epoData->satDataGPS);
|
---|
| 413 | while (iGPS.hasNext()) {
|
---|
| 414 | iGPS.next();
|
---|
| 415 | QString prn = iGPS.key();
|
---|
| 416 | t_satData* satData = iGPS.value();
|
---|
[2049] | 417 |
|
---|
[2240] | 418 | if (cmpToT(satData) != success) {
|
---|
[2049] | 419 | delete satData;
|
---|
[2231] | 420 | iGPS.remove();
|
---|
[2049] | 421 | continue;
|
---|
| 422 | }
|
---|
[2053] | 423 | }
|
---|
[2035] | 424 |
|
---|
[2231] | 425 | QMutableMapIterator<QString, t_satData*> iGlo(_epoData->satDataGlo);
|
---|
| 426 | while (iGlo.hasNext()) {
|
---|
| 427 | iGlo.next();
|
---|
| 428 | QString prn = iGlo.key();
|
---|
| 429 | t_satData* satData = iGlo.value();
|
---|
| 430 |
|
---|
[2240] | 431 | if (cmpToT(satData) != success) {
|
---|
[2231] | 432 | delete satData;
|
---|
| 433 | iGlo.remove();
|
---|
| 434 | continue;
|
---|
| 435 | }
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[2060] | 438 | // Filter Solution
|
---|
| 439 | // ---------------
|
---|
[2143] | 440 | if (_model->update(_epoData) == success) {
|
---|
[2145] | 441 | emit newPosition(_model->time(), _model->x(), _model->y(), _model->z());
|
---|
[2060] | 442 | }
|
---|
[2035] | 443 | }
|
---|
[2049] | 444 |
|
---|