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