Ignore:
Timestamp:
Sep 7, 2014, 6:35:49 PM (10 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/PPP_free/pppClient.cpp

    r6082 r6083  
    1 
    21// Part of BNC, a utility for retrieving decoding and
    32// converting GNSS data streams from NTRIP broadcasters.
     
    2827 * -------------------------------------------------------------------------
    2928 *
    30  * Class:      t_pppClient
    31  *
    32  * Purpose:    PPP Client processing starts here
     29 * Class:      bncPPPclient
     30 *
     31 * Purpose:    Precise Point Positioning
    3332 *
    3433 * Author:     L. Mervart
    3534 *
    36  * Created:    29-Jul-2014
     35 * Created:    21-Nov-2009
    3736 *
    3837 * Changes:   
     
    4039 * -----------------------------------------------------------------------*/
    4140
    42 #include <QThreadStorage>
    43 
    44 #include <iostream>
     41#include <newmatio.h>
    4542#include <iomanip>
    46 #include <stdlib.h>
    47 #include <string.h>
    48 #include <stdexcept>
    49 
     43#include <sstream>
     44
     45#include "bncpppclient.h"
     46#include "bnccore.h"
     47#include "bncutils.h"
     48#include "bncconst.h"
     49#include "bncmodel.h"
     50#include "pppOptions.h"
    5051#include "pppClient.h"
    51 #include "bncconst.h"
    52 #include "bncutils.h"
    53 #include "bncantex.h"
    5452
    5553using namespace BNC_PPP;
     
    5856// Global variable holding thread-specific pointers
    5957//////////////////////////////////////////////////////////////////////////////
    60 t_pppClient* PPP_CLIENT = 0;
     58bncPPPclient* PPP_CLIENT = 0;
    6159
    6260// Static function returning thread-specific pointer
    6361//////////////////////////////////////////////////////////////////////////////
    64 t_pppClient* t_pppClient::instance() {
     62bncPPPclient* t_pppClient::instance() {
    6563  return PPP_CLIENT;
    6664}
    6765
    6866// Constructor
    69 //////////////////////////////////////////////////////////////////////////////
    70 t_pppClient::t_pppClient(const t_pppOptions* opt) {
     67////////////////////////////////////////////////////////////////////////////
     68bncPPPclient::bncPPPclient(const t_pppOptions* opt) : bncEphUser(false) {
     69
    7170  _opt       = new t_pppOptions(*opt);
    72   _log       = new ostringstream();
    73   _client    = new bncPPPclient(QByteArray(_opt->_roverName.c_str()), _opt);
     71  _staID     = QByteArray(_opt->_roverName.c_str())
     72  _model     = new bncModel(this);
     73  _epoData   = new t_epoData();
    7474  PPP_CLIENT = this;
    7575}
    7676
    7777// Destructor
    78 //////////////////////////////////////////////////////////////////////////////
    79 t_pppClient::~t_pppClient() {
    80   delete _log;
     78////////////////////////////////////////////////////////////////////////////
     79bncPPPclient::~bncPPPclient() {
     80  _epoData->clear();
     81
     82  QMapIterator<QString, t_corr*> ic(_corr);
     83  while (ic.hasNext()) {
     84    ic.next();
     85    delete ic.value();
     86  }
     87
     88  QMapIterator<QString, t_bias*> ib(_bias);
     89  while (ib.hasNext()) {
     90    ib.next();
     91    delete ib.value();
     92  }
     93
     94  delete _model;
     95  delete _epoData;
    8196  delete _opt;
    82   delete _client;
     97}
     98
     99//
     100////////////////////////////////////////////////////////////////////////////
     101void bncPPPclient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
     102  QMutexLocker locker(&_mutex);
     103 
     104  // Convert and store observations
     105  // ------------------------------
     106  _epoData->clear();
     107  for (unsigned ii = 0; ii < satObs.size(); ii++) {
     108    const t_satObs* obs     = satObs[ii];
     109    t_satData*      satData = new t_satData();
     110
     111    if (_epoData->tt.undef()) {
     112      _epoData->tt = obs->_time;
     113    }
     114
     115    satData->tt       = obs->_time;
     116    satData->prn      = QString(obs->_prn.toString().c_str());
     117    satData->slipFlag = false;
     118    satData->P1       = 0.0;
     119    satData->P2       = 0.0;
     120    satData->P5       = 0.0;
     121    satData->L1       = 0.0;
     122    satData->L2       = 0.0;
     123    satData->L5       = 0.0;
     124    for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
     125      t_frqObs* frqObs = obs->_obs[ifrq];
     126      if      (frqObs->_rnxType2ch[0] == '1') {
     127        if (frqObs->_codeValid)  satData->P1       = frqObs->_code;
     128        if (frqObs->_phaseValid) satData->L1       = frqObs->_phase;
     129        if (frqObs->_slip)       satData->slipFlag = true;
     130      }
     131      else if (frqObs->_rnxType2ch[0] == '2') {
     132        if (frqObs->_codeValid)  satData->P2       = frqObs->_code;
     133        if (frqObs->_phaseValid) satData->L2       = frqObs->_phase;
     134        if (frqObs->_slip)       satData->slipFlag = true;
     135      }
     136      else if (frqObs->_rnxType2ch[0] == '5') {
     137        if (frqObs->_codeValid)  satData->P5       = frqObs->_code;
     138        if (frqObs->_phaseValid) satData->L5       = frqObs->_phase;
     139        if (frqObs->_slip)       satData->slipFlag = true;
     140      }
     141    }
     142    putNewObs(satData);
     143  }
     144
     145  // Data Pre-Processing
     146  // -------------------
     147  QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
     148  while (it.hasNext()) {
     149    it.next();
     150    QString    prn     = it.key();
     151    t_satData* satData = it.value();
     152
     153    if (cmpToT(satData) != success) {
     154      delete satData;
     155      it.remove();
     156      continue;
     157    }
     158  }
     159
     160  // Filter Solution
     161  // ---------------
     162  if (_model->update(_epoData) == success) {
     163    output->_error = false;
     164    output->_epoTime     = _model->time();
     165    output->_xyzRover[0] = _model->x();
     166    output->_xyzRover[1] = _model->y();
     167    output->_xyzRover[2] = _model->z();
     168    output->_numSat      = 0;
     169    output->_pDop        = 0.0;
     170  }
     171  else {
     172    output->_error = true;
     173  }
     174
     175  output->_log = LOG.str(); 
     176}
     177
     178//
     179////////////////////////////////////////////////////////////////////////////
     180void bncPPPclient::putNewObs(t_satData* satData) {
     181
     182  // Set Observations GPS and Glonass
     183  // --------------------------------
     184  if      (satData->system() == 'G' || satData->system() == 'R') {
     185    if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
     186        satData->L1 != 0.0 && satData->L2 != 0.0 ) {
     187
     188      int channel = 0;
     189      if (satData->system() == 'R') {
     190//        cerr << "not yet implemented" << endl;
     191//        exit(0);
     192      }
     193
     194      t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
     195      t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
     196      double f1 = t_CST::freq(fType1, channel);
     197      double f2 = t_CST::freq(fType2, channel);
     198      double a1 =   f1 * f1 / (f1 * f1 - f2 * f2);
     199      double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
     200      satData->L1      = satData->L1 * t_CST::c / f1;
     201      satData->L2      = satData->L2 * t_CST::c / f2;
     202      satData->P3      = a1 * satData->P1 + a2 * satData->P2;
     203      satData->L3      = a1 * satData->L1 + a2 * satData->L2;
     204      satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
     205      _epoData->satData[satData->prn] = satData;
     206    }
     207    else {
     208      delete satData;
     209    }
     210  }
     211
     212  // Set Observations Galileo
     213  // ------------------------
     214  else if (satData->system() == 'E') {
     215    if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
     216        satData->L1 != 0.0 && satData->L5 != 0.0 ) {
     217      double f1 = t_CST::freq(t_frequency::E1, 0);
     218      double f5 = t_CST::freq(t_frequency::E5, 0);
     219      double a1 =   f1 * f1 / (f1 * f1 - f5 * f5);
     220      double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
     221      satData->L1      = satData->L1 * t_CST::c / f1;
     222      satData->L5      = satData->L5 * t_CST::c / f5;
     223      satData->P3      = a1 * satData->P1 + a5 * satData->P5;
     224      satData->L3      = a1 * satData->L1 + a5 * satData->L5;
     225      satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
     226      _epoData->satData[satData->prn] = satData;
     227    }
     228    else {
     229      delete satData;
     230    }
     231  }
     232}
     233
     234//
     235////////////////////////////////////////////////////////////////////////////
     236void bncPPPclient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
     237  QMutexLocker locker(&_mutex);
     238}
     239
     240//
     241////////////////////////////////////////////////////////////////////////////
     242void bncPPPclient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
     243  QMutexLocker locker(&_mutex);
    83244}
    84245
     
    90251  const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
    91252  if      (ephGPS) {
    92     _client->putNewEph(new t_ephGPS(*ephGPS));
     253    putNewEph(new t_ephGPS(*ephGPS));
    93254  }
    94255  else if (ephGlo) {
    95     _client->putNewEph(new t_ephGlo(*ephGlo));
     256    putNewEph(new t_ephGlo(*ephGlo));
    96257  }
    97258  else if (ephGal) {
    98     _client->putNewEph(new t_ephGal(*ephGal));
    99   }
    100 }
    101 
    102 //
    103 //////////////////////////////////////////////////////////////////////////////
    104 void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
    105   _client->putOrbCorrections(corr);
    106 }
    107 
    108 //
    109 //////////////////////////////////////////////////////////////////////////////
    110 void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
    111   _client->putClkCorrections(corr);
    112 }
    113 
    114 //
    115 //////////////////////////////////////////////////////////////////////////////
    116 void t_pppClient::putBiases(const vector<t_satBias*>& biases) {
    117 }
    118 
    119 //
    120 //////////////////////////////////////////////////////////////////////////////
    121 void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
    122   _client->processEpoch(satObs, output);
    123 }
    124 
     259    putNewEph(new t_ephGal(*ephGal));
     260  }
     261}
     262
     263// Satellite Position
     264////////////////////////////////////////////////////////////////////////////
     265t_irc bncPPPclient::getSatPos(const bncTime& tt, const QString& prn,
     266                              ColumnVector& xc, ColumnVector& vv) {
     267  if (_eph.contains(prn)) {
     268    t_eph* eLast = _eph.value(prn)->last;
     269    t_eph* ePrev = _eph.value(prn)->prev;
     270    if      (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
     271      return success;
     272    }
     273    else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
     274      return success;
     275    }
     276  }
     277  return failure;
     278}
     279
     280// Correct Time of Transmission
     281////////////////////////////////////////////////////////////////////////////
     282t_irc bncPPPclient::cmpToT(t_satData* satData) {
     283
     284  double prange = satData->P3;
     285  if (prange == 0.0) {
     286    return failure;
     287  }
     288
     289  double clkSat = 0.0;
     290  for (int ii = 1; ii <= 10; ii++) {
     291
     292    bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
     293
     294    ColumnVector xc(4);
     295    ColumnVector vv(3);
     296    if (getSatPos(ToT, satData->prn, xc, vv) != success) {
     297      return failure;
     298    }
     299
     300    double clkSatOld = clkSat;
     301    clkSat = xc(4);
     302
     303    if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
     304      satData->xx      = xc.Rows(1,3);
     305      satData->vv      = vv;
     306      satData->clk     = clkSat * t_CST::c;
     307      return success;
     308    }
     309  }
     310
     311  return failure;
     312}
     313
Note: See TracChangeset for help on using the changeset viewer.