Ignore:
Timestamp:
Mar 30, 2011, 6:20:17 PM (13 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.