[6048] | 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 | *
|
---|
[6085] | 29 | * Class: t_pppClient
|
---|
[6048] | 30 | *
|
---|
[6083] | 31 | * Purpose: Precise Point Positioning
|
---|
[6048] | 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
[6083] | 35 | * Created: 21-Nov-2009
|
---|
[6048] | 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[6083] | 41 | #include <newmatio.h>
|
---|
[6048] | 42 | #include <iomanip>
|
---|
[6083] | 43 | #include <sstream>
|
---|
[6048] | 44 |
|
---|
[6086] | 45 | #include "pppClient.h"
|
---|
[6093] | 46 | #include "pppFilter.h"
|
---|
[6086] | 47 | #include "pppOptions.h"
|
---|
[6083] | 48 | #include "bncutils.h"
|
---|
| 49 | #include "bncconst.h"
|
---|
[6048] | 50 |
|
---|
| 51 | using namespace BNC_PPP;
|
---|
| 52 | using namespace std;
|
---|
| 53 |
|
---|
| 54 | // Global variable holding thread-specific pointers
|
---|
| 55 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6088] | 56 | QThreadStorage<t_pppClient*> CLIENTS;
|
---|
[6048] | 57 |
|
---|
| 58 | // Static function returning thread-specific pointer
|
---|
| 59 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 60 | t_pppClient* t_pppClient::instance() {
|
---|
[6088] | 61 | return CLIENTS.localData();
|
---|
[6048] | 62 | }
|
---|
| 63 |
|
---|
| 64 | // Constructor
|
---|
[6083] | 65 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 66 | t_pppClient::t_pppClient(const t_pppOptions* opt) : bncEphUser(false) {
|
---|
[6083] | 67 |
|
---|
[6093] | 68 | _opt = new t_pppOptions(*opt);
|
---|
| 69 | _filter = new t_pppFilter(this);
|
---|
| 70 | _epoData = new t_epoData();
|
---|
| 71 | _log = new ostringstream();
|
---|
| 72 | _staID = QByteArray(_opt->_roverName.c_str());
|
---|
[6088] | 73 |
|
---|
| 74 | CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
|
---|
[6048] | 75 | }
|
---|
| 76 |
|
---|
| 77 | // Destructor
|
---|
[6083] | 78 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 79 | t_pppClient::~t_pppClient() {
|
---|
[6093] | 80 | delete _filter;
|
---|
[6083] | 81 | delete _epoData;
|
---|
[6048] | 82 | delete _opt;
|
---|
[6087] | 83 | delete _log;
|
---|
[6048] | 84 | }
|
---|
| 85 |
|
---|
[6083] | 86 | //
|
---|
| 87 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 88 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
---|
[6083] | 89 | QMutexLocker locker(&_mutex);
|
---|
| 90 |
|
---|
| 91 | // Convert and store observations
|
---|
| 92 | // ------------------------------
|
---|
| 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();
|
---|
| 97 |
|
---|
| 98 | if (_epoData->tt.undef()) {
|
---|
| 99 | _epoData->tt = obs->_time;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 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);
|
---|
| 130 | }
|
---|
| 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 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | // Filter Solution
|
---|
| 148 | // ---------------
|
---|
[6093] | 149 | if (_filter->update(_epoData) == success) {
|
---|
[6083] | 150 | output->_error = false;
|
---|
[6093] | 151 | output->_epoTime = _filter->time();
|
---|
| 152 | output->_xyzRover[0] = _filter->x();
|
---|
| 153 | output->_xyzRover[1] = _filter->y();
|
---|
| 154 | output->_xyzRover[2] = _filter->z();
|
---|
[6083] | 155 | output->_numSat = 0;
|
---|
| 156 | output->_pDop = 0.0;
|
---|
| 157 | }
|
---|
| 158 | else {
|
---|
| 159 | output->_error = true;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[6098] | 162 | output->_log = _log->str();
|
---|
| 163 | delete _log; _log = new ostringstream();
|
---|
[6083] | 164 | }
|
---|
| 165 |
|
---|
| 166 | //
|
---|
| 167 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 168 | void t_pppClient::putNewObs(t_satData* satData) {
|
---|
[6083] | 169 |
|
---|
| 170 | // Set Observations GPS and Glonass
|
---|
| 171 | // --------------------------------
|
---|
| 172 | if (satData->system() == 'G' || satData->system() == 'R') {
|
---|
| 173 | if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
|
---|
| 174 | satData->L1 != 0.0 && satData->L2 != 0.0 ) {
|
---|
| 175 |
|
---|
| 176 | int channel = 0;
|
---|
| 177 | if (satData->system() == 'R') {
|
---|
[6096] | 178 | if (_eph.contains(satData->prn)) {
|
---|
| 179 | t_eph* eLast =_eph.value(satData->prn)->last;
|
---|
| 180 | channel = eLast->slotNum();
|
---|
| 181 | }
|
---|
| 182 | else {
|
---|
| 183 | delete satData;
|
---|
| 184 | return;
|
---|
| 185 | }
|
---|
[6083] | 186 | }
|
---|
| 187 |
|
---|
| 188 | t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
|
---|
| 189 | t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
|
---|
| 190 | double f1 = t_CST::freq(fType1, channel);
|
---|
| 191 | double f2 = t_CST::freq(fType2, channel);
|
---|
| 192 | double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
|
---|
| 193 | double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
|
---|
| 194 | satData->L1 = satData->L1 * t_CST::c / f1;
|
---|
| 195 | satData->L2 = satData->L2 * t_CST::c / f2;
|
---|
| 196 | satData->P3 = a1 * satData->P1 + a2 * satData->P2;
|
---|
| 197 | satData->L3 = a1 * satData->L1 + a2 * satData->L2;
|
---|
| 198 | satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
|
---|
| 199 | _epoData->satData[satData->prn] = satData;
|
---|
| 200 | }
|
---|
| 201 | else {
|
---|
| 202 | delete satData;
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | // Set Observations Galileo
|
---|
| 207 | // ------------------------
|
---|
| 208 | else if (satData->system() == 'E') {
|
---|
| 209 | if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
|
---|
| 210 | satData->L1 != 0.0 && satData->L5 != 0.0 ) {
|
---|
| 211 | double f1 = t_CST::freq(t_frequency::E1, 0);
|
---|
| 212 | double f5 = t_CST::freq(t_frequency::E5, 0);
|
---|
| 213 | double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
|
---|
| 214 | double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
|
---|
| 215 | satData->L1 = satData->L1 * t_CST::c / f1;
|
---|
| 216 | satData->L5 = satData->L5 * t_CST::c / f5;
|
---|
| 217 | satData->P3 = a1 * satData->P1 + a5 * satData->P5;
|
---|
| 218 | satData->L3 = a1 * satData->L1 + a5 * satData->L5;
|
---|
| 219 | satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
|
---|
| 220 | _epoData->satData[satData->prn] = satData;
|
---|
| 221 | }
|
---|
| 222 | else {
|
---|
| 223 | delete satData;
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[6048] | 228 | //
|
---|
[6083] | 229 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 230 | void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
|
---|
[6083] | 231 | QMutexLocker locker(&_mutex);
|
---|
[6097] | 232 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
---|
| 233 | QString prn = QString(corr[ii]->_prn.toString().c_str());
|
---|
| 234 | if (_eph.contains(prn)) {
|
---|
| 235 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 236 | t_eph* ePrev = _eph.value(prn)->prev;
|
---|
| 237 | if (eLast && eLast->IOD() == corr[ii]->_iod) {
|
---|
| 238 | eLast->setOrbCorr(corr[ii]);
|
---|
| 239 | }
|
---|
| 240 | else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
|
---|
| 241 | ePrev->setOrbCorr(corr[ii]);
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
[6083] | 245 | }
|
---|
| 246 |
|
---|
| 247 | //
|
---|
| 248 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 249 | void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
|
---|
[6083] | 250 | QMutexLocker locker(&_mutex);
|
---|
[6097] | 251 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
---|
| 252 | QString prn = QString(corr[ii]->_prn.toString().c_str());
|
---|
| 253 | if (_eph.contains(prn)) {
|
---|
| 254 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 255 | t_eph* ePrev = _eph.value(prn)->prev;
|
---|
| 256 | if (eLast && eLast->IOD() == corr[ii]->_iod) {
|
---|
| 257 | eLast->setClkCorr(corr[ii]);
|
---|
| 258 | }
|
---|
| 259 | else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
|
---|
| 260 | ePrev->setClkCorr(corr[ii]);
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
[6083] | 264 | }
|
---|
| 265 |
|
---|
| 266 | //
|
---|
[6048] | 267 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6086] | 268 | void t_pppClient::putBiases(const std::vector<t_satBias*>& /* satBias */) {
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | //
|
---|
| 272 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6048] | 273 | void t_pppClient::putEphemeris(const t_eph* eph) {
|
---|
[6069] | 274 | const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
|
---|
| 275 | const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
|
---|
| 276 | const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
|
---|
| 277 | if (ephGPS) {
|
---|
[6083] | 278 | putNewEph(new t_ephGPS(*ephGPS));
|
---|
[6069] | 279 | }
|
---|
| 280 | else if (ephGlo) {
|
---|
[6083] | 281 | putNewEph(new t_ephGlo(*ephGlo));
|
---|
[6069] | 282 | }
|
---|
| 283 | else if (ephGal) {
|
---|
[6083] | 284 | putNewEph(new t_ephGal(*ephGal));
|
---|
[6069] | 285 | }
|
---|
[6048] | 286 | }
|
---|
| 287 |
|
---|
[6083] | 288 | // Satellite Position
|
---|
| 289 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 290 | t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
|
---|
[6083] | 291 | ColumnVector& xc, ColumnVector& vv) {
|
---|
| 292 | if (_eph.contains(prn)) {
|
---|
| 293 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 294 | t_eph* ePrev = _eph.value(prn)->prev;
|
---|
| 295 | if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
|
---|
| 296 | return success;
|
---|
| 297 | }
|
---|
| 298 | else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
|
---|
| 299 | return success;
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | return failure;
|
---|
[6048] | 303 | }
|
---|
| 304 |
|
---|
[6083] | 305 | // Correct Time of Transmission
|
---|
| 306 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 307 | t_irc t_pppClient::cmpToT(t_satData* satData) {
|
---|
[6048] | 308 |
|
---|
[6083] | 309 | double prange = satData->P3;
|
---|
| 310 | if (prange == 0.0) {
|
---|
| 311 | return failure;
|
---|
| 312 | }
|
---|
[6048] | 313 |
|
---|
[6083] | 314 | double clkSat = 0.0;
|
---|
| 315 | for (int ii = 1; ii <= 10; ii++) {
|
---|
| 316 |
|
---|
| 317 | bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
|
---|
| 318 |
|
---|
| 319 | ColumnVector xc(4);
|
---|
| 320 | ColumnVector vv(3);
|
---|
| 321 | if (getSatPos(ToT, satData->prn, xc, vv) != success) {
|
---|
| 322 | return failure;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | double clkSatOld = clkSat;
|
---|
| 326 | clkSat = xc(4);
|
---|
| 327 |
|
---|
| 328 | if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
|
---|
| 329 | satData->xx = xc.Rows(1,3);
|
---|
| 330 | satData->vv = vv;
|
---|
| 331 | satData->clk = clkSat * t_CST::c;
|
---|
| 332 | return success;
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | return failure;
|
---|
[6048] | 337 | }
|
---|
| 338 |
|
---|