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