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