Changeset 6083 in ntrip


Ignore:
Timestamp:
Sep 7, 2014, 6:35:49 PM (10 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC/src/PPP_free
Files:
4 edited

Legend:

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

    r6082 r6083  
    5454using namespace std;
    5555
     56// Global variable holding thread-specific pointers
     57//////////////////////////////////////////////////////////////////////////////
     58bncPPPclient* PPP_CLIENT = 0;
     59
     60// Static function returning thread-specific pointer
     61//////////////////////////////////////////////////////////////////////////////
     62bncPPPclient* t_pppClient::instance() {
     63  return PPP_CLIENT;
     64}
     65
    5666// Constructor
    5767////////////////////////////////////////////////////////////////////////////
    58 bncPPPclient::bncPPPclient(QByteArray staID, const t_pppOptions* opt) : bncEphUser(false) {
    59 
    60   _opt     = opt;
    61   _staID   = staID;
    62   _model   = new bncModel(this);
    63   _epoData = new t_epoData();
     68bncPPPclient::bncPPPclient(const t_pppOptions* opt) : bncEphUser(false) {
     69
     70  _opt       = new t_pppOptions(*opt);
     71  _staID     = QByteArray(_opt->_roverName.c_str())
     72  _model     = new bncModel(this);
     73  _epoData   = new t_epoData();
     74  PPP_CLIENT = this;
    6475}
    6576
     
    8293
    8394  delete _model;
     95  delete _epoData;
     96  delete _opt;
    8497}
    8598
     
    231244}
    232245
     246//
     247//////////////////////////////////////////////////////////////////////////////
     248void t_pppClient::putEphemeris(const t_eph* eph) {
     249  const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
     250  const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
     251  const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
     252  if      (ephGPS) {
     253    putNewEph(new t_ephGPS(*ephGPS));
     254  }
     255  else if (ephGlo) {
     256    putNewEph(new t_ephGlo(*ephGlo));
     257  }
     258  else if (ephGal) {
     259    putNewEph(new t_ephGal(*ephGal));
     260  }
     261}
     262
    233263// Satellite Position
    234264////////////////////////////////////////////////////////////////////////////
  • trunk/BNC/src/PPP_free/bncpppclient.h

    r6082 r6083  
    2828#include <vector>
    2929#include "bncephuser.h"
    30 #include "GPSDecoder.h"
    31 
    3230
    3331namespace BNC_PPP {
     
    4139class t_orbCorr;
    4240class t_clkCorr;
     41class t_satBias;
    4342
    4443class bncPPPclient : public bncEphUser {
    4544 public:
    46   bncPPPclient(QByteArray staID, const t_pppOptions* opt);
     45  bncPPPclient(const t_pppOptions* opt);
    4746  ~bncPPPclient();
    48   void                processEpoch(const std::vector<t_satObs*>& satObs, t_output* output);
    49   void                putOrbCorrections(const std::vector<t_orbCorr*>& corr);
    50   void                putClkCorrections(const std::vector<t_clkCorr*>& corr);
    51   QByteArray          staID() const {return _staID;}
    52   const t_pppOptions* opt() const {return _opt;}
     47  void                 processEpoch(const std::vector<t_satObs*>& satObs, t_output* output);
     48  void                 putEphemeris(const t_eph* eph);                 
     49  void                 putOrbCorrections(const std::vector<t_orbCorr*>& corr);
     50  void                 putClkCorrections(const std::vector<t_clkCorr*>& corr);
     51  void                 putBiases(const std::vector<t_satBias*>& satBias);   
     52  QByteArray           staID() const {return _staID;}
     53  const t_pppOptions*  opt() const {return _opt;}
     54  static bncPPPclient* instance();
     55  std::ostringstream&  log() {return *_log;}
    5356
    5457 private:
    55   class slipInfo {
    56    public:
    57     slipInfo() {
    58       slipCntL1 = -1;
    59       slipCntL2 = -1;
    60       slipCntL5 = -1;
    61     }
    62     ~slipInfo(){}
    63     int slipCntL1;
    64     int slipCntL2;
    65     int slipCntL5;
    66   };
    67 
    6858  t_irc getSatPos(const bncTime& tt, const QString& prn, ColumnVector& xc, ColumnVector& vv);
    6959  void  putNewObs(t_satData* satData);
    7060  t_irc cmpToT(t_satData* satData);
    7161
    72   const t_pppOptions*     _opt;
    73   QByteArray              _staID;
    74   QMap<QString, t_corr*>  _corr;
    75   bncTime                 _corr_tt;
    76   QMap<QString, t_bias*>  _bias;
    77   t_epoData*              _epoData;
    78   bncModel*               _model;
     62  t_pppOptions*       _opt;
     63  QByteArray          _staID;
     64  t_epoData*          _epoData;
     65  bncModel*           _model;
     66  std::ostringstream* _log;
    7967};
    8068
     
    162150}
    163151
     152#define LOG (BNC_PPP::t_pppClient::instance()->log())
     153
    164154#endif
  • 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
  • trunk/BNC/src/PPP_free/pppClient.h

    r6067 r6083  
    1 #ifndef PPPCLIENT_H
    2 #define PPPCLIENT_H
     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.
    324
    4 #include <sstream>
     25#ifndef BNCPPPCLIENT_H
     26#define BNCPPPCLIENT_H
     27
    528#include <vector>
    6 #include "pppInclude.h"
    7 #include "ephemeris.h"
    8 #include "pppOptions.h"
    9 #include "bncpppclient.h"
     29#include "bncephuser.h"
    1030
    1131namespace BNC_PPP {
     32 
     33class bncModel;
     34class t_pppOptions;
     35class t_satObs;
     36class t_satData;
     37class t_epoData;
     38class t_output;
     39class t_orbCorr;
     40class t_clkCorr;
     41class t_satBias;
    1242
    13 class t_pppClient {
     43class bncPPPclient : public bncEphUser {
    1444 public:
    15   t_pppClient(const t_pppOptions* opt);                                                     
    16   ~t_pppClient();                                                     
    17 
    18   void putEphemeris(const t_eph* eph);                 
    19   void putOrbCorrections(const std::vector<t_orbCorr*>& corr);
    20   void putClkCorrections(const std::vector<t_clkCorr*>& corr);
    21   void putBiases(const std::vector<t_satBias*>& satBias);   
    22   void processEpoch(const std::vector<t_satObs*>& satObs, t_output* output);
    23 
    24   static t_pppClient* instance();
    25   std::ostringstream& log() {return *_log;}
     45  bncPPPclient(const t_pppOptions* opt);
     46  ~bncPPPclient();
     47  void                 processEpoch(const std::vector<t_satObs*>& satObs, t_output* output);
     48  void                 putEphemeris(const t_eph* eph);                 
     49  void                 putOrbCorrections(const std::vector<t_orbCorr*>& corr);
     50  void                 putClkCorrections(const std::vector<t_clkCorr*>& corr);
     51  void                 putBiases(const std::vector<t_satBias*>& satBias);   
     52  QByteArray           staID() const {return _staID;}
     53  const t_pppOptions*  opt() const {return _opt;}
     54  static bncPPPclient* instance();
     55  std::ostringstream&  log() {return *_log;}
    2656
    2757 private:
     58  t_irc getSatPos(const bncTime& tt, const QString& prn, ColumnVector& xc, ColumnVector& vv);
     59  void  putNewObs(t_satData* satData);
     60  t_irc cmpToT(t_satData* satData);
     61
     62  t_pppOptions*       _opt;
     63  QByteArray          _staID;
     64  t_epoData*          _epoData;
     65  bncModel*           _model;
    2866  std::ostringstream* _log;
    29   t_pppOptions*       _opt;
    30   bncPPPclient*       _client;
    3167};
    3268
    33 }; // namespace BNC_PPP
     69class t_satData {
     70 public:
     71  t_satData() {
     72    obsIndex = 0;
     73    P1 = 0.0;
     74    P2 = 0.0;
     75    P5 = 0.0;
     76    P3 = 0.0;
     77    L1 = 0.0;
     78    L2 = 0.0;
     79    L5 = 0.0;
     80    L3 = 0.0;
     81  }
     82  ~t_satData() {}
     83  bncTime      tt;
     84  QString      prn;
     85  double       P1;
     86  double       P2;
     87  double       P5;
     88  double       P3;
     89  double       L1;
     90  double       L2;
     91  double       L5;
     92  double       L3;
     93  ColumnVector xx;
     94  ColumnVector vv;
     95  double       clk;
     96  double       eleSat;
     97  double       azSat;
     98  double       rho;
     99  bool         slipFlag;
     100  double       lambda3;
     101  unsigned     obsIndex;
     102  char system() const {return prn.toAscii()[0];}
     103};
     104
     105class t_epoData {
     106 public:
     107  t_epoData() {}
     108
     109  ~t_epoData() {
     110    clear();
     111  }
     112
     113  void clear() {
     114    QMapIterator<QString, t_satData*> it(satData);
     115    while (it.hasNext()) {
     116      it.next();
     117      delete it.value();
     118    }
     119    satData.clear();
     120    tt.reset();
     121  }
     122
     123  void deepCopy(const t_epoData* from) {
     124    clear();
     125    tt = from->tt;
     126    QMapIterator<QString, t_satData*> it(from->satData);
     127    while (it.hasNext()) {
     128      it.next();
     129      satData[it.key()] = new t_satData(*it.value());
     130    }
     131  }
     132
     133  unsigned sizeSys(char system) const {
     134    unsigned ans = 0;
     135    QMapIterator<QString, t_satData*> it(satData);
     136    while (it.hasNext()) {
     137      it.next();
     138      if (it.value()->system() == system) {
     139        ++ans;
     140      }
     141    }
     142    return ans;
     143  }
     144  unsigned sizeAll() const {return satData.size();}
     145
     146  bncTime                   tt;
     147  QMap<QString, t_satData*> satData;
     148};
     149
     150}
    34151
    35152#define LOG (BNC_PPP::t_pppClient::instance()->log())
Note: See TracChangeset for help on using the changeset viewer.