Changeset 711 in ntrip for trunk


Ignore:
Timestamp:
Mar 8, 2008, 1:43:17 PM (17 years ago)
Author:
weber
Message:

* empty log message *

Location:
trunk/BNC/RTCM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/RTCM/RTCM2.cpp

    r709 r711  
    4545//   2008/03/04  AHA  Fixed problems with PRN 32
    4646//   2008/03/05  AHA  Implemeted fix for Trimble 4000SSI receivers
    47 //   2008/03/07  AHA  Major revision of input buffer handling
    48 //   2008/03/07  AHA  Removed unnecessary failure flag
    4947//
    5048// (c) DLR/GSOC
     
    6563// undersized packets in get(Unsigned)Bits
    6664
    67 #define DEBUG 0
     65#define DEBUG 0   
    6866
    6967// Activate (1) or deactivate (0) rounding of measurement epochs to 100ms
     
    138136void ThirtyBitWord::clear() {
    139137  W = 0;
     138};
     139
     140// Failure indicator for input operations
     141
     142bool ThirtyBitWord::fail() const {
     143  return failure;
    140144};
    141145
     
    255259
    256260
     261
    257262// Append a byte with six data bits
    258263
     
    270275  // Bits 7 and 6 (of 0..7) must be "01" for valid data bytes
    271276  if ( (b & 0x40) != 0x40 ) {
    272     // We simply skip the invalid input byte and leave the word unchanged
     277    failure = true;
    273278    return;
    274279  };
     
    285290// Get next 30bit word from string
    286291
    287 void ThirtyBitWord::get(const string& buf) {
     292void ThirtyBitWord::get(string& buf) {
    288293
    289294  // Check if string is long enough
    290295   
    291296  if (buf.size()<5) {
    292     // Ignore; users should avoid this case prior to calling get()
     297    failure = true;
    293298    return;
    294299  };
     
    297302 
    298303  for (int i=0; i<5; i++) append(buf[i]);
     304  buf.erase(0,5);
    299305
    300306#if (DEBUG>0)
    301307  if (!validParity()) {
    302     cerr << "Parity error in get()"
     308    cerr << "Parity error "
    303309         << bitset<32>(all()) << endl;
    304310  };
    305311#endif
     312  failure = false;
    306313
    307314};
     
    321328#if (DEBUG>0)
    322329  if (!validParity()) {
    323     cerr << "Parity error in get()"
     330    cerr << "Parity error "
    324331         << bitset<32>(all()) << endl;
    325332  };
    326333#endif
     334  failure = false;
    327335
    328336};
     
    332340void ThirtyBitWord::getHeader(string& buf) {
    333341
    334   const int wordLen = 5; // Number of bytes representing a 30-bit word
    335   const int spare   = 1; // Number of spare words for resync of parity
    336                          // (same value as inRTCM2packet::getPacket())
     342  unsigned int W_old = W;
    337343  unsigned int i;
    338344 
    339345  i=0;
    340   while (!isHeader() && i<buf.size() ) {
     346  while (!isHeader() || i<5 ) {
     347    // Check if string is long enough; if not restore old word and exit
     348    if (buf.size()<i+1) {
     349      W = W_old;
     350      failure = true;
     351      return;
     352    };
    341353    // Process byte
    342     append(buf[i]);
    343     // Increment count
    344     i++;
    345   };
    346 
    347   // Remove processed bytes from buffer. Retain also the previous word to
    348   // allow a resync if getHeader() is called repeatedly on the same buffer.
    349   if (i>=(1+spare)*wordLen) buf.erase(0,i-(1+spare)*wordLen);
     354    append(buf[i]); i++;
     355  };
     356
     357  // Remove processed bytes from buffer
     358 
     359  buf.erase(0,i);
    350360
    351361#if (DEBUG>0)
    352362  if (!validParity()) {
    353     cerr << "Parity error in getHeader()"
     363    cerr << "Parity error "
    354364         << bitset<32>(all()) << endl;
    355365  };
    356366#endif
    357  
     367  failure = false;
     368
    358369};
    359370
     
    374385#if (DEBUG>0)
    375386  if (!validParity()) {
    376     cerr << "Parity error in getHeader()"
     387    cerr << "Parity error "
    377388         << bitset<32>(all()) << endl;
    378389  };
    379390#endif
     391  failure = false;
    380392
    381393};
     
    431443void RTCM2packet::getPacket(std::string& buf) {
    432444
    433   const int wordLen = 5; // Number of bytes representing a 30-bit word
    434   const int spare   = 1; // Number of spare words for resync of parity
    435                          // (same value as used in ThirtyBitWord::getHeader)
    436   unsigned int n;
    437  
    438   // Try to read a full packet. Processed bytes are removed from the input
    439   // buffer except for the latest spare*wordLen bytes to restore the parity
    440   // bytes upon subseqeunt calls of getPAcket().
    441  
    442   // Locate and read the first header word
    443   W.getHeader(buf);
    444   if (!W.isHeader()) {
    445     // No header found; try again next time. buf retains only the spare
    446     // words. The packet contents is cleared to indicate an unsuccessful
    447     // termination of getPacket().
    448     clear();
    449     return;
    450   };
    451   H1 = W.value();
    452  
    453   // Do we have enough bytes to read the next word? If not, the packet
    454   // contents is cleared to indicate an unsuccessful termination. The
    455   // previously read spare and header bytes are retained in the buffer
    456   // for use in the next call of getPacket().
    457   if (buf.size()<(spare+2)*wordLen) { clear(); return; };
    458  
    459   // Read the second header word
    460   W.get(buf.substr((spare+1)*wordLen,buf.size()-1-(spare+1)*wordLen)); 
    461   H2 = W.value();
    462   if (!W.validParity()) {
    463     // Invalid H2 word; delete first buffer byte and try to resynch next time.
    464     // The packet contents is cleared to indicate an unsuccessful termination.
    465     clear();
    466     buf.erase(0,1);
    467     return;
    468   };
     445  int           n;
     446  ThirtyBitWord W_old = W;
     447  string        buf_old = buf;
     448 
     449  // Try to read a full packet. If the input buffer is too short
     450  // clear all data and restore the latest 30-bit word prior to
     451  // the getPacket call. The empty header word will indicate
     452  // an invalid message, which signals an unsuccessful getPacket()
     453  // call.
     454   
     455  W.getHeader(buf);
     456  H1 = W.value();
     457  if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
     458  if (!W.validParity()) { clear(); return; };
     459 
     460  W.get(buf);       
     461  H2 = W.value();
     462  if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
     463  if (!W.validParity()) { clear(); return; };
    469464
    470465  n = nDataWords();
    471  
    472   // Do we have enough bytes to read the next word? If not, the packet
    473   // contents is cleared to indicate an unsuccessful termination. The
    474   // previously read spare and header bytes are retained in the buffer
    475   // for use in the next call of getPacket().
    476   if (buf.size()<(spare+2+n)*wordLen) { clear(); return; };
    477  
    478466  DW.resize(n);
    479   for (unsigned int i=0; i<n; i++) {
    480     W.get(buf.substr((spare+2+i)*wordLen,buf.size()-1-(spare+2+i)*wordLen));
    481     DW[i] = W.value();
    482     if (!W.validParity()) {
    483       // Invalid data word; delete first byte and try to resynch next time.
    484       // The packet contents is cleared to indicate an unsuccessful termination.
    485       clear();
    486       buf.erase(0,1);
    487       return;
    488     };
    489   };
    490 
    491   // Successful packet extraction; delete total number of message bytes
    492   // from buffer.
    493   // Note: a total of "spare" words remain in the buffer to enable a
    494   // parity resynchronization when searching the next header.
    495  
    496   buf.erase(0,(n+2)*wordLen);
    497  
     467  for (int i=0; i<n; i++) {
     468    W.get(buf);
     469    DW[i] = W.value();
     470    if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
     471    if (!W.validParity()) { clear(); return; };
     472  };
     473
    498474  return;
    499475 
     
    511487  W.getHeader(inp);
    512488  H1 = W.value();
    513   if (inp.fail() || !W.isHeader()) { clear(); return; }
     489  if (W.fail() || !W.validParity()) { clear(); return; }
    514490 
    515491  W.get(inp);       
    516492  H2 = W.value();
    517   if (inp.fail() || !W.validParity()) { clear(); return; }
     493  if (W.fail() || !W.validParity()) { clear(); return; }
    518494
    519495  n = nDataWords();
     
    522498    W.get(inp);
    523499    DW[i] = W.value();
    524     if (inp.fail() || !W.validParity()) { clear(); return; }
     500    if (W.fail() || !W.validParity()) { clear(); return; }
    525501  };
    526502
  • trunk/BNC/RTCM/RTCM2.h

    r709 r711  
    2828//   2006/10/17  OMO  Removed obsolete check of multiple message indicator
    2929//   2006/11/25  OMO  Revised check for presence of GLONASS data
    30 //   2008/03/07  AHA  Removed unnecessary failure flag
    3130//
    3231// (c) DLR/GSOC
     
    8281    // Input
    8382   
    84     void         get(const std::string& buf);
     83    void         get(std::string& buf);
    8584    void         get(std::istream& inp);
    8685    void         getHeader(std::string& buf);
     
    9594  private:
    9695
    97 //    bool         failure;
     96    bool         failure;
    9897
    9998    //
Note: See TracChangeset for help on using the changeset viewer.