Changeset 1218 in ntrip


Ignore:
Timestamp:
Nov 19, 2008, 2:56:05 PM (15 years ago)
Author:
mervart
Message:

Zdenek Lukes:
a) changed logic how the ephemerides are stored for decoding of message 20/21 RTCM 2.3
b) added some debugging output (enabled is macro DEBUG_RTCM2_2021 is defined)

Location:
trunk/BNC
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/RTCM/GPSDecoder.h

    r1184 r1218  
    2727
    2828#include <iostream>
     29#include <vector>
     30#include <string>
    2931#include <QPointer>
    3032#include <QList>
     
    121123class GPSDecoder {
    122124 public:
    123   virtual t_irc Decode(char* buffer, int bufLen) = 0;
     125  virtual t_irc Decode(char* buffer, int bufLen, std::vector<std::string>& errmsg) = 0;
    124126
    125127  virtual ~GPSDecoder() {
  • trunk/BNC/RTCM/RTCM2Decoder.cpp

    r1167 r1218  
    4242#include <sstream>
    4343#include <iomanip>
     44#include <set>
    4445
    4546#include "../bncutils.h"
     
    6465
    6566RTCM2Decoder::~RTCM2Decoder() {
    66   for (t_pairMap::iterator ii = _ephPair.begin(); ii != _ephPair.end(); ii++) {
     67  for (t_listMap::iterator ii = _ephList.begin(); ii != _ephList.end(); ii++) {
    6768    delete ii->second;
    6869  }
     
    104105
    105106//
    106 t_irc RTCM2Decoder::Decode(char* buffer, int bufLen) {
     107t_irc RTCM2Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
     108
     109  errmsg.clear();
    107110
    108111  _buffer.append(buffer, bufLen);
     
    165168      if (_msg2021.valid()) {
    166169        decoded = true;
    167         translateCorr2Obs();
     170        translateCorr2Obs(errmsg);
    168171      }
    169172    }
     
    182185
    183186
    184 void RTCM2Decoder::storeEph(const gpsephemeris& gpseph) {
     187bool RTCM2Decoder::storeEph(const gpsephemeris& gpseph, string& storedPRN, vector<int>& IODs) {
    185188  t_ephGPS eph; eph.set(&gpseph);
    186189
    187   storeEph(eph);
    188 }
    189 
    190 
    191 void RTCM2Decoder::storeEph(const t_ephGPS& gpseph) {
     190  return storeEph(eph, storedPRN, IODs);
     191}
     192
     193
     194bool RTCM2Decoder::storeEph(const t_ephGPS& gpseph, string& storedPRN, vector<int>& IODs) {
    192195  t_ephGPS* eph = new t_ephGPS(gpseph);
    193196
    194197  string prn = eph->prn();
    195198
    196   t_pairMap::iterator ip = _ephPair.find(prn);
    197   if (ip == _ephPair.end() ) {
    198     ip = _ephPair.insert(pair<string, t_ephPair*>(prn, new t_ephPair)).first;
    199   }
    200   t_ephPair* pair = ip->second;
    201 
    202   if ( !pair->eph || eph->isNewerThan(pair->eph) ) {
    203     delete pair->oldEph;
    204     pair->oldEph = pair->eph;
    205     pair->eph    = eph;
    206 
    207     return;
     199  t_listMap::iterator ip = _ephList.find(prn);
     200  if (ip == _ephList.end() ) {
     201    ip = _ephList.insert(pair<string, t_ephList*>(prn, new t_ephList)).first;
     202  }
     203  t_ephList* ephList = ip->second;
     204
     205  bool stored = ephList->store(eph);
     206
     207  if ( stored ) {
     208    storedPRN = eph->prn();
     209    ephList->getIODs(IODs);
     210    return true;
    208211  }
    209212
    210213  delete eph;
     214
     215  return false;
    211216}
    212217 
    213218 
    214 void RTCM2Decoder::translateCorr2Obs() {
     219void RTCM2Decoder::translateCorr2Obs(vector<string>& errmsg) {
    215220
    216221  if ( !_msg03.validMsg || !_msg2021.valid() ) {
     
    248253    const RTCM2_2021::HiResCorr* corr = icorr->second;
    249254
     255    // beg test
     256    if ( corr->PRN >= 200 ) {
     257      continue;
     258    }
     259    // end test
     260
     261
    250262    ostringstream oPRN; oPRN.fill('0');
    251263
     
    255267    string PRN(oPRN.str());
    256268
    257     t_pairMap::const_iterator ieph = _ephPair.find(PRN);
    258     const t_eph* eph0 = 0;
    259     const t_eph* eph1 = 0;
    260 
    261     if ( ieph != _ephPair.end() ) {
    262       eph0 = ieph->second->eph;
    263       eph1 = ieph->second->oldEph;
    264     }
    265 
    266     if ( !eph0 && !eph1 ) {
     269    t_listMap::const_iterator ieph = _ephList.find(PRN);
     270
     271    if ( ieph == _ephList.end() ) {
     272      errmsg.push_back("missing eph for " + PRN);
    267273      continue;
    268274    }
     
    277283    p_obs new_obs = 0;
    278284
     285    // missing IOD
     286    vector<string> missingIOD;
     287    vector<string>     hasIOD;
    279288    for (unsigned ii = 0; ii < 4; ii++) {
    280289      int          IODcorr = 0;
     
    312321      }
    313322
    314       eph = 0;
    315       if      ( eph0 && eph0->IOD() == IODcorr )
    316         eph = eph0;
    317       else if ( eph1 && eph1->IOD() == IODcorr )
    318         eph = eph1;
    319       if ( eph && corr ) {
     323      eph = ieph->second->getEph(IODcorr);
     324
     325      if ( eph ) {
     326        ostringstream msg;
     327        msg << obsT << ':' << setw(3) << eph->IOD();
     328        hasIOD.push_back(msg.str());
     329
     330
    320331        int    GPSWeek_tot;
    321332        double GPSWeeks_tot;
     
    372383        }
    373384      }
     385      else if ( IODcorr != 0 ) {
     386        ostringstream msg;
     387        msg << obsT << ':' << setw(3) << IODcorr;
     388        missingIOD.push_back(msg.str());
     389      }
    374390    } // loop over frequencies
    375    
     391   
     392    // Error report
     393    if ( missingIOD.size() ) {
     394      ostringstream missingIODstr;
     395
     396      copy(missingIOD.begin(), missingIOD.end(), ostream_iterator<string>(missingIODstr, "   "));
     397
     398      errmsg.push_back("missing eph for " + PRN + " , IODs " + missingIODstr.str());
     399    }
     400
     401    // Store new observation
    376402    if ( new_obs ) {
    377403      _obsList.push_back( new_obs );
    378     }
    379   }
    380 }
     404
     405      ///ostringstream hasIODstr;
     406      ///copy(hasIOD.begin(), hasIOD.end(), ostream_iterator<string>(hasIODstr, "    "));
     407      ///errmsg.push_back("decoded PRN " + PRN + " : " + hasIODstr.str());
     408    }
     409  }
     410}
  • trunk/BNC/RTCM/RTCM2Decoder.h

    r1167 r1218  
    2727
    2828#include <map>
     29#include <vector>
     30#include <list>
    2931
    3032#include "GPSDecoder.h"
     
    3941    RTCM2Decoder(const std::string& ID);
    4042    virtual ~RTCM2Decoder();
    41     virtual t_irc Decode(char* buffer, int bufLen);
     43    virtual t_irc Decode(char* buffer, int bufLen, std::vector<std::string>& errmsg);
    4244
    43     void  storeEph(const gpsephemeris& gpseph);
    44     void  storeEph(const t_ephGPS&     gpseph);
     45    bool  storeEph(const gpsephemeris& gpseph, std::string& storedPRN, std::vector<int>& IODs);
     46    bool  storeEph(const t_ephGPS&     gpseph, std::string& storedPRN, std::vector<int>& IODs);
    4547
    4648    t_irc getStaCrd(double& xx, double& yy, double& zz);
    4749
    48     t_irc getStaCrd(double& xx, double& yy, double& zz,
     50    t_irc getStaCrd(double& xx,  double& yy, double& zz,
    4951                    double& dx1, double& dy1, double& dz1,
    5052                    double& dx2, double& dy2, double& dz2);
     
    5658  private:
    5759
    58     class t_ephPair {
     60    class t_ephList {
    5961    public:
    60       t_ephPair() {
    61         eph    = 0;
    62         oldEph = 0;
     62      t_ephList() {}
     63     
     64      ~t_ephList() {
     65        for (std::list<t_eph*>::iterator ii = _eph.begin(); ii != _eph.end(); ii++) {
     66          delete  (*ii);
     67        }
     68      }
     69
     70      bool store(t_eph* eph) {
     71        if ( _eph.size() == 0 ) {
     72          _eph.push_back(eph);
     73          return true;
     74        }
     75         
     76        std::list<t_eph*>::iterator ii = _eph.begin();
     77        while (ii != _eph.end()) {
     78          if ( eph->IOD() == (*ii)->IOD() ) {
     79            return false;
     80          }
     81          if ( ! eph->isNewerThan(*ii) ) {
     82            break;
     83          }
     84          ++ii;
     85        }
     86
     87        if ( ii == _eph.begin() && _eph.size() == MAXSIZE) {
     88          return false;
     89        }
     90
     91        _eph.insert(ii, eph);
     92
     93        while ( _eph.size() > MAXSIZE ) {
     94          delete _eph.front();
     95          _eph.pop_front();
     96        }
     97
     98        return true;
    6399      }
    64100     
    65       ~t_ephPair() {
    66         delete eph;
    67         delete oldEph;
     101      const t_eph* getEph(int IOD) const {
     102        for (std::list<t_eph*>::const_iterator ii = _eph.begin(); ii != _eph.end(); ii++) {
     103          if ( (*ii)->IOD() == IOD ) {
     104            return (*ii);
     105          }
     106        }
     107        return 0;
    68108      }
    69      
    70       t_eph* eph;
    71       t_eph* oldEph;
     109
     110      void getIODs(std::vector<int>& IODs) const {
     111        IODs.clear();
     112        for (std::list<t_eph*>::const_iterator ii = _eph.begin(); ii != _eph.end(); ii++) {
     113          IODs.push_back((*ii)->IOD());
     114        }
     115      }
     116
     117      static const unsigned MAXSIZE = 3;
     118
     119      std::list<t_eph*> _eph;
    72120    };
    73121
    74     void translateCorr2Obs();
     122    void translateCorr2Obs(std::vector<std::string>& errmsg);
    75123
    76124    std::string            _ID;
     
    86134    rtcm2::RTCM2_22           _msg22;
    87135    rtcm2::RTCM2_2021         _msg2021;
    88     std::map<std::string, t_ephPair*> _ephPair;
     136    std::map<std::string, t_ephList*> _ephList;
    89137
    90     typedef std::map<std::string, t_ephPair*> t_pairMap;
     138    typedef std::map<std::string, t_ephList*> t_listMap;
    91139};
    92140
  • trunk/BNC/RTCM3/RTCM3Decoder.cpp

    r1185 r1218  
    121121//
    122122////////////////////////////////////////////////////////////////////////////
    123 t_irc RTCM3Decoder::Decode(char* buffer, int bufLen) {
     123t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
     124
     125  errmsg.clear();
    124126
    125127  bool decoded = false;
     
    128130  // -----------------------------------------
    129131  if (_mode == unknown || _mode == corrections) {
    130     if ( _coDecoder->Decode(buffer, bufLen) == success ) {
     132    if ( _coDecoder->Decode(buffer, bufLen, errmsg) == success ) {
    131133      decoded = true;
    132134
     
    354356            decoded = true;
    355357            gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
     358
     359#ifdef DEBUG_RTCM2_2021
     360            QString msg = QString("%1: got eph %2 IODC %3 GPSweek %4 TOC %5 TOE %6")
     361              .arg(_staID)
     362              .arg(ep->satellite, 2)
     363              .arg(ep->IODC,      4)
     364              .arg(ep->GPSweek,   4)
     365              .arg(ep->TOC,       6)
     366              .arg(ep->TOE,       6);
     367            emit(newMessage(msg.toAscii()));
     368#endif
     369
    356370            emit newGPSEph(ep);
    357371          }
  • trunk/BNC/RTCM3/RTCM3Decoder.h

    r1095 r1218  
    4040  RTCM3Decoder(const QString& fileName);
    4141  virtual ~RTCM3Decoder();
    42   virtual t_irc Decode(char* buffer = 0, int bufLen = 0);
     42  virtual t_irc Decode(char* buffer, int bufLen, std::vector<std::string>& errmsg);
    4343 signals:
    4444  void newMessage(QByteArray msg);
  • trunk/BNC/RTCM3/RTCM3coDecoder.cpp

    r1154 r1218  
    109109//
    110110////////////////////////////////////////////////////////////////////////////
    111 t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen) {
     111t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
     112
     113  errmsg.clear();
    112114
    113115  _buffer.append(buffer, bufLen);
  • trunk/BNC/RTCM3/RTCM3coDecoder.h

    r974 r1218  
    4242  RTCM3coDecoder(const QString& staID);
    4343  virtual ~RTCM3coDecoder();
    44   virtual t_irc Decode(char* buffer = 0, int bufLen = 0);
     44  virtual t_irc Decode(char* buffer, int bufLen, std::vector<std::string>& errmsg);
    4545
    4646 signals:
  • trunk/BNC/RTIGS/RTIGSDecoder.cpp

    r661 r1218  
    6969//
    7070////////////////////////////////////////////////////////////////////////////
    71 t_irc RTIGSDecoder::Decode(char* buffer, int bufLen) {
     71t_irc RTIGSDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
     72
     73  errmsg.clear();
    7274
    7375  // Append the incomming data to the internal buffer
  • trunk/BNC/RTIGS/RTIGSDecoder.h

    r661 r1218  
    5151  RTIGSDecoder();
    5252  virtual ~RTIGSDecoder();
    53   virtual t_irc Decode(char* buffer = 0, int bufLen = 0);
     53  virtual t_irc Decode(char* buffer, int bufLen, std::vector<std::string>& errmsg);
    5454private:
    5555  CGPS_Transform _GPSTrans;
  • trunk/BNC/bnc.pro

    r1044 r1218  
    55###CONFIG += debug
    66
    7 DEFINES += NO_RTCM3_MAIN
     7##DEFINES += NO_RTCM3_MAIN DEBUG_RTCM2_2021
     8DEFINES += NO_RTCM3_MAIN
    89
    910RESOURCES += bnc.qrc
  • trunk/BNC/bncapp.cpp

    r1171 r1218  
    149149void bncApp::slotMessage(const QByteArray msg) {
    150150
    151   QMutexLocker locker(&_mutex);
     151  QMutexLocker locker(&_mutexMessage);
    152152
    153153  messagePrivate(msg);
     
    198198
    199199  gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
     200
    200201  if ( *ee == 0                         ||
    201202       gpseph->GPSweek > (*ee)->GPSweek ||
  • trunk/BNC/bncapp.h

    r1166 r1218  
    7575    QString           _bncVersion;
    7676    QMutex            _mutex;
     77    QMutex            _mutexMessage;
    7778    QString           _ephPath;
    7879    QString           _ephFileNameGPS;
  • trunk/BNC/bncgetthread.cpp

    r1201 r1218  
    4141#include <stdlib.h>
    4242#include <iomanip>
     43#include <sstream>
    4344
    4445#include <QFile>
     
    543544
    544545        if (_inspSegm<1) {
    545           _decoder->Decode(data, nBytes);
     546          vector<string> errmsg;
     547          _decoder->Decode(data, nBytes, errmsg);
     548#ifdef DEBUG_RTCM2_2021
     549          for (unsigned ii = 0; ii < errmsg.size(); ii++) {
     550            emit newMessage(_staID + ": " + errmsg[ii].c_str());
     551          }
     552#endif
    546553        }
    547554        else {
     
    553560       
    554561            if (decode) {
    555               if ( _decoder->Decode(data, nBytes) == success ) {
     562              vector<string> errmsg;
     563              if ( _decoder->Decode(data, nBytes, errmsg) == success ) {
    556564                numSucc += 1;
    557565              }
     
    559567                decode = false;
    560568              }
     569#ifdef DEBUG_RTCM2_2021
     570              for (unsigned ii = 0; ii < errmsg.size(); ii++) {
     571                emit newMessage(_staID + ": " + errmsg[ii].c_str());
     572              }
     573#endif
    561574            }
    562575       
     
    737750            bool dump = true;
    738751
    739 /*   // RTCMv2 XYZ
    740      // ----------
    741      RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
    742      if ( decoder2 && !_rnx_set_position ) {
     752            // RTCMv2 XYZ
     753            // ----------
     754            RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
     755            if ( decoder2 && !_rnx_set_position ) {
    743756              double stax, stay, staz;
    744757              double dL1[3], dL2[3];
     
    746759                                       dL1[0], dL1[1], dL1[2],
    747760                                       dL2[0], dL2[1], dL2[2]) == success ) {
    748                 QByteArray msg;
    749                 QTextStream out(&msg);
    750                 out.setRealNumberNotation(QTextStream::FixedNotation);
    751                 out.setRealNumberPrecision(5);
    752                 ////    _rnx->setApproxPos(stax, stay, staz);
    753                 out << "STA " << staID()
    754                     << ' '    << qSetFieldWidth(15) << stax
    755                     << ' '    << qSetFieldWidth(15) << stay
    756                     << ' '    << qSetFieldWidth(15) << staz
    757                     << " L1 " << qSetFieldWidth(10) << dL1[0]
    758                     << ' '    << qSetFieldWidth(10) << dL1[1]
    759                     << ' '    << qSetFieldWidth(10) << dL1[2]
    760                     << " L2 " << qSetFieldWidth(10) << dL2[0]
    761                     << ' '    << qSetFieldWidth(10) << dL2[1]
    762                     << ' '    << qSetFieldWidth(10) << dL2[2] << endl;
     761
     762                ostringstream msg2; msg2.setf(ios::fixed);
     763                msg2 << "station coordinates " << staID().data()
     764                     << ' ' << setw(14) << setprecision(5) << stax
     765                     << ' ' << setw(14) << setprecision(5) << stay
     766                     << ' ' << setw(14) << setprecision(5) << staz
     767                     << " L1 "
     768                     << ' ' << setw(8)  << setprecision(5) << dL1[0]
     769                     << ' ' << setw(8)  << setprecision(5) << dL1[1]
     770                     << ' ' << setw(8)  << setprecision(5) << dL1[2]
     771                     << " L2 "
     772                     << ' ' << setw(8)  << setprecision(5) << dL2[0]
     773                     << ' ' << setw(8)  << setprecision(5) << dL2[1]
     774                     << ' ' << setw(8)  << setprecision(5) << dL2[2]
     775                     << ends;
    763776                _rnx_set_position = true;
    764                 emit newMessage(msg);
     777                emit newMessage(QByteArray(msg2.str().c_str()));
    765778              }
    766             }  */
    767 
    768             ////RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
    769             ////if ( decoder2 && !_rnx_set_position ) {
    770             ////  double stax, stay, staz;
    771             ////  if ( decoder2->getStaCrd(stax, stay, staz) == success ) {
    772             ////        _rnx->setApproxPos(stax, stay, staz);
    773             ////        _rnx_set_position = true;
    774             ////  }
    775             ////  else {
    776             ////        dump = false;
    777             ////  }
    778             ////}
    779              
     779            } 
     780
    780781            if ( dump ) {
    781782              long iSec    = long(floor(obs->_o.GPSWeeks+0.5));
     
    942943    QMutexLocker locker(&_mutex);
    943944 
    944     decoder->storeEph(gpseph);
    945   }
    946 }
    947 
     945    string storedPRN;
     946    vector<int> IODs;
     947   
     948    if ( decoder->storeEph(gpseph, storedPRN, IODs) ) {
     949#ifdef DEBUG_RTCM2_2021
     950      QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
     951     
     952      for (unsigned ii = 0; ii < IODs.size(); ii++) {
     953        msg += QString(" %1").arg(IODs[ii],4);
     954      }
     955     
     956      emit(newMessage(msg.toAscii()));
     957#endif
     958    }
     959  }
     960}
     961
  • trunk/BNC/bncwindow.cpp

    r1204 r1218  
    6767
    6868  connect((bncApp*)qApp, SIGNAL(newMessage(QByteArray)),
    69           this, SLOT(slotWindowMessage(QByteArray)));
     69           this, SLOT(slotWindowMessage(QByteArray)));
    7070
    7171  // Create Actions
     
    755755void bncWindow::slotWindowMessage(const QByteArray msg) {
    756756
     757#ifdef DEBUG_RTCM2_2021 
     758  const int maxBufferSize = 1000;
     759#else
    757760  const int maxBufferSize = 10000;
     761#endif
    758762 
    759763  QString txt = _log->toPlainText() + "\n" +
  • trunk/BNC/bnczerodecoder.cpp

    r1154 r1218  
    8282// Decode Method
    8383////////////////////////////////////////////////////////////////////////
    84 t_irc bncZeroDecoder::Decode(char* buffer, int bufLen) {
     84t_irc bncZeroDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
     85  errmsg.clear();
    8586  reopen();
    8687  _out->write(buffer, bufLen);
  • trunk/BNC/bnczerodecoder.h

    r934 r1218  
    3434  bncZeroDecoder(const QString& fileName);
    3535  ~bncZeroDecoder();
    36   virtual t_irc Decode(char* buffer, int bufLen);
     36  virtual t_irc Decode(char* buffer, int bufLen, std::vector<std::string>& errmsg);
    3737 private:
    3838  void reopen();
Note: See TracChangeset for help on using the changeset viewer.