Changeset 3172 in ntrip


Ignore:
Timestamp:
Mar 29, 2011, 4:43:51 PM (13 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC/upload
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/upload/bncrtnetdecoder.cpp

    r3171 r3172  
    5858}
    5959
    60 // Decode Method
     60//
    6161////////////////////////////////////////////////////////////////////////
    6262void bncRtnetDecoder::readEpochTime(const QString& line) {
     
    7272
    7373  errmsg.clear();
    74 
    7574  _buffer.append(QByteArray(buffer, bufLen));
    7675
     76  // Prepare list of lines with satellite positions in SP3-like format
     77  // -----------------------------------------------------------------
     78  QStringList lines;
    7779  int iLast = _buffer.lastIndexOf('\n');
    78 
    7980  if (iLast != -1) {
    80     QStringList lines = _buffer.split('\n', QString::SkipEmptyParts);
     81    QStringList hlpLines = _buffer.split('\n', QString::SkipEmptyParts);
    8182    _buffer = _buffer.mid(iLast+1);
    82     cout << "number of lines = " << lines.size() << endl;
    83     for (int ii = 0; ii < lines.size(); ii++) {
    84       if (lines[ii].indexOf('*') != -1) {
    85         readEpochTime(lines[ii]);
    86         cout << "epoch: " << lines[ii].toAscii().data() << endl;
     83    for (int ii = 0; ii < hlpLines.size(); ii++) {
     84      if      (hlpLines[ii].indexOf('*') != -1) {
     85        readEpochTime(hlpLines[ii]);
    8786      }
    8887      else if (_year != 0) {
    89         cout << "pos: " << lines[ii].toAscii().data() << endl;
     88        lines << hlpLines[ii];
     89      }
     90    }
     91  }
     92
     93  // Satellite positions to be processed
     94  // -----------------------------------
     95  if (lines.size() > 0) {
     96
     97    QStringList prns;
     98
     99    for (int ic = 0; ic < _caster.size(); ic++) {
     100      _caster.at(ic)->open();
     101
     102      struct ClockOrbit co;
     103      memset(&co, 0, sizeof(co));
     104      co.GPSEpochTime      = (int)_GPSweeks;
     105      co.GLONASSEpochTime  = (int)fmod(_GPSweeks, 86400.0)
     106                           + 3 * 3600 - gnumleap(_year, _month, _day);
     107      co.ClockDataSupplied = 1;
     108      co.OrbitDataSupplied = 1;
     109      co.SatRefDatum       = DATUM_ITRF;
     110     
     111      struct Bias bias;
     112      memset(&bias, 0, sizeof(bias));
     113      bias.GPSEpochTime      = (int)_GPSweeks;
     114      bias.GLONASSEpochTime  = (int)fmod(_GPSweeks, 86400.0)
     115                             + 3 * 3600 - gnumleap(_year, _month, _day);
     116
     117      for (int ii = 0; ii < lines.size(); ii++) {
     118
     119        QString      prn;
     120        ColumnVector xx(14); xx = 0.0;
     121        t_ephPair*   pair = 0;
     122     
     123        if (ic == 0) {
     124          QTextStream in(lines[ii].toAscii());
     125          in >> prn;
     126          prns << prn;
     127          if ( _ephList.contains(prn) ) {
     128            in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5)
     129               >> xx(6) >> xx(7) >> xx(8) >> xx(9) >> xx(10)
     130               >> xx(11) >> xx(12) >> xx(13) >> xx(14);
     131            xx(1) *= 1e3;          // x-crd
     132            xx(2) *= 1e3;          // y-crd
     133            xx(3) *= 1e3;          // z-crd
     134            xx(4) *= 1e-6;         // clk
     135            xx(5) *= 1e-6;         // rel. corr.
     136                                   // xx(6), xx(7), xx(8) ... PhaseCent - CoM
     137                                   // xx(9)  ... P1-C1 DCB in meters
     138                                   // xx(10) ... P1-P2 DCB in meters
     139                                   // xx(11) ... dT
     140            xx(12) *= 1e3;         // x-crd at time + dT
     141            xx(13) *= 1e3;         // y-crd at time + dT
     142            xx(14) *= 1e3;         // z-crd at time + dT
     143
     144            pair     = _ephList[prn];
     145            pair->xx = xx;
     146          }
     147        }
     148        else {
     149          prn = prns[ii];
     150          if ( _ephList.contains(prn) ) {
     151            pair = _ephList[prn];
     152            xx   = pair->xx;
     153          }
     154        }
     155
     156        // Use old ephemeris if the new one is too recent
     157        // ----------------------------------------------
     158        t_eph* ep = 0;
     159        if (pair) {
     160          ep = pair->eph;
     161          if (pair->oldEph && ep &&
     162              ep->receptDateTime().secsTo(QDateTime::currentDateTime()) < 60) {
     163            ep = pair->oldEph;
     164          }
     165        }
     166
     167        if (ep != 0) {
     168          struct ClockOrbit::SatData* sd = 0;
     169          if      (prn[0] == 'G') {
     170            sd = co.Sat + co.NumberOfGPSSat;
     171            ++co.NumberOfGPSSat;
     172          }
     173          else if (prn[0] == 'R') {
     174            sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
     175            ++co.NumberOfGLONASSSat;
     176          }
     177          if (sd) {
     178            QString outLine;
     179            processSatellite(ic, _caster.at(ic)->crdTrafo(),
     180                             _caster.at(ic)->CoM(), ep,
     181                             _GPSweek, _GPSweeks, prn, xx, sd, outLine);
     182            _caster.at(ic)->printAscii(outLine);
     183          }
     184
     185          struct Bias::BiasSat* biasSat = 0;
     186          if      (prn[0] == 'G') {
     187            biasSat = bias.Sat + bias.NumberOfGPSSat;
     188            ++bias.NumberOfGPSSat;
     189          }
     190          else if (prn[0] == 'R') {
     191            biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfGLONASSSat;
     192            ++bias.NumberOfGLONASSSat;
     193          }
     194
     195          // Coefficient of Ionosphere-Free LC
     196          // ---------------------------------
     197          const static double a_L1_GPS =  2.54572778;
     198          const static double a_L2_GPS = -1.54572778;
     199          const static double a_L1_Glo =  2.53125000;
     200          const static double a_L2_Glo = -1.53125000;
     201
     202          if (biasSat) {
     203            biasSat->ID = prn.mid(1).toInt();
     204            biasSat->NumberOfCodeBiases = 3;
     205            if      (prn[0] == 'G') {
     206              biasSat->Biases[0].Type = CODETYPEGPS_L1_Z;
     207              biasSat->Biases[0].Bias = - a_L2_GPS * xx(10);
     208              biasSat->Biases[1].Type = CODETYPEGPS_L1_CA;
     209              biasSat->Biases[1].Bias = - a_L2_GPS * xx(10) + xx(9);
     210              biasSat->Biases[2].Type = CODETYPEGPS_L2_Z;
     211              biasSat->Biases[2].Bias = a_L1_GPS * xx(10);
     212            }
     213            else if (prn[0] == 'R') {
     214              biasSat->Biases[0].Type = CODETYPEGLONASS_L1_P;
     215              biasSat->Biases[0].Bias = - a_L2_Glo * xx(10);
     216              biasSat->Biases[1].Type = CODETYPEGLONASS_L1_CA;
     217              biasSat->Biases[1].Bias = - a_L2_Glo * xx(10) + xx(9);
     218              biasSat->Biases[2].Type = CODETYPEGLONASS_L2_P;
     219              biasSat->Biases[2].Bias = a_L1_Glo * xx(10);
     220            }
     221          }
     222        }
     223      }
     224     
     225      if ( _caster.at(ic)->usedSocket() &&
     226           (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
     227        char obuffer[CLOCKORBIT_BUFFERSIZE];
     228
     229        int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
     230        if (len > 0) {
     231          if (_caster.at(ic)->ic() == 1)  { emit(newOutBytes1(len));}
     232          if (_caster.at(ic)->ic() == 2)  { emit(newOutBytes2(len));}
     233          if (_caster.at(ic)->ic() == 3)  { emit(newOutBytes3(len));}
     234          if (_caster.at(ic)->ic() == 4)  { emit(newOutBytes4(len));}
     235          if (_caster.at(ic)->ic() == 5)  { emit(newOutBytes5(len));}
     236          if (_caster.at(ic)->ic() == 6)  { emit(newOutBytes6(len));}
     237          if (_caster.at(ic)->ic() == 7)  { emit(newOutBytes7(len));}
     238          if (_caster.at(ic)->ic() == 8)  { emit(newOutBytes8(len));}
     239          if (_caster.at(ic)->ic() == 9)  { emit(newOutBytes9(len));}
     240          if (_caster.at(ic)->ic() == 10) { emit(newOutBytes10(len));}
     241          _caster.at(ic)->write(obuffer, len);
     242        }
     243      }
     244
     245      if ( _caster.at(ic)->usedSocket() &&
     246           (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) ) {
     247        char obuffer[CLOCKORBIT_BUFFERSIZE];
     248        int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
     249        if (len > 0) {
     250          _caster.at(ic)->write(obuffer, len);
     251        }
    90252      }
    91253    }
     
    95257}
    96258
     259//
     260////////////////////////////////////////////////////////////////////////////
     261void bncRtnetDecoder::processSatellite(int iCaster, const QString trafo,
     262                                       bool CoM, t_eph* ep, int GPSweek,
     263                                       double GPSweeks, const QString& prn,
     264                                       const ColumnVector& xx,
     265                                       struct ClockOrbit::SatData* sd,
     266                                       QString& outLine) {
     267
     268  const double secPerWeek = 7.0 * 86400.0;
     269
     270  ColumnVector rsw(3);
     271  ColumnVector rsw2(3);
     272  double dClk;
     273
     274  for (int ii = 1; ii <= 2; ++ii) {
     275
     276    int    GPSweek12  = GPSweek;
     277    double GPSweeks12 = GPSweeks;
     278    if (ii == 2) {
     279      GPSweeks12 += xx(11);
     280      if (GPSweeks12 > secPerWeek) {
     281        GPSweek12  += 1;
     282        GPSweeks12 -= secPerWeek;
     283      }
     284    }
     285
     286    ColumnVector xB(4);
     287    ColumnVector vv(3);
     288
     289    ep->position(GPSweek12, GPSweeks12, xB, vv);
     290   
     291    ColumnVector xyz;
     292    if (ii == 1) {
     293      xyz = xx.Rows(1,3);
     294    }
     295    else {
     296      xyz = xx.Rows(12,14);
     297    }
     298   
     299    // Correction Center of Mass -> Antenna Phase Center
     300    // -------------------------------------------------
     301    if (! CoM) {
     302      xyz(1) += xx(6);
     303      xyz(2) += xx(7);
     304      xyz(3) += xx(8);
     305    }
     306   
     307    if (trafo != "IGS05") {
     308      crdTrafo(GPSweek12, xyz, trafo);
     309    }
     310   
     311    ColumnVector dx = xB.Rows(1,3) - xyz ;
     312   
     313    if (ii == 1) {
     314      XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw);
     315      dClk = (xx(4) + xx(5) - xB(4)) * 299792458.0;
     316    }
     317    else {
     318      XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw2);
     319    }
     320  }
     321
     322  if (sd) {
     323    sd->ID                    = prn.mid(1).toInt();
     324    sd->IOD                   = ep->IOD();
     325    sd->Clock.DeltaA0         = dClk;
     326    sd->Orbit.DeltaRadial     = rsw(1);
     327    sd->Orbit.DeltaAlongTrack = rsw(2);
     328    sd->Orbit.DeltaCrossTrack = rsw(3);
     329    sd->Orbit.DotDeltaRadial     = (rsw2(1) - rsw(1)) / xx(11);
     330    sd->Orbit.DotDeltaAlongTrack = (rsw2(2) - rsw(2)) / xx(11);
     331    sd->Orbit.DotDeltaCrossTrack = (rsw2(3) - rsw(3)) / xx(11);
     332  }
     333
     334  outLine.sprintf("%d %.1f %s  %3d  %10.3f  %8.3f %8.3f %8.3f\n",
     335                  GPSweek, GPSweeks, ep->prn().toAscii().data(),
     336                  ep->IOD(), dClk, rsw(1), rsw(2), rsw(3));
     337
     338  if (iCaster == 0) {
     339    if (_rnx) {
     340      _rnx->write(GPSweek, GPSweeks, prn, xx);
     341    }
     342    if (_sp3) {
     343      _sp3->write(GPSweek, GPSweeks, prn, xx, _append);
     344    }
     345  }
     346}
     347
     348// Transform Coordinates
     349////////////////////////////////////////////////////////////////////////////
     350void bncRtnetDecoder::crdTrafo(int GPSWeek, ColumnVector& xyz,
     351                               const QString& trafo) {
     352
     353  bnsSettings settings;
     354
     355  if (trafo == "ETRF2000") {
     356    _dx  =    0.0541;
     357    _dy  =    0.0502;
     358    _dz  =   -0.0538;
     359    _dxr =   -0.0002;
     360    _dyr =    0.0001;
     361    _dzr =   -0.0018;
     362    _ox  =  0.000891;
     363    _oy  =  0.005390;
     364    _oz  = -0.008712;
     365    _oxr =  0.000081;
     366    _oyr =  0.000490;
     367    _ozr = -0.000792;
     368    _sc  =      0.40;
     369    _scr =      0.08;
     370    _t0  =    2000.0;
     371  }
     372  else if (trafo == "NAD83") {
     373    _dx  =    0.9963;
     374    _dy  =   -1.9024;
     375    _dz  =   -0.5210;
     376    _dxr =    0.0005;
     377    _dyr =   -0.0006;
     378    _dzr =   -0.0013;
     379    _ox  =  0.025915;
     380    _oy  =  0.009426;
     381    _oz  =  0.011599;
     382    _oxr =  0.000067;
     383    _oyr = -0.000757;
     384    _ozr = -0.000051;
     385    _sc  =      0.78;
     386    _scr =     -0.10;
     387    _t0  =    1997.0;
     388  }
     389  else if (trafo == "GDA94") {
     390    _dx  =   -0.07973;
     391    _dy  =   -0.00686;
     392    _dz  =    0.03803;
     393    _dxr =    0.00225;
     394    _dyr =   -0.00062;
     395    _dzr =   -0.00056;
     396    _ox  =  0.0000351;
     397    _oy  = -0.0021211;
     398    _oz  = -0.0021411;
     399    _oxr = -0.0014707;
     400    _oyr = -0.0011443;
     401    _ozr = -0.0011701;
     402    _sc  =      6.636;
     403    _scr =      0.294;
     404    _t0  =     1994.0;
     405  }
     406  else if (trafo == "SIRGAS2000") {
     407    _dx  =   -0.0051;
     408    _dy  =   -0.0065;
     409    _dz  =   -0.0099;
     410    _dxr =    0.0000;
     411    _dyr =    0.0000;
     412    _dzr =    0.0000;
     413    _ox  =  0.000150;
     414    _oy  =  0.000020;
     415    _oz  =  0.000021;
     416    _oxr =  0.000000;
     417    _oyr =  0.000000;
     418    _ozr =  0.000000;
     419    _sc  =     0.000;
     420    _scr =     0.000;
     421    _t0  =    0000.0;
     422  }
     423  else if (trafo == "SIRGAS95") {
     424    _dx  =    0.0077;
     425    _dy  =    0.0058;
     426    _dz  =   -0.0138;
     427    _dxr =    0.0000;
     428    _dyr =    0.0000;
     429    _dzr =    0.0000;
     430    _ox  =  0.000000;
     431    _oy  =  0.000000;
     432    _oz  = -0.000030;
     433    _oxr =  0.000000;
     434    _oyr =  0.000000;
     435    _ozr =  0.000000;
     436    _sc  =     1.570;
     437    _scr =     0.000;
     438    _t0  =    0000.0;
     439  }
     440  else if (trafo == "Custom") {
     441    _dx  = settings.value("trafo_dx").toDouble();
     442    _dy  = settings.value("trafo_dy").toDouble();
     443    _dz  = settings.value("trafo_dz").toDouble();
     444    _dxr = settings.value("trafo_dxr").toDouble();
     445    _dyr = settings.value("trafo_dyr").toDouble();
     446    _dzr = settings.value("trafo_dzr").toDouble();
     447    _ox  = settings.value("trafo_ox").toDouble();
     448    _oy  = settings.value("trafo_oy").toDouble();
     449    _oz  = settings.value("trafo_oz").toDouble();
     450    _oxr = settings.value("trafo_oxr").toDouble();
     451    _oyr = settings.value("trafo_oyr").toDouble();
     452    _ozr = settings.value("trafo_ozr").toDouble();
     453    _sc  = settings.value("trafo_sc").toDouble();
     454    _scr = settings.value("trafo_scr").toDouble();
     455    _t0  = settings.value("trafo_t0").toDouble();
     456  }
     457
     458  // Current epoch minus 2000.0 in years
     459  // ------------------------------------
     460  double dt = (GPSWeek - (1042.0+6.0/7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
     461
     462  ColumnVector dx(3);
     463
     464  dx(1) = _dx + dt * _dxr;
     465  dx(2) = _dy + dt * _dyr;
     466  dx(3) = _dz + dt * _dzr;
     467
     468  static const double arcSec = 180.0 * 3600.0 / M_PI;
     469
     470  double ox = (_ox + dt * _oxr) / arcSec;
     471  double oy = (_oy + dt * _oyr) / arcSec;
     472  double oz = (_oz + dt * _ozr) / arcSec;
     473
     474  double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
     475
     476  Matrix rMat(3,3);
     477  rMat(1,1) = 1.0;
     478  rMat(1,2) = -oz;
     479  rMat(1,3) =  oy;
     480  rMat(2,1) =  oz;
     481  rMat(2,2) = 1.0;
     482  rMat(2,3) = -ox;
     483  rMat(3,1) = -oy;
     484  rMat(3,2) =  ox;
     485  rMat(3,3) = 1.0;
     486
     487  xyz = sc * rMat * xyz + dx;
     488}
  • trunk/BNC/upload/bncrtnetdecoder.h

    r3171 r3172  
    3838 private:
    3939  void readEpochTime(const QString& line);
     40  void processSatellite(int iCaster, const QString trafo,
     41                        bool CoM, t_eph* ep, int GPSweek,
     42                        double GPSweeks, const QString& prn,
     43                        const ColumnVector& xx,
     44                        struct ClockOrbit::SatData* sd,
     45                        QString& outLine);
     46  void crdTrafo(int GPSWeek, ColumnVector& xyz,
     47                const QString& trafo);
    4048
    4149  QString _buffer;
Note: See TracChangeset for help on using the changeset viewer.