Ignore:
Timestamp:
Sep 13, 2014, 5:08:22 PM (10 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/RTCM3/RTCM3coDecoder.cpp

    r5665 r6141  
    6969    _fileNameSkl = path + staID;
    7070  }
    71   _out      = 0;
    72   _GPSweeks = -1.0;
     71  _out = 0;
    7372
    7473  qRegisterMetaType<bncTime>("bncTime");
    75 
    76   connect(this, SIGNAL(newCorrLine(QString, QString, bncTime)),
    77           BNC_CORE, SLOT(slotNewCorrLine(QString, QString, bncTime)));
     74  qRegisterMetaType< QList<t_orbCorr> >("QList:t_orbCorr");
     75  qRegisterMetaType< QList<t_clkCorr> >("QList:t_clkCorr");
     76
     77  connect(this, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
     78          BNC_CORE, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
     79
     80  connect(this, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
     81          BNC_CORE, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
    7882
    7983  connect(this, SIGNAL(providerIDChanged(QString)),
     
    99103// Reopen Output File
    100104////////////////////////////////////////////////////////////////////////
    101 void RTCM3coDecoder::reopen(const QString& fileNameSkl, QString& fileName,
    102                             ofstream*& out) {
    103 
    104   if (!fileNameSkl.isEmpty()) {
     105void RTCM3coDecoder::reopen() {
     106
     107  if (!_fileNameSkl.isEmpty()) {
    105108
    106109    bncSettings settings;
     
    111114                                      settings.value("corrIntr").toString());
    112115
    113     QString fileNameHlp = fileNameSkl
     116    QString fileNameHlp = _fileNameSkl
    114117      + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
    115118      + hlpStr + datTim.toString(".yyC");
    116119
    117     if (fileName == fileNameHlp) {
     120    if (_fileName == fileNameHlp) {
    118121      return;
    119122    }
    120123    else {
    121       fileName = fileNameHlp;
    122     }
    123 
    124     delete out;
     124      _fileName = fileNameHlp;
     125    }
     126
     127    delete _out;
    125128    if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
    126       out = new ofstream( fileName.toAscii().data(),
    127                            ios_base::out | ios_base::app );
     129      _out = new ofstream( _fileName.toAscii().data(), ios_base::out | ios_base::app );
    128130    }
    129131    else {
    130       out = new ofstream( fileName.toAscii().data() );
     132      _out = new ofstream( _fileName.toAscii().data() );
    131133    }
    132134  }
     
    170172            _bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0 || _bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) ) {
    171173
    172         reopen(_fileNameSkl, _fileName, _out);
     174        reopen();
    173175
    174176        // Guess GPS week and sec using system time
     
    189191            GPSweek -= 1;
    190192          }
    191           _GPSweeks = GPSEpochTime;
     193          _lastTime.set(GPSweek, double(GPSEpochTime));
    192194        }
    193195
     
    223225            }
    224226          }
    225 
    226           _GPSweeks = weekDay * 86400.0 + GPSDaySec;
     227          _lastTime.set(GPSweek, weekDay * 86400.0 + GPSDaySec);
    227228        }
    228229
    229230        checkProviderID();
    230231
    231         QStringList asciiLines = corrsToASCIIlines(GPSweek, _GPSweeks,
    232                                                    _co, &_bias);
    233 
    234         QStringListIterator it(asciiLines);
    235         while (it.hasNext()) {
    236           QString line = it.next();
    237           printLine(line, GPSweek, _GPSweeks);
    238         }
     232        sendResults();
    239233
    240234        retCode = success;
     235
    241236        memset(&_co, 0, sizeof(_co));
    242237        memset(&_bias, 0, sizeof(_bias));
     
    245240  }
    246241
    247   if (retCode != success) {
    248     _GPSweeks = -1.0;
    249   }
    250242  return retCode;
    251243}
     
    253245//
    254246////////////////////////////////////////////////////////////////////////////
    255 void RTCM3coDecoder::printLine(const QString& line, int GPSweek,
    256                                double GPSweeks) {
    257   if (_out) {
    258     *_out << line.toAscii().data() << endl;
    259     _out->flush();
    260   }
    261 
    262   int    currWeek;
    263   double currSec;
    264   currentGPSWeeks(currWeek, currSec);
    265   bncTime currTime(currWeek, currSec);
    266 
    267   bncTime coTime(GPSweek, GPSweeks);
    268 
    269   double dt = currTime - coTime;
    270   const double MAXDT = 10 * 60.0;
    271   if (fabs(dt) > MAXDT) {
    272     emit newMessage("suspicious correction: " + _staID.toAscii() + " "
    273                     + line.toAscii(), false);
    274   }
    275   else {
    276     emit newCorrLine(line, _staID, coTime);
    277   }
    278 }
    279 
    280 //
    281 ////////////////////////////////////////////////////////////////////////////
    282 QStringList RTCM3coDecoder::corrsToASCIIlines(int GPSweek, double GPSweeks,
    283                                               const ClockOrbit& co,
    284                                               const CodeBias* bias) {
    285 
    286   QStringList retLines;
     247void RTCM3coDecoder::sendResults() {
     248
     249  QList<t_orbCorr> orbCorrections;
     250  QList<t_clkCorr> clkCorrections;
    287251
    288252  // Loop over all satellites (GPS and Glonass)
    289253  // ------------------------------------------
    290   if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
    291     QString line1;
    292     line1.sprintf("! Orbits/Clocks: %d GPS %d Glonass",
    293                   co.NumberOfSat[CLOCKORBIT_SATGPS], co.NumberOfSat[CLOCKORBIT_SATGLONASS]);
    294     retLines << line1;
    295   }
    296   for (int ii = 0; ii < CLOCKORBIT_NUMGPS+co.NumberOfSat[CLOCKORBIT_SATGLONASS]; ii++) {
     254  for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS + _co.NumberOfSat[CLOCKORBIT_SATGLONASS]; ii++) {
    297255    char sysCh = ' ';
    298     if      (ii < co.NumberOfSat[CLOCKORBIT_SATGPS]) {
     256    if      (ii < _co.NumberOfSat[CLOCKORBIT_SATGPS]) {
    299257      sysCh = 'G';
    300258    }
     
    302260      sysCh = 'R';
    303261    }
    304 
    305     if (sysCh != ' ') {
    306 
    307       QString linePart;
    308       linePart.sprintf("%d %d %d %.1f %c%2.2d",
    309                        co.messageType, co.UpdateInterval, GPSweek, GPSweeks,
    310                        sysCh, co.Sat[ii].ID);
    311 
    312       // Combined message (orbit and clock)
    313       // ----------------------------------
    314       if ( co.messageType == COTYPE_GPSCOMBINED     ||
    315            co.messageType == COTYPE_GLONASSCOMBINED ) {
    316         QString line;
    317         line.sprintf("   %3d"
    318                      "   %8.3f %8.3f %8.3f %8.3f"
    319                      "   %10.5f %10.5f %10.5f %10.5f"
    320                      "   %10.5f",
    321                      co.Sat[ii].IOD,
    322                      co.Sat[ii].Clock.DeltaA0,
    323                      co.Sat[ii].Orbit.DeltaRadial,
    324                      co.Sat[ii].Orbit.DeltaAlongTrack,
    325                      co.Sat[ii].Orbit.DeltaCrossTrack,
    326                      co.Sat[ii].Clock.DeltaA1,
    327                      co.Sat[ii].Orbit.DotDeltaRadial,
    328                      co.Sat[ii].Orbit.DotDeltaAlongTrack,
    329                      co.Sat[ii].Orbit.DotDeltaCrossTrack,
    330                      co.Sat[ii].Clock.DeltaA2);
    331         retLines << linePart+line;
     262    else {
     263      continue;
     264    }
     265
     266    // Orbit correction
     267    // ----------------
     268    if ( _co.messageType == COTYPE_GPSCOMBINED     ||
     269         _co.messageType == COTYPE_GLONASSCOMBINED ||
     270         _co.messageType == COTYPE_GPSORBIT        ||
     271         _co.messageType == COTYPE_GLONASSORBIT    ) {
     272
     273      t_orbCorr orbCorr;
     274      orbCorr._prn.set(sysCh, _co.Sat[ii].ID);
     275      orbCorr._staID    = _staID.toAscii().data();
     276      orbCorr._iod      = _co.Sat[ii].IOD;
     277      orbCorr._time     = _lastTime;
     278      orbCorr._system   = 'R';
     279      orbCorr._xr[0]    = _co.Sat[ii].Orbit.DeltaRadial;
     280      orbCorr._xr[1]    = _co.Sat[ii].Orbit.DeltaAlongTrack;
     281      orbCorr._xr[2]    = _co.Sat[ii].Orbit.DeltaCrossTrack;
     282      orbCorr._dotXr[0] = _co.Sat[ii].Orbit.DotDeltaRadial;
     283      orbCorr._dotXr[1] = _co.Sat[ii].Orbit.DotDeltaAlongTrack;
     284      orbCorr._dotXr[2] = _co.Sat[ii].Orbit.DotDeltaCrossTrack;
     285
     286      orbCorrections.push_back(orbCorr);
     287
     288      _IODs[orbCorr._prn.toString()] = _co.Sat[ii].IOD;
     289    }
     290
     291    if ( _co.messageType == COTYPE_GPSCOMBINED     ||
     292         _co.messageType == COTYPE_GLONASSCOMBINED ||
     293         _co.messageType == COTYPE_GPSCLOCK        ||
     294         _co.messageType == COTYPE_GLONASSCLOCK    ) {
     295
     296      t_clkCorr clkCorr;
     297      clkCorr._prn.set(sysCh, _co.Sat[ii].ID);
     298      clkCorr._staID      = _staID.toAscii().data();
     299      clkCorr._time       = _lastTime;
     300      clkCorr._dClk       = _co.Sat[ii].Clock.DeltaA0,
     301      clkCorr._dotDClk    = _co.Sat[ii].Clock.DeltaA1,
     302      clkCorr._dotDotDClk = _co.Sat[ii].Clock.DeltaA2;
     303      clkCorr._clkPartial = 0.0;
     304
     305      if (_IODs.contains(clkCorr._prn.toString())) {
     306        clkCorr._iod = _IODs[clkCorr._prn.toString()];
     307        clkCorrections.push_back(clkCorr);
    332308      }
    333 
    334       // Orbits only
    335       // -----------
    336       else if ( co.messageType == COTYPE_GPSORBIT     ||
    337                 co.messageType == COTYPE_GLONASSORBIT ) {
    338         QString line;
    339         line.sprintf("   %3d"
    340                      "   %8.3f %8.3f %8.3f"
    341                      "   %10.5f %10.5f %10.5f",
    342                      co.Sat[ii].IOD,
    343                      co.Sat[ii].Orbit.DeltaRadial,
    344                      co.Sat[ii].Orbit.DeltaAlongTrack,
    345                      co.Sat[ii].Orbit.DeltaCrossTrack,
    346                      co.Sat[ii].Orbit.DotDeltaRadial,
    347                      co.Sat[ii].Orbit.DotDeltaAlongTrack,
    348                      co.Sat[ii].Orbit.DotDeltaCrossTrack);
    349         retLines << linePart+line;
    350       }
    351 
    352       // Clocks only
    353       // -----------
    354       else if ( co.messageType == COTYPE_GPSCLOCK     ||
    355                 co.messageType == COTYPE_GLONASSCLOCK ) {
    356         QString line;
    357         line.sprintf("   %8.3f   %10.5f   %10.5f",
    358                      co.Sat[ii].Clock.DeltaA0,
    359                      co.Sat[ii].Clock.DeltaA1,
    360                      co.Sat[ii].Clock.DeltaA2);
    361         retLines << linePart+line;
    362       }
    363 
    364       // User Range Accuracy
    365       // -------------------
    366       else if ( co.messageType == COTYPE_GPSURA     ||
    367                 co.messageType == COTYPE_GLONASSURA ) {
    368         QString line;
    369         line.sprintf("   %f", co.Sat[ii].UserRangeAccuracy);
    370         retLines << linePart+line;
    371       }
    372 
    373       // High-Resolution Clocks
    374       // ----------------------
    375       else if ( co.messageType == COTYPE_GPSHR     ||
    376                 co.messageType == COTYPE_GLONASSHR ) {
    377         QString line;
    378         line.sprintf("   %8.3f", co.Sat[ii].hrclock);
    379         retLines << linePart+line;
    380       }
     309    }
     310
     311    // High-Resolution Clocks
     312    // ----------------------
     313    if ( _co.messageType == COTYPE_GPSHR     ||
     314         _co.messageType == COTYPE_GLONASSHR ) {
    381315    }
    382316  }
     
    384318  // Loop over all satellites (GPS and Glonass)
    385319  // ------------------------------------------
    386   if (bias) {
    387     if (bias->NumberOfSat[CLOCKORBIT_SATGPS] > 0 || bias->NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
    388       QString line1;
    389       line1.sprintf("! Biases: %d GPS %d Glonass",
    390                     bias->NumberOfSat[CLOCKORBIT_SATGPS], bias->NumberOfSat[CLOCKORBIT_SATGLONASS]);
    391       retLines << line1;
    392     }
    393     for (int ii = 0; ii < CLOCKORBIT_NUMGPS + bias->NumberOfSat[CLOCKORBIT_SATGLONASS]; ii++) {
    394       char sysCh = ' ';
    395       int messageType;
    396       if      (ii < bias->NumberOfSat[CLOCKORBIT_SATGPS]) {
    397         sysCh = 'G';
    398         messageType = BTYPE_GPS;
    399       }
    400       else if (ii >= CLOCKORBIT_NUMGPS) {
    401         sysCh = 'R';
    402         messageType = BTYPE_GLONASS;
    403       }
    404       if (sysCh != ' ') {
    405         QString line;
    406         line.sprintf("%d %d %d %.1f %c%2.2d %d",
    407                      messageType, bias->UpdateInterval, GPSweek, GPSweeks,
    408                      sysCh, bias->Sat[ii].ID,
    409                      bias->Sat[ii].NumberOfCodeBiases);
    410         for (int jj = 0; jj < bias->Sat[ii].NumberOfCodeBiases; jj++) {
    411           QString hlp;
    412           hlp.sprintf(" %d %8.3f",  bias->Sat[ii].Biases[jj].Type,
    413                       bias->Sat[ii].Biases[jj].Bias);
    414           line += hlp;
    415         }
    416         retLines << line;
    417       }
    418     }
    419   }
    420 
    421   return retLines;
     320  QList<t_satBias> satBiases;
     321  for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS + _bias.NumberOfSat[CLOCKORBIT_SATGLONASS]; ii++) {
     322    char sysCh = ' ';
     323    if      (ii < _bias.NumberOfSat[CLOCKORBIT_SATGPS]) {
     324      sysCh = 'G';
     325    }
     326    else if (ii >= CLOCKORBIT_NUMGPS) {
     327      sysCh = 'R';
     328    }
     329    else {
     330      continue;
     331    }
     332    t_satBias satBias;
     333    satBias._prn.set(sysCh, _bias.Sat[ii].ID);
     334    satBias._time      = _lastTime;
     335    satBias._nx        = 0;
     336    satBias._jumpCount = 0;
     337    for (unsigned jj = 0; jj < _bias.Sat[ii].NumberOfCodeBiases; jj++) {
     338    }
     339  }
     340
     341  if (orbCorrections.size() > 0) {
     342    emit newOrbCorrections(orbCorrections);
     343  }
     344  if (clkCorrections.size() > 0) {
     345    emit newClkCorrections(clkCorrections);
     346  }
     347  if (_out) {
     348    QListIterator<t_orbCorr> itOrb(orbCorrections);
     349    while (itOrb.hasNext()) {
     350      const t_orbCorr& orbCorr = itOrb.next();
     351      *_out << "O " << orbCorr.toString() << endl;
     352    }
     353    QListIterator<t_clkCorr> itClk(clkCorrections);
     354    while (itClk.hasNext()) {
     355      const t_clkCorr& clkCorr = itClk.next();
     356      *_out << "C " << clkCorr.toString() << endl;
     357    }
     358    _out->flush();
     359  }
    422360}
    423361
Note: See TracChangeset for help on using the changeset viewer.