[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"
|
---|
| 46 | #include "pppOptions.h"
|
---|
[6083] | 47 | #include "bncutils.h"
|
---|
| 48 | #include "bncconst.h"
|
---|
| 49 | #include "bncmodel.h"
|
---|
[6048] | 50 |
|
---|
| 51 | using namespace BNC_PPP;
|
---|
| 52 | using namespace std;
|
---|
| 53 |
|
---|
| 54 | // Global variable holding thread-specific pointers
|
---|
| 55 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 56 | t_pppClient* PPP_CLIENT = 0;
|
---|
[6048] | 57 |
|
---|
| 58 | // Static function returning thread-specific pointer
|
---|
| 59 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 60 | t_pppClient* t_pppClient::instance() {
|
---|
[6067] | 61 | return PPP_CLIENT;
|
---|
[6048] | 62 | }
|
---|
| 63 |
|
---|
| 64 | // Constructor
|
---|
[6083] | 65 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 66 | t_pppClient::t_pppClient(const t_pppOptions* opt) : bncEphUser(false) {
|
---|
[6083] | 67 |
|
---|
[6067] | 68 | _opt = new t_pppOptions(*opt);
|
---|
[6083] | 69 | _model = new bncModel(this);
|
---|
| 70 | _epoData = new t_epoData();
|
---|
[6087] | 71 | _log = new ostringstream();
|
---|
[6086] | 72 | _staID = QByteArray(_opt->_roverName.c_str());
|
---|
[6067] | 73 | PPP_CLIENT = this;
|
---|
[6048] | 74 | }
|
---|
| 75 |
|
---|
| 76 | // Destructor
|
---|
[6083] | 77 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 78 | t_pppClient::~t_pppClient() {
|
---|
[6083] | 79 | delete _model;
|
---|
| 80 | delete _epoData;
|
---|
[6048] | 81 | delete _opt;
|
---|
[6087] | 82 | delete _log;
|
---|
[6048] | 83 | }
|
---|
| 84 |
|
---|
[6083] | 85 | //
|
---|
| 86 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 87 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
---|
[6083] | 88 | QMutexLocker locker(&_mutex);
|
---|
| 89 |
|
---|
| 90 | // Convert and store observations
|
---|
| 91 | // ------------------------------
|
---|
| 92 | _epoData->clear();
|
---|
| 93 | for (unsigned ii = 0; ii < satObs.size(); ii++) {
|
---|
| 94 | const t_satObs* obs = satObs[ii];
|
---|
| 95 | t_satData* satData = new t_satData();
|
---|
| 96 |
|
---|
| 97 | if (_epoData->tt.undef()) {
|
---|
| 98 | _epoData->tt = obs->_time;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | satData->tt = obs->_time;
|
---|
| 102 | satData->prn = QString(obs->_prn.toString().c_str());
|
---|
| 103 | satData->slipFlag = false;
|
---|
| 104 | satData->P1 = 0.0;
|
---|
| 105 | satData->P2 = 0.0;
|
---|
| 106 | satData->P5 = 0.0;
|
---|
| 107 | satData->L1 = 0.0;
|
---|
| 108 | satData->L2 = 0.0;
|
---|
| 109 | satData->L5 = 0.0;
|
---|
| 110 | for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
|
---|
| 111 | t_frqObs* frqObs = obs->_obs[ifrq];
|
---|
| 112 | if (frqObs->_rnxType2ch[0] == '1') {
|
---|
| 113 | if (frqObs->_codeValid) satData->P1 = frqObs->_code;
|
---|
| 114 | if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
|
---|
| 115 | if (frqObs->_slip) satData->slipFlag = true;
|
---|
| 116 | }
|
---|
| 117 | else if (frqObs->_rnxType2ch[0] == '2') {
|
---|
| 118 | if (frqObs->_codeValid) satData->P2 = frqObs->_code;
|
---|
| 119 | if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
|
---|
| 120 | if (frqObs->_slip) satData->slipFlag = true;
|
---|
| 121 | }
|
---|
| 122 | else if (frqObs->_rnxType2ch[0] == '5') {
|
---|
| 123 | if (frqObs->_codeValid) satData->P5 = frqObs->_code;
|
---|
| 124 | if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
|
---|
| 125 | if (frqObs->_slip) satData->slipFlag = true;
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | putNewObs(satData);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | // Data Pre-Processing
|
---|
| 132 | // -------------------
|
---|
| 133 | QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
|
---|
| 134 | while (it.hasNext()) {
|
---|
| 135 | it.next();
|
---|
| 136 | QString prn = it.key();
|
---|
| 137 | t_satData* satData = it.value();
|
---|
| 138 |
|
---|
| 139 | if (cmpToT(satData) != success) {
|
---|
| 140 | delete satData;
|
---|
| 141 | it.remove();
|
---|
| 142 | continue;
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | // Filter Solution
|
---|
| 147 | // ---------------
|
---|
| 148 | if (_model->update(_epoData) == success) {
|
---|
| 149 | output->_error = false;
|
---|
| 150 | output->_epoTime = _model->time();
|
---|
| 151 | output->_xyzRover[0] = _model->x();
|
---|
| 152 | output->_xyzRover[1] = _model->y();
|
---|
| 153 | output->_xyzRover[2] = _model->z();
|
---|
| 154 | output->_numSat = 0;
|
---|
| 155 | output->_pDop = 0.0;
|
---|
| 156 | }
|
---|
| 157 | else {
|
---|
| 158 | output->_error = true;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | output->_log = LOG.str();
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | //
|
---|
| 165 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 166 | void t_pppClient::putNewObs(t_satData* satData) {
|
---|
[6083] | 167 |
|
---|
| 168 | // Set Observations GPS and Glonass
|
---|
| 169 | // --------------------------------
|
---|
| 170 | if (satData->system() == 'G' || satData->system() == 'R') {
|
---|
| 171 | if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
|
---|
| 172 | satData->L1 != 0.0 && satData->L2 != 0.0 ) {
|
---|
| 173 |
|
---|
| 174 | int channel = 0;
|
---|
| 175 | if (satData->system() == 'R') {
|
---|
| 176 | // cerr << "not yet implemented" << endl;
|
---|
| 177 | // exit(0);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
|
---|
| 181 | t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
|
---|
| 182 | double f1 = t_CST::freq(fType1, channel);
|
---|
| 183 | double f2 = t_CST::freq(fType2, channel);
|
---|
| 184 | double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
|
---|
| 185 | double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
|
---|
| 186 | satData->L1 = satData->L1 * t_CST::c / f1;
|
---|
| 187 | satData->L2 = satData->L2 * t_CST::c / f2;
|
---|
| 188 | satData->P3 = a1 * satData->P1 + a2 * satData->P2;
|
---|
| 189 | satData->L3 = a1 * satData->L1 + a2 * satData->L2;
|
---|
| 190 | satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
|
---|
| 191 | _epoData->satData[satData->prn] = satData;
|
---|
| 192 | }
|
---|
| 193 | else {
|
---|
| 194 | delete satData;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | // Set Observations Galileo
|
---|
| 199 | // ------------------------
|
---|
| 200 | else if (satData->system() == 'E') {
|
---|
| 201 | if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
|
---|
| 202 | satData->L1 != 0.0 && satData->L5 != 0.0 ) {
|
---|
| 203 | double f1 = t_CST::freq(t_frequency::E1, 0);
|
---|
| 204 | double f5 = t_CST::freq(t_frequency::E5, 0);
|
---|
| 205 | double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
|
---|
| 206 | double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
|
---|
| 207 | satData->L1 = satData->L1 * t_CST::c / f1;
|
---|
| 208 | satData->L5 = satData->L5 * t_CST::c / f5;
|
---|
| 209 | satData->P3 = a1 * satData->P1 + a5 * satData->P5;
|
---|
| 210 | satData->L3 = a1 * satData->L1 + a5 * satData->L5;
|
---|
| 211 | satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
|
---|
| 212 | _epoData->satData[satData->prn] = satData;
|
---|
| 213 | }
|
---|
| 214 | else {
|
---|
| 215 | delete satData;
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[6048] | 220 | //
|
---|
[6083] | 221 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 222 | void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
|
---|
[6083] | 223 | QMutexLocker locker(&_mutex);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | //
|
---|
| 227 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 228 | void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
|
---|
[6083] | 229 | QMutexLocker locker(&_mutex);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | //
|
---|
[6048] | 233 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6086] | 234 | void t_pppClient::putBiases(const std::vector<t_satBias*>& /* satBias */) {
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | //
|
---|
| 238 | //////////////////////////////////////////////////////////////////////////////
|
---|
[6048] | 239 | void t_pppClient::putEphemeris(const t_eph* eph) {
|
---|
[6069] | 240 | const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
|
---|
| 241 | const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
|
---|
| 242 | const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
|
---|
| 243 | if (ephGPS) {
|
---|
[6083] | 244 | putNewEph(new t_ephGPS(*ephGPS));
|
---|
[6069] | 245 | }
|
---|
| 246 | else if (ephGlo) {
|
---|
[6083] | 247 | putNewEph(new t_ephGlo(*ephGlo));
|
---|
[6069] | 248 | }
|
---|
| 249 | else if (ephGal) {
|
---|
[6083] | 250 | putNewEph(new t_ephGal(*ephGal));
|
---|
[6069] | 251 | }
|
---|
[6048] | 252 | }
|
---|
| 253 |
|
---|
[6083] | 254 | // Satellite Position
|
---|
| 255 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 256 | t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
|
---|
[6083] | 257 | ColumnVector& xc, ColumnVector& vv) {
|
---|
| 258 | if (_eph.contains(prn)) {
|
---|
| 259 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 260 | t_eph* ePrev = _eph.value(prn)->prev;
|
---|
| 261 | if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
|
---|
| 262 | return success;
|
---|
| 263 | }
|
---|
| 264 | else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
|
---|
| 265 | return success;
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 | return failure;
|
---|
[6048] | 269 | }
|
---|
| 270 |
|
---|
[6083] | 271 | // Correct Time of Transmission
|
---|
| 272 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6085] | 273 | t_irc t_pppClient::cmpToT(t_satData* satData) {
|
---|
[6048] | 274 |
|
---|
[6083] | 275 | double prange = satData->P3;
|
---|
| 276 | if (prange == 0.0) {
|
---|
| 277 | return failure;
|
---|
| 278 | }
|
---|
[6048] | 279 |
|
---|
[6083] | 280 | double clkSat = 0.0;
|
---|
| 281 | for (int ii = 1; ii <= 10; ii++) {
|
---|
| 282 |
|
---|
| 283 | bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
|
---|
| 284 |
|
---|
| 285 | ColumnVector xc(4);
|
---|
| 286 | ColumnVector vv(3);
|
---|
| 287 | if (getSatPos(ToT, satData->prn, xc, vv) != success) {
|
---|
| 288 | return failure;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | double clkSatOld = clkSat;
|
---|
| 292 | clkSat = xc(4);
|
---|
| 293 |
|
---|
| 294 | if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
|
---|
| 295 | satData->xx = xc.Rows(1,3);
|
---|
| 296 | satData->vv = vv;
|
---|
| 297 | satData->clk = clkSat * t_CST::c;
|
---|
| 298 | return success;
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | return failure;
|
---|
[6048] | 303 | }
|
---|
| 304 |
|
---|