| 1 | /* -------------------------------------------------------------------------
|
|---|
| 2 | * BKG NTRIP Client
|
|---|
| 3 | * -------------------------------------------------------------------------
|
|---|
| 4 | *
|
|---|
| 5 | * Class: t_pppClient
|
|---|
| 6 | *
|
|---|
| 7 | * Purpose: PPP Client processing starts here
|
|---|
| 8 | *
|
|---|
| 9 | * Author: L. Mervart
|
|---|
| 10 | *
|
|---|
| 11 | * Created: 29-Jul-2014
|
|---|
| 12 | *
|
|---|
| 13 | * Changes:
|
|---|
| 14 | *
|
|---|
| 15 | * -----------------------------------------------------------------------*/
|
|---|
| 16 |
|
|---|
| 17 | #include <QThreadStorage>
|
|---|
| 18 |
|
|---|
| 19 | #include <iostream>
|
|---|
| 20 | #include <iomanip>
|
|---|
| 21 | #include <cmath>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <string.h>
|
|---|
| 24 | #include <stdexcept>
|
|---|
| 25 |
|
|---|
| 26 | #include "pppClient.h"
|
|---|
| 27 | #include "pppEphPool.h"
|
|---|
| 28 | #include "pppObsPool.h"
|
|---|
| 29 | #include "bncconst.h"
|
|---|
| 30 | #include "bncutils.h"
|
|---|
| 31 | #include "pppStation.h"
|
|---|
| 32 | #include "bncantex.h"
|
|---|
| 33 | #include "pppFilter.h"
|
|---|
| 34 |
|
|---|
| 35 | using namespace BNC_PPP;
|
|---|
| 36 | using namespace std;
|
|---|
| 37 |
|
|---|
| 38 | // Global variable holding thread-specific pointers
|
|---|
| 39 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 40 | QThreadStorage<t_pppClient*> CLIENTS;
|
|---|
| 41 |
|
|---|
| 42 | // Static function returning thread-specific pointer
|
|---|
| 43 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 44 | t_pppClient* t_pppClient::instance() {
|
|---|
| 45 | return CLIENTS.localData();
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | // Constructor
|
|---|
| 49 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 50 | t_pppClient::t_pppClient(const t_pppOptions* opt) {
|
|---|
| 51 | _running = true;
|
|---|
| 52 | _output = 0;
|
|---|
| 53 | _opt = new t_pppOptions(*opt);
|
|---|
| 54 | _log = new ostringstream();
|
|---|
| 55 | _ephPool = new t_pppEphPool();
|
|---|
| 56 | _obsPool = new t_pppObsPool();
|
|---|
| 57 | _staRover = new t_pppStation();
|
|---|
| 58 | _filter = new t_pppFilter();
|
|---|
| 59 | _tides = new t_tides();
|
|---|
| 60 | _antex = 0;
|
|---|
| 61 | if (!_opt->_antexFileName.empty()) {
|
|---|
| 62 | _antex = new bncAntex(_opt->_antexFileName.c_str());
|
|---|
| 63 | }
|
|---|
| 64 | if (!_opt->_blqFileName.empty()) {
|
|---|
| 65 | if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
|
|---|
| 66 | //_tides->printAllBlqSets();
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | // Destructor
|
|---|
| 73 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 74 | t_pppClient::~t_pppClient() {
|
|---|
| 75 | _running = false;
|
|---|
| 76 | delete _log;
|
|---|
| 77 | delete _opt;
|
|---|
| 78 | delete _ephPool;
|
|---|
| 79 | delete _obsPool;
|
|---|
| 80 | delete _staRover;
|
|---|
| 81 | if (_antex) {
|
|---|
| 82 | delete _antex;
|
|---|
| 83 | }
|
|---|
| 84 | delete _filter;
|
|---|
| 85 | delete _tides;
|
|---|
| 86 | clearObs();
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | //
|
|---|
| 90 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 91 | void t_pppClient::putEphemeris(const t_eph* eph) {
|
|---|
| 92 | const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
|
|---|
| 93 | const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
|
|---|
| 94 | const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
|
|---|
| 95 | const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
|
|---|
| 96 | if (ephGPS) {
|
|---|
| 97 | _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
|
|---|
| 98 | }
|
|---|
| 99 | else if (ephGlo) {
|
|---|
| 100 | _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
|
|---|
| 101 | }
|
|---|
| 102 | else if (ephGal) {
|
|---|
| 103 | _ephPool->putEphemeris(new t_ephGal(*ephGal));
|
|---|
| 104 | }
|
|---|
| 105 | else if (ephBDS) {
|
|---|
| 106 | _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | //
|
|---|
| 111 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 112 | void t_pppClient::putTec(const t_vTec* vTec) {
|
|---|
| 113 | _obsPool->putTec(new t_vTec(*vTec));
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | //
|
|---|
| 117 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 118 | void t_pppClient::putMetaData(const t_metaData* metaData) {
|
|---|
| 119 | _obsPool->putMetaData(new t_metaData(*metaData));
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | //
|
|---|
| 123 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 124 | void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
|
|---|
| 125 | if (OPT->_logMode == t_pppOptions::normal && corr.size() > 0) {
|
|---|
| 126 | LOG << "orbCorrections " << string(corr[0]->_time) << ' ' << corr.size() << endl;
|
|---|
| 127 | }
|
|---|
| 128 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
|---|
| 129 | _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | //
|
|---|
| 134 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 135 | void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
|
|---|
| 136 | if (OPT->_logMode == t_pppOptions::normal && corr.size() > 0) {
|
|---|
| 137 | LOG << "clkCorrections " << string(corr[0]->_time) << ' ' << corr.size() << endl;
|
|---|
| 138 | }
|
|---|
| 139 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
|---|
| 140 | _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | //
|
|---|
| 145 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 146 | void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
|
|---|
| 147 | if (OPT->_logMode == t_pppOptions::normal && biases.size() > 0) {
|
|---|
| 148 | LOG << "codeBiases " << string(biases[0]->_time) << ' ' << biases.size() << endl;
|
|---|
| 149 | }
|
|---|
| 150 | set<char> systems;
|
|---|
| 151 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
|---|
| 152 | t_satCodeBias* newBias = new t_satCodeBias(*biases[ii]);
|
|---|
| 153 | char sys = newBias->_prn.system();
|
|---|
| 154 | if (systems.find(sys) == systems.end()) {
|
|---|
| 155 | _obsPool->clearCodeBiases(sys);
|
|---|
| 156 | systems.insert(sys);
|
|---|
| 157 | }
|
|---|
| 158 | _obsPool->putCodeBias(newBias);
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | //
|
|---|
| 163 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 164 | void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
|
|---|
| 165 | if (OPT->_logMode == t_pppOptions::normal && biases.size() > 0) {
|
|---|
| 166 | LOG << "phaseBiases " << string(biases[0]->_time) << ' ' << biases.size() << endl;
|
|---|
| 167 | }
|
|---|
| 168 | set<char> systems;
|
|---|
| 169 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
|---|
| 170 | t_satPhaseBias* newBias = new t_satPhaseBias(*biases[ii]);
|
|---|
| 171 | char sys = newBias->_prn.system();
|
|---|
| 172 | if (systems.find(sys) == systems.end()) {
|
|---|
| 173 | _obsPool->clearPhaseBiases(sys);
|
|---|
| 174 | systems.insert(sys);
|
|---|
| 175 | }
|
|---|
| 176 | _obsPool->putPhaseBias(newBias);
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | //
|
|---|
| 181 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 182 | t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
|
|---|
| 183 | vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
|
|---|
| 184 |
|
|---|
| 185 | // Default
|
|---|
| 186 | // -------
|
|---|
| 187 | epoTime.reset();
|
|---|
| 188 | clearObs();
|
|---|
| 189 |
|
|---|
| 190 | // Create vector of valid observations
|
|---|
| 191 | // -----------------------------------
|
|---|
| 192 | for (unsigned ii = 0; ii < satObs.size(); ii++) {
|
|---|
| 193 | char sys = satObs[ii]->_prn.system();
|
|---|
| 194 | if (_opt->useSystem(sys)) {
|
|---|
| 195 | t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
|
|---|
| 196 | if (pppSatObs->isValid()) {
|
|---|
| 197 | obsVector.push_back(pppSatObs);
|
|---|
| 198 | }
|
|---|
| 199 | else {
|
|---|
| 200 | delete pppSatObs;
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | // Check whether data are synchronized, compute epoTime
|
|---|
| 206 | // ----------------------------------------------------
|
|---|
| 207 | const double MAXSYNC = 0.05; // synchronization limit
|
|---|
| 208 | double meanDt = 0.0;
|
|---|
| 209 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 210 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 211 | if (epoTime.undef()) {
|
|---|
| 212 | epoTime = satObs->time();
|
|---|
| 213 | }
|
|---|
| 214 | else {
|
|---|
| 215 | double dt = satObs->time() - epoTime;
|
|---|
| 216 | if (fabs(dt) > MAXSYNC) {
|
|---|
| 217 | LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
|
|---|
| 218 | return failure;
|
|---|
| 219 | }
|
|---|
| 220 | meanDt += dt;
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | if (obsVector.size() > 0) {
|
|---|
| 225 | epoTime += meanDt / obsVector.size();
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | return success;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | //
|
|---|
| 232 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 233 | bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
|
|---|
| 234 |
|
|---|
| 235 | bool pseudoObsIono = false;
|
|---|
| 236 |
|
|---|
| 237 | if (_opt->_pseudoObsIono) {
|
|---|
| 238 |
|
|---|
| 239 | // Select reference satellite per system: keep the current one if still
|
|---|
| 240 | // visible; only switch to highest elevation when the current one disappears
|
|---|
| 241 | // -------------------------------------------------------------------------
|
|---|
| 242 | map<char, t_pppSatObs*> refSatMap;
|
|---|
| 243 | map<char, t_pppSatObs*> bestEleMap;
|
|---|
| 244 | for (t_pppSatObs* satObs : obsVector) {
|
|---|
| 245 | satObs->resetReference();
|
|---|
| 246 | double stec = satObs->getIonoCodeDelay(t_frequency::G1);
|
|---|
| 247 | if (stec == 0.0) continue;
|
|---|
| 248 | char sys = satObs->prn().system();
|
|---|
| 249 | if (!bestEleMap.count(sys) || satObs->eleSat() > bestEleMap[sys]->eleSat()) {
|
|---|
| 250 | bestEleMap[sys] = satObs;
|
|---|
| 251 | }
|
|---|
| 252 | if (_refPrnMap.count(sys) && satObs->prn() == _refPrnMap[sys]) {
|
|---|
| 253 | refSatMap[sys] = satObs;
|
|---|
| 254 | }
|
|---|
| 255 | }
|
|---|
| 256 | for (auto& kv : bestEleMap) {
|
|---|
| 257 | if (!refSatMap.count(kv.first)) {
|
|---|
| 258 | refSatMap[kv.first] = kv.second;
|
|---|
| 259 | }
|
|---|
| 260 | }
|
|---|
| 261 | for (auto& kv : refSatMap) {
|
|---|
| 262 | _refPrnMap[kv.first] = kv.second->prn();
|
|---|
| 263 | kv.second->setAsReference();
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | if (bestEleMap.empty()) {
|
|---|
| 267 | LOG << "GIM pseudo-obs unavailable: no valid STEC (vTec data missing?)" << endl;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | // Set STEC pseudo-observations (single-differenced vs reference satellite)
|
|---|
| 271 | // -------------------------------------------------------------------------
|
|---|
| 272 | int nGIM = 0;
|
|---|
| 273 | for (t_pppSatObs* satObs : obsVector) {
|
|---|
| 274 | char sys = satObs->prn().system();
|
|---|
| 275 | double stecRefSat = refSatMap.count(sys)
|
|---|
| 276 | ? refSatMap[sys]->getIonoCodeDelay(t_frequency::G1)
|
|---|
| 277 | : 0.0;
|
|---|
| 278 | if (satObs->setPseudoObsIono(t_frequency::G1, stecRefSat)) {
|
|---|
| 279 | pseudoObsIono = true;
|
|---|
| 280 | nGIM++;
|
|---|
| 281 | }
|
|---|
| 282 | }
|
|---|
| 283 | if (nGIM > 0) {
|
|---|
| 284 | LOG << "GIM pseudo-obs: " << nGIM << " satellites, ref:";
|
|---|
| 285 | for (auto& kv : refSatMap) {
|
|---|
| 286 | LOG << ' ' << kv.second->prn().toString();
|
|---|
| 287 | }
|
|---|
| 288 | LOG << endl;
|
|---|
| 289 | }
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | if (OPT->_logMode == t_pppOptions::all) {
|
|---|
| 293 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 294 | while (it != obsVector.end()) {
|
|---|
| 295 | t_pppSatObs* satObs = *it;
|
|---|
| 296 | satObs->printObsMinusComputed();
|
|---|
| 297 | it++;
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 | return pseudoObsIono;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | // Compute the Bancroft position, check for blunders
|
|---|
| 304 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 305 | t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
|
|---|
| 306 | vector<t_pppSatObs*>& obsVector,
|
|---|
| 307 | ColumnVector& xyzc, bool print) {
|
|---|
| 308 |
|
|---|
| 309 | int numBancroft = obsVector.size();
|
|---|
| 310 |
|
|---|
| 311 | while (_running) {
|
|---|
| 312 | Matrix BB(numBancroft, 4);
|
|---|
| 313 | int iObs = -1;
|
|---|
| 314 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 315 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 316 | t_lc LC = satObs->rangeLC();
|
|---|
| 317 | if ( satObs->isValid(LC) &&
|
|---|
| 318 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
|---|
| 319 | ++iObs;
|
|---|
| 320 | BB[iObs][0] = satObs->xc()[0];
|
|---|
| 321 | BB[iObs][1] = satObs->xc()[1];
|
|---|
| 322 | BB[iObs][2] = satObs->xc()[2];
|
|---|
| 323 | BB[iObs][3] = satObs->obsValue(LC) - satObs->cmpValueForBanc(LC);
|
|---|
| 324 | }
|
|---|
| 325 | }
|
|---|
| 326 | if (iObs + 1 < _opt->_minObs) {
|
|---|
| 327 | LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
|
|---|
| 328 | return failure;
|
|---|
| 329 | }
|
|---|
| 330 | BB = BB.Rows(1,iObs+1);
|
|---|
| 331 | if (bancroft(BB, xyzc) != success) {
|
|---|
| 332 | return failure;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | xyzc[3] /= t_CST::c;
|
|---|
| 336 |
|
|---|
| 337 | // Check Blunders
|
|---|
| 338 | // --------------
|
|---|
| 339 | const double BLUNDER = 1500.0;
|
|---|
| 340 | double maxRes = 0.0;
|
|---|
| 341 | unsigned maxResIndex = 0;
|
|---|
| 342 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 343 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 344 | t_lc LC = satObs->rangeLC();
|
|---|
| 345 | if (satObs->isValid(LC) &&
|
|---|
| 346 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
|---|
| 347 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
|---|
| 348 | double res = rr.NormFrobenius() - satObs->obsValue(LC)
|
|---|
| 349 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
|---|
| 350 | if (fabs(res) > maxRes) {
|
|---|
| 351 | maxRes = fabs(res);
|
|---|
| 352 | maxResIndex = ii;
|
|---|
| 353 | }
|
|---|
| 354 | }
|
|---|
| 355 | }
|
|---|
| 356 | if (maxRes < BLUNDER) {
|
|---|
| 357 | if (print) {
|
|---|
| 358 | LOG.setf(ios::fixed);
|
|---|
| 359 | LOG << "\nPPP of Epoch ";
|
|---|
| 360 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
|---|
| 361 | LOG << " using " << _opt->_corrMount;
|
|---|
| 362 | LOG << "\n---------------------------------------------------------------\n";
|
|---|
| 363 | LOG << string(epoTime) << " BANCROFT: "
|
|---|
| 364 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
|---|
| 365 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
|---|
| 366 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
|---|
| 367 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
|---|
| 368 | }
|
|---|
| 369 | break;
|
|---|
| 370 | }
|
|---|
| 371 | else {
|
|---|
| 372 | t_pppSatObs* satObs = obsVector.at(maxResIndex);
|
|---|
| 373 | LOG << "t_pppClient::cmpBancroft Outlier " << satObs->prn().toString()
|
|---|
| 374 | << " " << maxRes << endl;
|
|---|
| 375 | delete satObs;
|
|---|
| 376 | obsVector.erase(obsVector.begin() + maxResIndex);
|
|---|
| 377 | }
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | return success;
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | //
|
|---|
| 384 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 385 | void t_pppClient::initOutput(t_output* output) {
|
|---|
| 386 | _output = output;
|
|---|
| 387 | _output->_numSat = 0;
|
|---|
| 388 | _output->_hDop = 0.0;
|
|---|
| 389 | _output->_error = false;
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | //
|
|---|
| 393 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 394 | void t_pppClient::clearObs() {
|
|---|
| 395 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
|---|
| 396 | delete _obsRover.at(ii);
|
|---|
| 397 | }
|
|---|
| 398 | _obsRover.clear();
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | //
|
|---|
| 402 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 403 | void t_pppClient::finish(t_irc irc, int ind) {
|
|---|
| 404 | #ifdef BNC_DEBUG_PPP
|
|---|
| 405 | LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
|
|---|
| 406 | #endif
|
|---|
| 407 |
|
|---|
| 408 | clearObs();
|
|---|
| 409 |
|
|---|
| 410 | _output->_epoTime = _epoTimeRover;
|
|---|
| 411 |
|
|---|
| 412 | if (irc == success) {
|
|---|
| 413 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
|---|
| 414 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
|---|
| 415 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
|---|
| 416 |
|
|---|
| 417 | xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
|
|---|
| 418 |
|
|---|
| 419 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
|---|
| 420 |
|
|---|
| 421 | _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
|
|---|
| 422 | _output->_trp = _filter->trp();
|
|---|
| 423 | _output->_trpStdev = _filter->trpStdev();
|
|---|
| 424 |
|
|---|
| 425 | _output->_fixRatio = _filter->fixRatio();
|
|---|
| 426 |
|
|---|
| 427 | _output->_numSat = _filter->numSat();
|
|---|
| 428 | _output->_hDop = _filter->HDOP();
|
|---|
| 429 | _output->_error = false;
|
|---|
| 430 | }
|
|---|
| 431 | else {
|
|---|
| 432 | _output->_error = true;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | _output->_log = _log->str();
|
|---|
| 436 | delete _log; _log = new ostringstream();
|
|---|
| 437 |
|
|---|
| 438 | return;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | //
|
|---|
| 442 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 443 | t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
|
|---|
| 444 | vector<t_pppSatObs*>& obsVector) {
|
|---|
| 445 | bncTime time;
|
|---|
| 446 | time = _epoTimeRover;
|
|---|
| 447 | station->setName(_opt->_roverName);
|
|---|
| 448 | station->setAntName(_opt->_antNameRover);
|
|---|
| 449 | station->setEpochTime(time);
|
|---|
| 450 |
|
|---|
| 451 | if (_opt->xyzAprRoverSet()) {
|
|---|
| 452 | if (_opt->_refEpochRover != 0.0) {
|
|---|
| 453 | double dt = decimalYear(time) - _opt->_refEpochRover;
|
|---|
| 454 | station->setXyzApr(_opt->_xyzAprRover + dt * _opt->_velRover);
|
|---|
| 455 | }
|
|---|
| 456 | else {
|
|---|
| 457 | station->setXyzApr(_opt->_xyzAprRover);
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 | else {
|
|---|
| 461 | station->setXyzApr(xyzc.Rows(1,3));
|
|---|
| 462 | }
|
|---|
| 463 | station->setNeuEcc(_opt->_neuEccRover);
|
|---|
| 464 |
|
|---|
| 465 | // Receiver Clock
|
|---|
| 466 | // --------------
|
|---|
| 467 | station->setDClk(xyzc[3]);
|
|---|
| 468 |
|
|---|
| 469 | // Tides
|
|---|
| 470 | // -----
|
|---|
| 471 | // RTCM-SSR Metadata (model correction type 3 = solid earth tides) tells us
|
|---|
| 472 | // whether - and with which model - the correction stream's generation
|
|---|
| 473 | // system already accounted for solid earth tides. To stay consistent with
|
|---|
| 474 | // the orbit/clock corrections, mirror that choice here: skip our own
|
|---|
| 475 | // correction if the provider applied none, apply our default model if the
|
|---|
| 476 | // provider used its own default, and fall back to our default (with a
|
|---|
| 477 | // warning) if the provider used some other, unsupported model - we have no
|
|---|
| 478 | // way to reproduce an unknown model exactly. Absent any Metadata message
|
|---|
| 479 | // (e.g. RTNET or older streams), keep today's unconditional behavior.
|
|---|
| 480 | bool applyEarthTide = true;
|
|---|
| 481 | const t_metaData* metaData = _obsPool->metaData();
|
|---|
| 482 | if (metaData) {
|
|---|
| 483 | for (unsigned ii = 0; ii < metaData->_entries.size(); ii++) {
|
|---|
| 484 | const t_metaDataEntry& entry = metaData->_entries[ii];
|
|---|
| 485 | if (entry._typeIndicator == 3) { // solid earth tides
|
|---|
| 486 | if (!entry._applicationIndicator) {
|
|---|
| 487 | applyEarthTide = false;
|
|---|
| 488 | }
|
|---|
| 489 | else if (entry._nonDefaultIndicator) {
|
|---|
| 490 | LOG << "WARNING: SSR Metadata signals a non-default solid earth "
|
|---|
| 491 | << "tide model (identifier " << entry._nonDefaultIdentifier
|
|---|
| 492 | << "); applying BNC's default model anyway, results may be "
|
|---|
| 493 | << "inconsistent" << endl;
|
|---|
| 494 | }
|
|---|
| 495 | break;
|
|---|
| 496 | }
|
|---|
| 497 | }
|
|---|
| 498 | }
|
|---|
| 499 | if (applyEarthTide) {
|
|---|
| 500 | station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
|
|---|
| 501 | }
|
|---|
| 502 | else {
|
|---|
| 503 | ColumnVector tideDsplEarth(3); tideDsplEarth = 0.0;
|
|---|
| 504 | station->setTideDsplEarth(tideDsplEarth);
|
|---|
| 505 | }
|
|---|
| 506 | station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
|
|---|
| 507 |
|
|---|
| 508 | // Observation model
|
|---|
| 509 | // -----------------
|
|---|
| 510 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 511 | while (it != obsVector.end()) {
|
|---|
| 512 | t_pppSatObs* satObs = *it;
|
|---|
| 513 | t_irc modelSetup;
|
|---|
| 514 | if (satObs->isValid()) {
|
|---|
| 515 | modelSetup = satObs->cmpModel(station);
|
|---|
| 516 | }
|
|---|
| 517 | if (satObs->isValid() &&
|
|---|
| 518 | satObs->eleSat() >= _opt->_minEle &&
|
|---|
| 519 | modelSetup == success) {
|
|---|
| 520 | ++it;
|
|---|
| 521 | }
|
|---|
| 522 | else {
|
|---|
| 523 | delete satObs;
|
|---|
| 524 | it = obsVector.erase(it);
|
|---|
| 525 | }
|
|---|
| 526 | }
|
|---|
| 527 |
|
|---|
| 528 | return success;
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | //
|
|---|
| 532 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 533 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
|---|
| 534 |
|
|---|
| 535 | try {
|
|---|
| 536 | initOutput(output);
|
|---|
| 537 |
|
|---|
| 538 | // Prepare Observations of the Rover
|
|---|
| 539 | // ---------------------------------
|
|---|
| 540 | if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
|
|---|
| 541 | return finish(failure, 1);
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 545 | ColumnVector xyzc(4); xyzc = 0.0;
|
|---|
| 546 | bool print = (iter == 2);
|
|---|
| 547 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
|---|
| 548 | return finish(failure, 2);
|
|---|
| 549 | }
|
|---|
| 550 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
|---|
| 551 | return finish(failure, 3);
|
|---|
| 552 | }
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | // Use observations only if satellite code biases are available
|
|---|
| 556 | // ------------------------------------------------------------
|
|---|
| 557 | if (_opt->ambRes()) {
|
|---|
| 558 | useObsWithBiasesOnly(_obsRover);
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | if (int(_obsRover.size()) < _opt->_minObs) {
|
|---|
| 562 | LOG << "t_pppClient::processEpoch not enough observations" << endl;
|
|---|
| 563 | return finish(failure, 4);
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | // Prepare Pseudo Observations of the Rover
|
|---|
| 567 | // ----------------------------------------
|
|---|
| 568 | _pseudoObsIono = preparePseudoObs(_obsRover);
|
|---|
| 569 |
|
|---|
| 570 | // Store last epoch of data
|
|---|
| 571 | // ------------------------
|
|---|
| 572 | _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
|
|---|
| 573 |
|
|---|
| 574 | // Process Epoch in Filter
|
|---|
| 575 | // -----------------------
|
|---|
| 576 | if (_filter->processEpoch(_obsPool) != success) {
|
|---|
| 577 | LOG << "t_pppFilter::processEpoch() != success" << endl;
|
|---|
| 578 | return finish(failure, 5);
|
|---|
| 579 | }
|
|---|
| 580 | }
|
|---|
| 581 | catch (Exception& exc) {
|
|---|
| 582 | LOG << exc.what() << endl;
|
|---|
| 583 | return finish(failure, 6);
|
|---|
| 584 | }
|
|---|
| 585 | catch (t_except msg) {
|
|---|
| 586 | LOG << msg.what() << endl;
|
|---|
| 587 | return finish(failure, 7);
|
|---|
| 588 | }
|
|---|
| 589 | catch (const char* msg) {
|
|---|
| 590 | LOG << msg << endl;
|
|---|
| 591 | return finish(failure, 8);
|
|---|
| 592 | }
|
|---|
| 593 | catch (...) {
|
|---|
| 594 | LOG << "unknown exception" << endl;
|
|---|
| 595 | return finish(failure, 9);
|
|---|
| 596 | }
|
|---|
| 597 | return finish(success, 0);
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | //
|
|---|
| 601 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 602 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
|---|
| 603 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | //
|
|---|
| 607 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 608 | t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
|---|
| 609 |
|
|---|
| 610 | if (pos.Nrows() != 4) {
|
|---|
| 611 | pos.ReSize(4);
|
|---|
| 612 | }
|
|---|
| 613 | pos = 0.0;
|
|---|
| 614 |
|
|---|
| 615 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 616 | Matrix BB = BBpass;
|
|---|
| 617 | int mm = BB.Nrows();
|
|---|
| 618 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 619 | double xx = BB(ii,1);
|
|---|
| 620 | double yy = BB(ii,2);
|
|---|
| 621 | double traveltime = 0.072;
|
|---|
| 622 | if (iter > 1) {
|
|---|
| 623 | double zz = BB(ii,3);
|
|---|
| 624 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
|---|
| 625 | (yy-pos(2)) * (yy-pos(2)) +
|
|---|
| 626 | (zz-pos(3)) * (zz-pos(3)) );
|
|---|
| 627 | traveltime = rho / t_CST::c;
|
|---|
| 628 | }
|
|---|
| 629 | double angle = traveltime * t_CST::omega;
|
|---|
| 630 | double cosa = cos(angle);
|
|---|
| 631 | double sina = sin(angle);
|
|---|
| 632 | BB(ii,1) = cosa * xx + sina * yy;
|
|---|
| 633 | BB(ii,2) = -sina * xx + cosa * yy;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | Matrix BBB;
|
|---|
| 637 | if (mm > 4) {
|
|---|
| 638 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
|---|
| 639 | BBB = hlp.i() * BB.t();
|
|---|
| 640 | }
|
|---|
| 641 | else {
|
|---|
| 642 | BBB = BB.i();
|
|---|
| 643 | }
|
|---|
| 644 | ColumnVector ee(mm); ee = 1.0;
|
|---|
| 645 | ColumnVector alpha(mm); alpha = 0.0;
|
|---|
| 646 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 647 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
|---|
| 648 | }
|
|---|
| 649 | ColumnVector BBBe = BBB * ee;
|
|---|
| 650 | ColumnVector BBBalpha = BBB * alpha;
|
|---|
| 651 | double aa = lorentz(BBBe, BBBe);
|
|---|
| 652 | double bb = lorentz(BBBe, BBBalpha)-1;
|
|---|
| 653 | double cc = lorentz(BBBalpha, BBBalpha);
|
|---|
| 654 | double root = sqrt(bb*bb-aa*cc);
|
|---|
| 655 |
|
|---|
| 656 | Matrix hlpPos(4,2);
|
|---|
| 657 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
|---|
| 658 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
|---|
| 659 |
|
|---|
| 660 | ColumnVector omc(2);
|
|---|
| 661 | for (int pp = 1; pp <= 2; pp++) {
|
|---|
| 662 | hlpPos(4,pp) = -hlpPos(4,pp);
|
|---|
| 663 | omc(pp) = BB(1,4) -
|
|---|
| 664 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
|---|
| 665 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
|---|
| 666 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
|---|
| 667 | hlpPos(4,pp);
|
|---|
| 668 | }
|
|---|
| 669 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
|---|
| 670 | pos = hlpPos.Column(2);
|
|---|
| 671 | }
|
|---|
| 672 | else {
|
|---|
| 673 | pos = hlpPos.Column(1);
|
|---|
| 674 | }
|
|---|
| 675 | }
|
|---|
| 676 | if (pos.size() != 4 ||
|
|---|
| 677 | std::isnan(pos(1)) ||
|
|---|
| 678 | std::isnan(pos(2)) ||
|
|---|
| 679 | std::isnan(pos(3)) ||
|
|---|
| 680 | std::isnan(pos(4))) {
|
|---|
| 681 | return failure;
|
|---|
| 682 | }
|
|---|
| 683 |
|
|---|
| 684 | return success;
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | //
|
|---|
| 688 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 689 | void t_pppClient::reset() {
|
|---|
| 690 |
|
|---|
| 691 | LOG << "pppClient: reset" << endl;
|
|---|
| 692 | _refPrnMap.clear();
|
|---|
| 693 | // to delete old orbit and clock corrections
|
|---|
| 694 | delete _ephPool;
|
|---|
| 695 | _ephPool = new t_pppEphPool();
|
|---|
| 696 |
|
|---|
| 697 | // to delete old biases
|
|---|
| 698 | delete _obsPool;
|
|---|
| 699 | _obsPool = new t_pppObsPool();
|
|---|
| 700 |
|
|---|
| 701 | // to delete all parameters
|
|---|
| 702 | delete _filter;
|
|---|
| 703 | _filter = new t_pppFilter();
|
|---|
| 704 |
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | //
|
|---|
| 708 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 709 | void t_pppClient::useObsWithBiasesOnly(vector<t_pppSatObs*>& obsVector) const {
|
|---|
| 710 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 711 | while (it != obsVector.end()) {
|
|---|
| 712 | t_pppSatObs* pppSatObs = *it;
|
|---|
| 713 | if (pppSatObs->hasBiases()) {
|
|---|
| 714 | ++it;
|
|---|
| 715 | }
|
|---|
| 716 | else {
|
|---|
| 717 | it = obsVector.erase(it);
|
|---|
| 718 | delete pppSatObs;
|
|---|
| 719 | }
|
|---|
| 720 | }
|
|---|
| 721 | }
|
|---|