Changeset 3255 in ntrip


Ignore:
Timestamp:
Apr 3, 2011, 1:18:26 PM (13 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/RTCM3/RTCM3Decoder.cpp

    r3008 r3255  
    446446  double weekold = 0.0;
    447447  double weeknew = gpseph.GPSweek() + gpseph.GPSweeks() / secPerWeek;
    448   if ( _ephList.find(gpseph.prn()) != _ephList.end() ) {
    449     weekold = _ephList.find(gpseph.prn())->second.GPSweek()
    450             + _ephList.find(gpseph.prn())->second.GPSweeks() / secPerWeek;
     448  string prn = gpseph.prn().toAscii().data();
     449  if ( _ephList.find(prn) != _ephList.end() ) {
     450    weekold = _ephList.find(prn)->second.GPSweek()
     451            + _ephList.find(prn)->second.GPSweeks() / secPerWeek;
    451452  }
    452453
    453454  if ( weeknew - weekold > 1.0/secPerWeek ) {
    454     _ephList[gpseph.prn()] = gpseph;
     455    _ephList[prn] = gpseph;
    455456
    456457    return true;
  • trunk/BNC/RTCM3/ephemeris.cpp

    r2771 r3255  
    1414using namespace std;
    1515
     16#define PI          3.1415926535898
     17// Returns nearest integer value
     18////////////////////////////////////////////////////////////////////////////
     19static double NearestInt(double fl, double * remain)
     20{
     21  bool isneg = fl < 0.0;
     22  double intval;
     23  if(isneg) fl *= -1.0;
     24  intval = (double)((unsigned long)(fl+0.5));
     25  if(isneg) {fl *= -1.0; intval *= -1.0;}
     26  if(remain)
     27    *remain = fl-intval;
     28  return intval;
     29} /* NearestInt() */
     30
     31// Returns CRC24
     32////////////////////////////////////////////////////////////////////////////
     33static unsigned long CRC24(long size, const unsigned char *buf)
     34{
     35  unsigned long crc = 0;
     36  int i;
     37
     38  while(size--)
     39  {
     40    crc ^= (*buf++) << (16);
     41    for(i = 0; i < 8; i++)
     42    {
     43      crc <<= 1;
     44      if(crc & 0x1000000)
     45        crc ^= 0x01864cfb;
     46    }
     47  }
     48  return crc;
     49} /* CRC24 */
     50
    1651//
    1752////////////////////////////////////////////////////////////////////////////
     
    2964////////////////////////////////////////////////////////////////////////////
    3065void t_ephGPS::set(const gpsephemeris* ee) {
    31   ostringstream prn;
    32   prn << 'G' << setfill('0') << setw(2) << ee->satellite;
    33 
    34   _prn = prn.str();
     66
     67  _prn = QString("G%1").arg(ee->satellite, 2, 10, QChar('0'));
    3568
    3669  // TODO: check if following two lines are correct
     
    154187}
    155188
     189// build up RTCM3 for GPS
     190////////////////////////////////////////////////////////////////////////////
     191#define GPSTOINT(type, value) static_cast<type>(NearestInt(value,0))
     192
     193#define GPSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
     194                       |(GPSTOINT(long long,b)&((1ULL<<a)-1)); \
     195                       numbits += (a); \
     196                       while(numbits >= 8) { \
     197                       buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
     198#define GPSADDBITSFLOAT(a,b,c) {long long i = GPSTOINT(long long,(b)/(c)); \
     199                             GPSADDBITS(a,i)};
     200
     201int t_ephGPS::RTCM3(unsigned char *buffer)
     202{
     203
     204  unsigned char *startbuffer = buffer;
     205  buffer= buffer+3;
     206  int size = 0;
     207  int numbits = 0;
     208  unsigned long long bitbuffer = 0;
     209  if (_ura <= 2.40){
     210    _ura = 0;
     211  }
     212  else if (_ura <= 3.40){
     213    _ura = 1;
     214  }
     215  else if (_ura <= 6.85){
     216    _ura = 2;
     217  }
     218  else if (_ura <= 9.65){
     219    _ura = 3;
     220  }
     221  else if (_ura <= 13.65){
     222    _ura = 4;
     223  }
     224  else if (_ura <= 24.00){
     225    _ura = 5;
     226  }
     227  else if (_ura <= 48.00){
     228    _ura = 6;
     229  }
     230  else if (_ura <= 96.00){
     231    _ura = 7;
     232  }
     233  else if (_ura <= 192.00){
     234    _ura = 8;
     235  }
     236  else if (_ura <= 384.00){
     237    _ura = 9;
     238  }
     239  else if (_ura <= 768.00){
     240    _ura = 10;
     241  }
     242  else if (_ura <= 1536.00){
     243    _ura = 11;
     244  }
     245  else if (_ura <= 1536.00){
     246    _ura = 12;
     247  }
     248  else if (_ura <= 2072.00){
     249    _ura = 13;
     250  }
     251  else if (_ura <= 6144.00){
     252    _ura = 14;
     253  }
     254  else{
     255    _ura = 15;
     256  }
     257
     258  GPSADDBITS(12, 1019)
     259  GPSADDBITS(6,_prn.right((_prn.length()-1)).toInt())
     260  GPSADDBITS(10, _GPSweek)
     261  GPSADDBITS(4, _ura)
     262  GPSADDBITS(2,_L2Codes)
     263  GPSADDBITSFLOAT(14, _IDOT, PI/static_cast<double>(1<<30)
     264  /static_cast<double>(1<<13))
     265  GPSADDBITS(8, _IODE)
     266  GPSADDBITS(16, static_cast<int>(_TOC)>>4)
     267  GPSADDBITSFLOAT(8, _clock_driftrate, 1.0/static_cast<double>(1<<30)
     268  /static_cast<double>(1<<25))
     269  GPSADDBITSFLOAT(16, _clock_drift, 1.0/static_cast<double>(1<<30)
     270  /static_cast<double>(1<<13))
     271  GPSADDBITSFLOAT(22, _clock_bias, 1.0/static_cast<double>(1<<30)
     272  /static_cast<double>(1<<1))
     273  GPSADDBITS(10, _IODC)
     274  GPSADDBITSFLOAT(16, _Crs, 1.0/static_cast<double>(1<<5))
     275  GPSADDBITSFLOAT(16, _Delta_n, PI/static_cast<double>(1<<30)
     276  /static_cast<double>(1<<13))
     277  GPSADDBITSFLOAT(32, _M0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
     278  GPSADDBITSFLOAT(16, _Cuc, 1.0/static_cast<double>(1<<29))
     279  GPSADDBITSFLOAT(32, _e, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<3))
     280  GPSADDBITSFLOAT(16, _Cus, 1.0/static_cast<double>(1<<29))
     281  GPSADDBITSFLOAT(32, _sqrt_A, 1.0/static_cast<double>(1<<19))
     282  GPSADDBITS(16, static_cast<int>(_TOE)>>4)
     283  GPSADDBITSFLOAT(16, _Cic, 1.0/static_cast<double>(1<<29))
     284  GPSADDBITSFLOAT(32, _OMEGA0, PI/static_cast<double>(1<<30)
     285  /static_cast<double>(1<<1))
     286  GPSADDBITSFLOAT(16, _Cis, 1.0/static_cast<double>(1<<29))
     287  GPSADDBITSFLOAT(32, _i0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
     288  GPSADDBITSFLOAT(16, _Crc, 1.0/static_cast<double>(1<<5))
     289  GPSADDBITSFLOAT(32, _omega, PI/static_cast<double>(1<<30)
     290  /static_cast<double>(1<<1))
     291  GPSADDBITSFLOAT(24, _OMEGADOT, PI/static_cast<double>(1<<30)
     292  /static_cast<double>(1<<13))
     293  GPSADDBITSFLOAT(8, _TGD, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
     294  GPSADDBITS(6, _health)
     295  GPSADDBITS(1, _L2PFlag)
     296  GPSADDBITS(1, 0) /* GPS fit interval */
     297
     298  startbuffer[0]=0xD3;
     299  startbuffer[1]=(size >> 8);
     300  startbuffer[2]=size;
     301  unsigned long  i = CRC24(size+3, startbuffer);
     302  buffer[size++] = i >> 16;
     303  buffer[size++] = i >> 8;
     304  buffer[size++] = i;
     305  size += 3;
     306  return size;
     307}
    156308
    157309// Derivative of the state vector using a simple force model (static)
     
    268420void t_ephGlo::set(const glonassephemeris* ee) {
    269421
    270   ostringstream prn;
    271   prn << 'R' << setfill('0') << setw(2) << ee->almanac_number;
    272   _prn = prn.str();
     422  _prn = QString("R%1").arg(ee->almanac_number, 2, 10, QChar('0'));
    273423
    274424  int ww  = ee->GPSWeek;
    275425  int tow = ee->GPSTOW;
    276426  updatetime(&ww, &tow, ee->tb*1000, 0);  // Moscow -> GPS
     427
     428  bncTime hlpTime(ee->GPSWeek, ee->GPSTOW);
     429  unsigned year, month, day;
     430  hlpTime.civil_date(year, month, day);
     431  _gps_utc = gnumleap(year, month, day);
    277432
    278433  _GPSweek           = ww;
     
    306461}
    307462
     463// build up RTCM3 for GLONASS
     464////////////////////////////////////////////////////////////////////////////
     465#define GLONASSTOINT(type, value) static_cast<type>(NearestInt(value,0))
     466
     467#define GLONASSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
     468                       |(GLONASSTOINT(long long,b)&((1ULL<<(a))-1)); \
     469                       numbits += (a); \
     470                       while(numbits >= 8) { \
     471                       buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
     472#define GLONASSADDBITSFLOATM(a,b,c) {int s; long long i; \
     473                       if(b < 0.0) \
     474                       { \
     475                         s = 1; \
     476                         i = GLONASSTOINT(long long,(-b)/(c)); \
     477                         if(!i) s = 0; \
     478                       } \
     479                       else \
     480                       { \
     481                         s = 0; \
     482                         i = GLONASSTOINT(long long,(b)/(c)); \
     483                       } \
     484                       GLONASSADDBITS(1,s) \
     485                       GLONASSADDBITS(a-1,i)}
     486
     487int t_ephGlo::RTCM3(unsigned char *buffer)
     488{
     489
     490  int size = 0;
     491  int numbits = 0;
     492  long long bitbuffer = 0;
     493  unsigned char *startbuffer = buffer;
     494  buffer= buffer+3;
     495
     496  GLONASSADDBITS(12, 1020)
     497  GLONASSADDBITS(6, _prn.right((_prn.length()-1)).toInt())
     498  GLONASSADDBITS(5, 7+_frequency_number)
     499  GLONASSADDBITS(1, 0)
     500  GLONASSADDBITS(1, 0)
     501  GLONASSADDBITS(2, 0)
     502  _tki=_tki+3*60*60;
     503  GLONASSADDBITS(5, static_cast<int>(_tki)/(60*60))
     504  GLONASSADDBITS(6, (static_cast<int>(_tki)/60)%60)
     505  GLONASSADDBITS(1, (static_cast<int>(_tki)/30)%30)
     506  GLONASSADDBITS(1, _health)
     507  GLONASSADDBITS(1, 0)
     508  unsigned long long timeofday = (static_cast<int>(_tt+3*60*60-_gps_utc)%86400);
     509  GLONASSADDBITS(7, timeofday/60/15)
     510  GLONASSADDBITSFLOATM(24, _x_velocity*1000, 1000.0/static_cast<double>(1<<20))
     511  GLONASSADDBITSFLOATM(27, _x_pos*1000, 1000.0/static_cast<double>(1<<11))
     512  GLONASSADDBITSFLOATM(5, _x_acceleration*1000, 1000.0/static_cast<double>(1<<30))
     513  GLONASSADDBITSFLOATM(24, _y_velocity*1000, 1000.0/static_cast<double>(1<<20))
     514  GLONASSADDBITSFLOATM(27, _y_pos*1000, 1000.0/static_cast<double>(1<<11))
     515  GLONASSADDBITSFLOATM(5, _y_acceleration*1000, 1000.0/static_cast<double>(1<<30))
     516  GLONASSADDBITSFLOATM(24, _z_velocity*1000, 1000.0/static_cast<double>(1<<20))
     517  GLONASSADDBITSFLOATM(27,_z_pos*1000, 1000.0/static_cast<double>(1<<11))
     518  GLONASSADDBITSFLOATM(5, _z_acceleration*1000, 1000.0/static_cast<double>(1<<30))
     519  GLONASSADDBITS(1, 0)
     520  GLONASSADDBITSFLOATM(11, _gamma, 1.0/static_cast<double>(1<<30)
     521  /static_cast<double>(1<<10))
     522  GLONASSADDBITS(2, 0) /* GLONASS-M P */
     523  GLONASSADDBITS(1, 0) /* GLONASS-M ln(3) */
     524  GLONASSADDBITSFLOATM(22, _tau, 1.0/static_cast<double>(1<<30))
     525  GLONASSADDBITS(5, 0) /* GLONASS-M delta tau */
     526  GLONASSADDBITS(5, _E)
     527  GLONASSADDBITS(1, 0) /* GLONASS-M P4 */
     528  GLONASSADDBITS(4, 0) /* GLONASS-M FT */
     529  GLONASSADDBITS(11, 0) /* GLONASS-M NT */
     530  GLONASSADDBITS(2, 0) /* GLONASS-M active? */
     531  GLONASSADDBITS(1, 0) /* GLONASS additional data */
     532  GLONASSADDBITS(11, 0) /* GLONASS NA */
     533  GLONASSADDBITS(32, 0) /* GLONASS tau C */
     534  GLONASSADDBITS(5, 0) /* GLONASS-M N4 */
     535  GLONASSADDBITS(22, 0) /* GLONASS-M tau GPS */
     536  GLONASSADDBITS(1, 0) /* GLONASS-M ln(5) */
     537  GLONASSADDBITS(7, 0) /* Reserved */
     538
     539  startbuffer[0]=0xD3;
     540  startbuffer[1]=(size >> 8);
     541  startbuffer[2]=size;
     542  unsigned long i = CRC24(size+3, startbuffer);
     543  buffer[size++] = i >> 16;
     544  buffer[size++] = i >> 8;
     545  buffer[size++] = i;
     546  size += 3;
     547  return size;
     548}
     549
    308550// Set Galileo Satellite Position
    309551////////////////////////////////////////////////////////////////////////////
    310552void t_ephGal::set(const galileoephemeris* ee) {
    311   ostringstream prn;
    312   prn << 'E' << setfill('0') << setw(2) << ee->satellite;
    313 
    314   _prn = prn.str();
     553
     554  _prn = QString("E%1").arg(ee->satellite, 2, 10, QChar('0'));
    315555
    316556  _GPSweek  = ee->Week;
     
    429669}
    430670
     671// build up RTCM3 for Galileo
     672////////////////////////////////////////////////////////////////////////////
     673int t_ephGal::RTCM3(unsigned char *buffer) {
     674
     675  return 0;
     676}
  • trunk/BNC/RTCM3/ephemeris.h

    r3174 r3255  
    1414  virtual ~t_eph() {};
    1515
    16   bool        isNewerThan(const t_eph* eph) const;
    17   std::string prn() const {return _prn;}
     16  bool     isNewerThan(const t_eph* eph) const;
     17  QString prn() const {return _prn;}
    1818  void    setReceptDateTime(const QDateTime& dateTime) {
    1919    _receptDateTime = dateTime;
     
    4141
    4242  virtual int  IOD() const = 0;
     43 
     44  virtual int  RTCM3(unsigned char *) = 0;
    4345
    4446 protected: 
    45   std::string _prn;
    46   int         _GPSweek;
    47   double      _GPSweeks;
    48   QDateTime   _receptDateTime;
     47  QString  _prn;
     48  int       _GPSweek;
     49  double    _GPSweeks;
     50  QDateTime _receptDateTime;
    4951};
    5052
     
    6365
    6466  virtual int  IOD() const { return static_cast<int>(_IODC); }
     67
     68  virtual int  RTCM3(unsigned char *);
    6569
    6670 private:
     
    9296
    9397  double  _TGD;              //  [s]   
     98  double _health;            //  SV health
     99  double _ura;               //  SV accuracy
     100  double _L2PFlag;           //  L2 P data flag
     101  double _L2Codes;           //  Codes on L2 channel
    94102};
    95103
     
    106114  virtual int  IOD() const;
    107115
     116  virtual int  RTCM3(unsigned char *);
     117
    108118  void set(const glonassephemeris* ee);
    109119
     
    115125  mutable ColumnVector _xv;  // status vector (position, velocity) at time _tt
    116126
     127  double  _gps_utc;
    117128  double  _E;                // [days]   
    118129  double  _tau;              // [s]     
     
    146157  virtual int  IOD() const { return static_cast<int>(_IODnav); }
    147158
     159  virtual int  RTCM3(unsigned char *);
     160
    148161 private:
    149162  double  _IODnav;             
     
    169182  double  _IDOT;             //  [rad/s]
    170183  double  _BGD_1_5A;         //  group delay [s]
     184  double  _BGD_1_5B;         //  group delay [s]
    171185  int     _SISA;             //  Signal In Space Accuracy
    172186  int     _E5aHS;            //  E5a Health Status
  • trunk/BNC/upload/bncephuploadcaster.cpp

    r3254 r3255  
    2727
    2828  QString mountpoint = settings.value("uploadEphMountpoint").toString();
    29   QString outHost    = settings.value("uploadEphHost").toString();
    30   int     outPort    = settings.value("uploadEphPort").toInt();
    31   QString password   = settings.value("uploadEphPassword").toString();
     29  if (mountpoint.isEmpty()) {
     30    _ephUploadCaster = 0;
     31  }
     32  else {
     33    QString outHost    = settings.value("uploadEphHost").toString();
     34    int     outPort    = settings.value("uploadEphPort").toInt();
     35    QString password   = settings.value("uploadEphPassword").toString();
    3236
    33   _ephUploadCaster = new bncUploadCaster(mountpoint, outHost, outPort,
     37    _ephUploadCaster = new bncUploadCaster(mountpoint, outHost, outPort,
    3438                                         password, -1);
    3539
    36   connect(_ephUploadCaster, SIGNAL(newBytes(QByteArray,double)),
     40    connect(_ephUploadCaster, SIGNAL(newBytes(QByteArray,double)),
    3741          this, SIGNAL(newBytes(QByteArray,double)));
    3842
    39   _ephUploadCaster->start();
     43    _ephUploadCaster->start();
     44  }
    4045}
    4146
     
    4348////////////////////////////////////////////////////////////////////////////
    4449bncEphUploadCaster::~bncEphUploadCaster() {
    45   _ephUploadCaster->deleteSafely();
     50  if (_ephUploadCaster) {
     51    _ephUploadCaster->deleteSafely();
     52  }
    4653}
    4754
     
    4956////////////////////////////////////////////////////////////////////////////
    5057void bncEphUploadCaster::ephBufferChanged() {
    51 
     58  if (_ephUploadCaster) {
     59    QByteArray dummy = "from bncEphUploadCaster";
     60    _ephUploadCaster->setOutBuffer(dummy);
     61  }
    5262}
  • trunk/BNC/upload/bncrtnetuploadcaster.cpp

    r3233 r3255  
    444444
    445445  outLine.sprintf("%d %.1f %s  %3d  %10.3f  %8.3f %8.3f %8.3f\n",
    446                   GPSweek, GPSweeks, eph->prn().c_str(),
     446                  GPSweek, GPSweeks, eph->prn().toAscii().data(),
    447447                  eph->IOD(), dClk, rsw(1), rsw(2), rsw(3));
    448448
Note: See TracChangeset for help on using the changeset viewer.