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