[6054] | 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 <newmatio.h>
|
---|
| 42 | #include <iomanip>
|
---|
| 43 | #include <sstream>
|
---|
| 44 |
|
---|
| 45 | #include "bncpppclient.h"
|
---|
| 46 | #include "bnccore.h"
|
---|
| 47 | #include "bncutils.h"
|
---|
| 48 | #include "bncconst.h"
|
---|
| 49 | #include "bncmodel.h"
|
---|
[6055] | 50 | #include "pppOptions.h"
|
---|
[6073] | 51 | #include "pppClient.h"
|
---|
[6054] | 52 |
|
---|
[6055] | 53 | using namespace BNC_PPP;
|
---|
[6054] | 54 | using namespace std;
|
---|
| 55 |
|
---|
| 56 | // Constructor
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6067] | 58 | bncPPPclient::bncPPPclient(QByteArray staID, const t_pppOptions* opt) : bncEphUser(false) {
|
---|
[6054] | 59 |
|
---|
[6073] | 60 | _opt = opt;
|
---|
| 61 | _staID = staID;
|
---|
| 62 | _model = new bncModel(this);
|
---|
| 63 | _epoData = new t_epoData();
|
---|
[6054] | 64 | }
|
---|
| 65 |
|
---|
| 66 | // Destructor
|
---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 68 | bncPPPclient::~bncPPPclient() {
|
---|
[6073] | 69 | _epoData->clear();
|
---|
| 70 |
|
---|
[6054] | 71 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
| 72 | while (ic.hasNext()) {
|
---|
| 73 | ic.next();
|
---|
| 74 | delete ic.value();
|
---|
| 75 | }
|
---|
[6073] | 76 |
|
---|
[6054] | 77 | QMapIterator<QString, t_bias*> ib(_bias);
|
---|
| 78 | while (ib.hasNext()) {
|
---|
| 79 | ib.next();
|
---|
| 80 | delete ib.value();
|
---|
| 81 | }
|
---|
[6073] | 82 |
|
---|
[6065] | 83 | delete _model;
|
---|
[6054] | 84 | }
|
---|
| 85 |
|
---|
| 86 | //
|
---|
| 87 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6073] | 88 | void bncPPPclient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
---|
[6054] | 89 | QMutexLocker locker(&_mutex);
|
---|
[6075] | 90 |
|
---|
| 91 | // Convert and store observations
|
---|
| 92 | // ------------------------------
|
---|
[6073] | 93 | _epoData->clear();
|
---|
| 94 | for (unsigned ii = 0; ii < satObs.size(); ii++) {
|
---|
| 95 | const t_satObs* obs = satObs[ii];
|
---|
| 96 | t_satData* satData = new t_satData();
|
---|
[6080] | 97 |
|
---|
| 98 | if (_epoData->tt.undef()) {
|
---|
| 99 | _epoData->tt = obs->_time;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[6073] | 102 | satData->tt = obs->_time;
|
---|
| 103 | satData->prn = QString(obs->_prn.toString().c_str());
|
---|
| 104 | satData->slipFlag = false;
|
---|
| 105 | satData->P1 = 0.0;
|
---|
| 106 | satData->P2 = 0.0;
|
---|
| 107 | satData->P5 = 0.0;
|
---|
| 108 | satData->L1 = 0.0;
|
---|
| 109 | satData->L2 = 0.0;
|
---|
| 110 | satData->L5 = 0.0;
|
---|
| 111 | for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
|
---|
| 112 | t_frqObs* frqObs = obs->_obs[ifrq];
|
---|
| 113 | if (frqObs->_rnxType2ch[0] == '1') {
|
---|
| 114 | if (frqObs->_codeValid) satData->P1 = frqObs->_code;
|
---|
| 115 | if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
|
---|
| 116 | if (frqObs->_slip) satData->slipFlag = true;
|
---|
| 117 | }
|
---|
| 118 | else if (frqObs->_rnxType2ch[0] == '2') {
|
---|
| 119 | if (frqObs->_codeValid) satData->P2 = frqObs->_code;
|
---|
| 120 | if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
|
---|
| 121 | if (frqObs->_slip) satData->slipFlag = true;
|
---|
| 122 | }
|
---|
| 123 | else if (frqObs->_rnxType2ch[0] == '5') {
|
---|
| 124 | if (frqObs->_codeValid) satData->P5 = frqObs->_code;
|
---|
| 125 | if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
|
---|
| 126 | if (frqObs->_slip) satData->slipFlag = true;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | putNewObs(satData);
|
---|
[6054] | 130 | }
|
---|
[6073] | 131 |
|
---|
| 132 | // Data Pre-Processing
|
---|
| 133 | // -------------------
|
---|
| 134 | QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
|
---|
| 135 | while (it.hasNext()) {
|
---|
| 136 | it.next();
|
---|
| 137 | QString prn = it.key();
|
---|
| 138 | t_satData* satData = it.value();
|
---|
| 139 |
|
---|
| 140 | if (cmpToT(satData) != success) {
|
---|
| 141 | delete satData;
|
---|
| 142 | it.remove();
|
---|
| 143 | continue;
|
---|
| 144 | }
|
---|
[6054] | 145 | }
|
---|
| 146 |
|
---|
[6073] | 147 | // Filter Solution
|
---|
| 148 | // ---------------
|
---|
| 149 | if (_model->update(_epoData) == success) {
|
---|
[6075] | 150 | output->_error = false;
|
---|
[6077] | 151 | output->_epoTime = _model->time();
|
---|
| 152 | output->_xyzRover[0] = _model->x();
|
---|
| 153 | output->_xyzRover[1] = _model->y();
|
---|
| 154 | output->_xyzRover[2] = _model->z();
|
---|
| 155 | output->_numSat = 0;
|
---|
| 156 | output->_pDop = 0.0;
|
---|
[6073] | 157 | }
|
---|
| 158 | else {
|
---|
| 159 | output->_error = true;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[6079] | 162 | output->_log = LOG.str();
|
---|
[6073] | 163 | }
|
---|
| 164 |
|
---|
| 165 | //
|
---|
| 166 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 167 | void bncPPPclient::putNewObs(t_satData* satData) {
|
---|
| 168 |
|
---|
[6054] | 169 | // Set Observations GPS and Glonass
|
---|
| 170 | // --------------------------------
|
---|
[6072] | 171 | if (satData->system() == 'G' || satData->system() == 'R') {
|
---|
| 172 | if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
|
---|
| 173 | satData->L1 != 0.0 && satData->L2 != 0.0 ) {
|
---|
[6054] | 174 |
|
---|
[6072] | 175 | int channel = 0;
|
---|
| 176 | if (satData->system() == 'R') {
|
---|
[6077] | 177 | // cerr << "not yet implemented" << endl;
|
---|
| 178 | // exit(0);
|
---|
[6054] | 179 | }
|
---|
| 180 |
|
---|
[6072] | 181 | t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
|
---|
| 182 | t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
|
---|
| 183 | double f1 = t_CST::freq(fType1, channel);
|
---|
| 184 | double f2 = t_CST::freq(fType2, channel);
|
---|
[6054] | 185 | double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
|
---|
| 186 | double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
|
---|
[6080] | 187 | satData->L1 = satData->L1 * t_CST::c / f1;
|
---|
| 188 | satData->L2 = satData->L2 * t_CST::c / f2;
|
---|
[6054] | 189 | satData->P3 = a1 * satData->P1 + a2 * satData->P2;
|
---|
| 190 | satData->L3 = a1 * satData->L1 + a2 * satData->L2;
|
---|
| 191 | satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
|
---|
[6073] | 192 | _epoData->satData[satData->prn] = satData;
|
---|
[6054] | 193 | }
|
---|
| 194 | else {
|
---|
| 195 | delete satData;
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | // Set Observations Galileo
|
---|
| 200 | // ------------------------
|
---|
[6072] | 201 | else if (satData->system() == 'E') {
|
---|
[6054] | 202 | if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
|
---|
| 203 | satData->L1 != 0.0 && satData->L5 != 0.0 ) {
|
---|
[6055] | 204 | double f1 = t_CST::freq(t_frequency::E1, 0);
|
---|
| 205 | double f5 = t_CST::freq(t_frequency::E5, 0);
|
---|
[6054] | 206 | double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
|
---|
| 207 | double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
|
---|
[6080] | 208 | satData->L1 = satData->L1 * t_CST::c / f1;
|
---|
| 209 | satData->L5 = satData->L5 * t_CST::c / f5;
|
---|
[6054] | 210 | satData->P3 = a1 * satData->P1 + a5 * satData->P5;
|
---|
| 211 | satData->L3 = a1 * satData->L1 + a5 * satData->L5;
|
---|
| 212 | satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
|
---|
[6073] | 213 | _epoData->satData[satData->prn] = satData;
|
---|
[6054] | 214 | }
|
---|
| 215 | else {
|
---|
| 216 | delete satData;
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | //
|
---|
| 222 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6065] | 223 | void bncPPPclient::putNewCorrections(QList<QString> corrList) {
|
---|
[6054] | 224 | QMutexLocker locker(&_mutex);
|
---|
| 225 |
|
---|
| 226 | // Check the Mountpoint (source of corrections)
|
---|
| 227 | // --------------------------------------------
|
---|
[6055] | 228 | if (!_opt->_corrMount.empty()) {
|
---|
[6054] | 229 | QMutableListIterator<QString> itm(corrList);
|
---|
| 230 | while (itm.hasNext()) {
|
---|
| 231 | QStringList hlp = itm.next().split(" ");
|
---|
| 232 | if (hlp.size() > 0) {
|
---|
| 233 | QString mountpoint = hlp[hlp.size()-1];
|
---|
[6055] | 234 | if (mountpoint != QString(_opt->_corrMount.c_str())) {
|
---|
[6054] | 235 | itm.remove();
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | if (corrList.size() == 0) {
|
---|
| 242 | return;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | QListIterator<QString> it(corrList);
|
---|
| 246 | while (it.hasNext()) {
|
---|
| 247 | QString line = it.next();
|
---|
| 248 |
|
---|
| 249 | QTextStream in(&line);
|
---|
| 250 | int messageType;
|
---|
| 251 | int updateInterval;
|
---|
| 252 | int GPSweek;
|
---|
| 253 | double GPSweeks;
|
---|
| 254 | QString prn;
|
---|
| 255 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
| 256 |
|
---|
| 257 | if ( t_corr::relevantMessageType(messageType) ) {
|
---|
| 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 | }
|
---|
| 266 | cc->readLine(line);
|
---|
| 267 | _corr_tt = cc->tClk;
|
---|
| 268 | }
|
---|
| 269 | else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
|
---|
| 270 | t_bias* bb = 0;
|
---|
| 271 | if (_bias.contains(prn)) {
|
---|
| 272 | bb = _bias.value(prn);
|
---|
| 273 | }
|
---|
| 274 | else {
|
---|
| 275 | bb = new t_bias();
|
---|
| 276 | _bias[prn] = bb;
|
---|
| 277 | }
|
---|
| 278 | bb->readLine(line);
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | // Satellite Position
|
---|
| 284 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 285 | t_irc bncPPPclient::getSatPos(const bncTime& tt, const QString& prn,
|
---|
| 286 | ColumnVector& xc, ColumnVector& vv) {
|
---|
| 287 | if (_eph.contains(prn)) {
|
---|
[6081] | 288 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 289 | t_eph* ePrev = _eph.value(prn)->prev;
|
---|
| 290 | if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
|
---|
| 291 | return success;
|
---|
[6054] | 292 | }
|
---|
[6081] | 293 | else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
|
---|
[6054] | 294 | return success;
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
| 297 | return failure;
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | //
|
---|
| 301 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 302 | t_irc bncPPPclient::applyCorr(const bncTime& tt, const t_corr* cc,
|
---|
| 303 | ColumnVector& xc, ColumnVector& vv) {
|
---|
| 304 |
|
---|
| 305 | double dtRao = tt - cc->tRao;
|
---|
| 306 |
|
---|
| 307 | // Position
|
---|
| 308 | // --------
|
---|
| 309 | ColumnVector raoHlp = cc->rao + cc->dotRao * dtRao;
|
---|
| 310 |
|
---|
| 311 | if (raoHlp.norm_Frobenius() > 20.0) {
|
---|
| 312 | return failure;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | ColumnVector dx(3);
|
---|
| 316 | RSW_to_XYZ(xc.Rows(1,3), vv, raoHlp, dx);
|
---|
| 317 | xc[0] -= dx[0];
|
---|
| 318 | xc[1] -= dx[1];
|
---|
| 319 | xc[2] -= dx[2];
|
---|
| 320 |
|
---|
| 321 | // Velocity
|
---|
| 322 | // --------
|
---|
| 323 | ColumnVector dotRaoHlp = cc->dotRao;
|
---|
| 324 |
|
---|
| 325 | ColumnVector dv(3);
|
---|
| 326 | RSW_to_XYZ(xc.Rows(1,3), vv, dotRaoHlp, dv);
|
---|
| 327 | vv[0] -= dv[0];
|
---|
| 328 | vv[1] -= dv[1];
|
---|
| 329 | vv[2] -= dv[2];
|
---|
| 330 |
|
---|
| 331 | // Clocks
|
---|
| 332 | // ------
|
---|
| 333 | double dtClk = tt - cc->tClk;
|
---|
| 334 |
|
---|
| 335 | xc[3] += cc->dClk + cc->dotDClk * dtClk + cc->dotDotDClk * dtClk * dtClk
|
---|
| 336 | + cc->hrClk;
|
---|
| 337 |
|
---|
| 338 | return success;
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | // Correct Time of Transmission
|
---|
| 342 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 343 | t_irc bncPPPclient::cmpToT(t_satData* satData) {
|
---|
| 344 |
|
---|
| 345 | double prange = satData->P3;
|
---|
| 346 | if (prange == 0.0) {
|
---|
| 347 | return failure;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | double clkSat = 0.0;
|
---|
| 351 | for (int ii = 1; ii <= 10; ii++) {
|
---|
| 352 |
|
---|
| 353 | bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
|
---|
| 354 |
|
---|
| 355 | ColumnVector xc(4);
|
---|
| 356 | ColumnVector vv(3);
|
---|
| 357 | if (getSatPos(ToT, satData->prn, xc, vv) != success) {
|
---|
| 358 | return failure;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | double clkSatOld = clkSat;
|
---|
| 362 | clkSat = xc(4);
|
---|
| 363 |
|
---|
| 364 | if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
|
---|
| 365 | satData->xx = xc.Rows(1,3);
|
---|
| 366 | satData->vv = vv;
|
---|
| 367 | satData->clk = clkSat * t_CST::c;
|
---|
| 368 | return success;
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | return failure;
|
---|
| 373 | }
|
---|
| 374 |
|
---|