Changeset 3206 in ntrip


Ignore:
Timestamp:
Mar 30, 2011, 6:20:17 PM (13 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncgetthread.cpp

    r3204 r3206  
    319319  else if (_format.indexOf("RTNET") != -1) {
    320320    emit(newMessage(_staID + ": Get data in RTNet format", true));
    321     bncRtnetDecoder* rtnetDecoder = new bncRtnetDecoder();
    322     rtnetDecoder->start();
    323     _decoder = rtnetDecoder;
     321    _decoder = new bncRtnetDecoder();
    324322  }
    325323  else {
  • trunk/BNC/combination/bnccomb.cpp

    r3205 r3206  
    119119
    120120  _rtnetDecoder = new bncRtnetDecoder();
    121   _rtnetDecoder->start();
    122121
    123122  connect(this, SIGNAL(newMessage(QByteArray,bool)),
  • trunk/BNC/upload/bncrtnetdecoder.cpp

    r3203 r3206  
    4949////////////////////////////////////////////////////////////////////////
    5050bncRtnetDecoder::bncRtnetDecoder() {
    51 }
    52 
    53 // Destructor
    54 ////////////////////////////////////////////////////////////////////////
    55 bncRtnetDecoder::~bncRtnetDecoder() {
    56   for (int ic = 0; ic < _casters->size(); ic++) {
    57     delete _casters->at(ic);
    58   }
    59   delete _casters;
    60 }
    61 
    62 // Run
    63 ////////////////////////////////////////////////////////////////////////
    64 void bncRtnetDecoder::run() {
    65 
    6651  bncSettings settings;
    6752
    6853  // List of upload casters
    6954  // ----------------------
    70   _casters = new QVector<bncUploadCaster*>;
    7155  QListIterator<QString> it(settings.value("uploadMountpointsOut").toStringList());
    7256  while (it.hasNext()) {
     
    7559      int  outPort = hlp[1].toInt();
    7660      bool CoM     = (hlp[5].toInt() == Qt::Checked);
    77       _casters->push_back(new bncUploadCaster(hlp[2], hlp[0], outPort,
    78                                              hlp[3], hlp[4], CoM,
    79                                              hlp[6], "", ""));
     61      bncUploadCaster* newCaster = new bncUploadCaster(hlp[2], hlp[0], outPort,
     62                                                       hlp[3], hlp[4], CoM,
     63                                                       hlp[6], "", "");
     64      newCaster->start();
     65      _casters.push_back(newCaster);
    8066    }
    8167  }
     68}
    8269
    83   // Endless Loop - Decode
    84   // ---------------------
    85   while (true) {
    86     DecodeInThread();
    87     msleep(10);
     70// Destructor
     71////////////////////////////////////////////////////////////////////////
     72bncRtnetDecoder::~bncRtnetDecoder() {
     73  for (int ic = 0; ic < _casters.size(); ic++) {
     74    delete _casters[ic];
    8875  }
    8976}
     
    9481  QMutexLocker locker(&_mutex);
    9582  errmsg.clear();
    96   _buffer.append(QByteArray(buffer, bufLen));
     83  for (int ic = 0; ic < _casters.size(); ic++) {
     84    _casters[ic]->decodeRtnetStream(buffer, bufLen, _eph);
     85  }
    9786  return success;
    9887}
    9988
    100 // Decode and upload in separate thread
    101 ////////////////////////////////////////////////////////////////////////
    102 void bncRtnetDecoder::DecodeInThread() {
    103   QMutexLocker locker(&_mutex);
    104 
    105   // Prepare list of lines with satellite positions in SP3-like format
    106   // -----------------------------------------------------------------
    107   QStringList lines;
    108   int iLast = _buffer.lastIndexOf('\n');
    109   if (iLast != -1) {
    110     QStringList hlpLines = _buffer.split('\n', QString::SkipEmptyParts);
    111     _buffer = _buffer.mid(iLast+1);
    112     for (int ii = 0; ii < hlpLines.size(); ii++) {
    113       if      (hlpLines[ii].indexOf('*') != -1) {
    114         QTextStream in(hlpLines[ii].toAscii());
    115         QString hlp;
    116         int     year, month, day, hour, min;
    117         double  sec;
    118         in >> hlp >> year >> month >> day >> hour >> min >> sec;
    119         _epoTime.set( year, month, day, hour, min, sec);
    120       }
    121       else if (_epoTime.valid()) {
    122         lines << hlpLines[ii];
    123       }
    124     }
    125   }
    126 
    127   // Satellite positions to be processed
    128   // -----------------------------------
    129   if (lines.size() > 0) {
    130     for (int ic = 0; ic < _casters->size(); ic++) {
    131       _casters->at(ic)->uploadClockOrbitBias(_epoTime, _eph, lines);
    132     }
    133   }
    134 }
    135 
  • trunk/BNC/upload/bncrtnetdecoder.h

    r3203 r3206  
    3333#include "RTCM/GPSDecoder.h"
    3434
    35 class bncRtnetDecoder: public GPSDecoder, public bncEphUser, public QThread {
     35class bncRtnetDecoder: public GPSDecoder, public bncEphUser {
    3636 public:
    3737  bncRtnetDecoder();
    3838  ~bncRtnetDecoder();
    39   virtual void run();
    4039  virtual t_irc Decode(char* buffer, int bufLen,
    4140                       std::vector<std::string>& errmsg);
    4241 private:
    43   void DecodeInThread();
    44   QVector<bncUploadCaster*>* _casters;
    45   QString                    _buffer;
    46   bncTime                    _epoTime;
    47   QMutex                     _mutex;
     42  QVector<bncUploadCaster*> _casters;
    4843};
    4944
  • trunk/BNC/upload/bncuploadcaster.cpp

    r3192 r3206  
    3434                                 const QString& rnxFileName,
    3535                                 const QString& outFileName) {
    36 
    3736  bncSettings settings;
    3837
     
    181180    _t0  = settings.value("trafo_t0").toDouble();
    182181  }
     182 
     183  // Deep copy of ephemerides
     184  // ------------------------
     185  _ephMap = 0;
    183186}
    184187
     
    186189////////////////////////////////////////////////////////////////////////////
    187190bncUploadCaster::~bncUploadCaster() {
     191  if (_ephMap) {
     192    QMapIterator<QString, t_eph*> it(*_ephMap);
     193    while (it.hasNext()) {
     194      it.next();
     195      t_eph* eph = it.value();
     196      delete eph;
     197    }
     198    delete _ephMap;
     199  }
    188200  delete _outFile;
    189201  delete _rnx;
    190202  delete _sp3;
     203}
     204
     205// Endless Loop
     206////////////////////////////////////////////////////////////////////////////
     207void bncUploadCaster::run() {
     208  while (true) {
     209    uploadClockOrbitBias();
     210    msleep(10);
     211  }
    191212}
    192213
     
    260281}
    261282
    262 // Encode and Upload Clocks, Orbits, and Biases
    263 ////////////////////////////////////////////////////////////////////////////
    264 void bncUploadCaster::uploadClockOrbitBias(const bncTime& epoTime,
    265                             const QMap<QString, bncEphUser::t_ephPair*>& ephMap,
    266                             const QStringList& lines) {
     283//
     284////////////////////////////////////////////////////////////////////////////
     285void bncUploadCaster::decodeRtnetStream(char* buffer, int bufLen,
     286                      const QMap<QString, bncEphUser::t_ephPair*>& ephPairMap) {
     287                                       
     288  QMutexLocker locker(&_mutex);
     289
     290  // Delete old ephemeris
     291  // --------------------
     292  if (_ephMap) {
     293    QMapIterator<QString, t_eph*> it(*_ephMap);
     294    while (it.hasNext()) {
     295      it.next();
     296      t_eph* eph = it.value();
     297      delete eph;
     298    }
     299    delete _ephMap;
     300  }
     301  _ephMap = new QMap<QString, t_eph*>;
     302
     303  // Make a deep copy of ephemeris
     304  // -----------------------------
     305  QMapIterator<QString, bncEphUser::t_ephPair*> it(ephPairMap);
     306  while (it.hasNext()) {
     307    it.next();
     308    bncEphUser::t_ephPair* pair = it.value();
     309    t_eph* ep = pair->last;
     310    if (pair->prev && ep &&
     311        ep->receptDateTime().secsTo(QDateTime::currentDateTime()) < 60) {
     312      ep = pair->prev;
     313    }
     314    QString prn(ep->prn().c_str());
     315    if      (prn[0] == 'G') {
     316      t_ephGPS* epGPS = static_cast<t_ephGPS*>(ep);
     317      (*_ephMap)[prn] = new t_ephGPS(*epGPS);
     318    }
     319    else if (prn[0] == 'R') {
     320      t_ephGlo* epGlo = static_cast<t_ephGlo*>(ep);
     321      (*_ephMap)[prn] = new t_ephGlo(*epGlo);
     322    }
     323    else if (prn[0] == 'E') {
     324      t_ephGal* epGal = static_cast<t_ephGal*>(ep);
     325      (*_ephMap)[prn] = new t_ephGal(*epGal);
     326    }
     327  }
     328
     329  // Append to buffer
     330  // ----------------
     331  _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
     332}
     333
     334// Function called in separate thread
     335////////////////////////////////////////////////////////////////////////
     336void bncUploadCaster::uploadClockOrbitBias() {
     337
     338  QMutexLocker locker(&_mutex);
     339
     340  // Prepare list of lines with satellite positions in SP3-like format
     341  // -----------------------------------------------------------------
     342  QStringList lines;
     343  int iLast = _rtnetStreamBuffer.lastIndexOf('\n');
     344  if (iLast != -1) {
     345    QStringList hlpLines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
     346    _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLast+1);
     347    for (int ii = 0; ii < hlpLines.size(); ii++) {
     348      if      (hlpLines[ii].indexOf('*') != -1) {
     349        QTextStream in(hlpLines[ii].toAscii());
     350        QString hlp;
     351        int     year, month, day, hour, min;
     352        double  sec;
     353        in >> hlp >> year >> month >> day >> hour >> min >> sec;
     354        _epoTime.set( year, month, day, hour, min, sec);
     355      }
     356      else if (_epoTime.valid()) {
     357        lines << hlpLines[ii];
     358      }
     359    }
     360  }
     361
     362  if (lines.size() == 0) {
     363    return;
     364  }
     365
    267366  this->open();
    268367
    269368  unsigned year, month, day;
    270   epoTime.civil_date(year, month, day);
     369  _epoTime.civil_date(year, month, day);
    271370 
    272371  struct ClockOrbit co;
    273372  memset(&co, 0, sizeof(co));
    274   co.GPSEpochTime      = static_cast<int>(epoTime.gpssec());
    275   co.GLONASSEpochTime  = static_cast<int>(fmod(epoTime.gpssec(), 86400.0))
     373  co.GPSEpochTime      = static_cast<int>(_epoTime.gpssec());
     374  co.GLONASSEpochTime  = static_cast<int>(fmod(_epoTime.gpssec(), 86400.0))
    276375                       + 3 * 3600 - gnumleap(year, month, day);
    277376  co.ClockDataSupplied = 1;
     
    288387    QString      prn;
    289388    ColumnVector xx(14); xx = 0.0;
    290     bncEphUser::t_ephPair*   pair = 0;
    291389 
    292390    QTextStream in(lines[ii].toAscii());
     
    297395    }
    298396
    299     if ( ephMap.contains(prn) ) {
     397    if ( _ephMap->contains(prn) ) {
     398      t_eph* ep = (*_ephMap)[prn];
     399
    300400      in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5)
    301401         >> xx(6) >> xx(7) >> xx(8) >> xx(9) >> xx(10)
     
    314414      xx(14) *= 1e3;         // z-crd at time + dT
    315415 
    316       pair = ephMap[prn];
    317     }
    318  
    319     // Use old ephemeris if the new one is too recent
    320     // ----------------------------------------------
    321     t_eph* ep = 0;
    322     if (pair) {
    323       ep = pair->last;
    324       if (pair->prev && ep &&
    325           ep->receptDateTime().secsTo(QDateTime::currentDateTime()) < 60) {
    326         ep = pair->prev;
    327       }
    328     }
    329  
    330     if (ep != 0) {
    331416      struct ClockOrbit::SatData* sd = 0;
    332417      if      (prn[0] == 'G') {
     
    340425      if (sd) {
    341426        QString outLine;
    342         processSatellite(ep, epoTime.gpsw(), epoTime.gpssec(), prn, xx, sd, outLine);
     427        processSatellite(ep, _epoTime.gpsw(), _epoTime.gpssec(), prn, xx, sd, outLine);
    343428        if (_outFile) {
    344           _outFile->write(epoTime.gpsw(), epoTime.gpssec(), outLine);
     429          _outFile->write(_epoTime.gpsw(), _epoTime.gpssec(), outLine);
    345430        }
    346431      }
     
    386471  }
    387472 
    388   if ( this->usedSocket() &&
    389        (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
     473  if (_outSocket && (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0)) {
    390474    char obuffer[CLOCKORBIT_BUFFERSIZE];
    391475 
     
    396480  }
    397481 
    398   if ( this->usedSocket() &&
    399        (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) ) {
     482  if (_outSocket && (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0)) {
    400483    char obuffer[CLOCKORBIT_BUFFERSIZE];
    401484    int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
     
    527610  xyz = sc * rMat * xyz + dx;
    528611}
     612
  • trunk/BNC/upload/bncuploadcaster.h

    r3189 r3206  
    1010class bncSP3;
    1111
    12 class bncUploadCaster : public QObject {
     12class bncUploadCaster : public QThread {
    1313 Q_OBJECT
    1414 public:
     
    2121                  const QString& outFileName);
    2222  virtual ~bncUploadCaster();
    23   void open();
    24   void write(char* buffer, unsigned len);
    25   void printAscii(const QString& line);
    26   bool usedSocket() const {return _outSocket;}
    27   void uploadClockOrbitBias(const bncTime& epoTime,
    28                             const QMap<QString, bncEphUser::t_ephPair*>& ephMap,
    29                             const QStringList& lines);
     23  virtual void run();
     24  void decodeRtnetStream(char* buffer, int bufLen,
     25                         const QMap<QString, bncEphUser::t_ephPair*>& ephMap);
    3026
    3127 signals:
     
    3329
    3430 private:
     31  void open();
     32  void write(char* buffer, unsigned len);
     33  void uploadClockOrbitBias();
    3534  void processSatellite(t_eph* eph, int GPSweek,
    3635                        double GPSweeks, const QString& prn,
     
    3938                        QString& outLine);
    4039  void crdTrafo(int GPSWeek, ColumnVector& xyz);
     40
     41  QMap<QString, t_eph*>* _ephMap;
     42  QMutex                 _mutex; 
     43  QString                _rtnetStreamBuffer;
     44  bncTime                _epoTime;
    4145  QString        _mountpoint;
    4246  QString        _outHost;
Note: See TracChangeset for help on using the changeset viewer.