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