Changeset 728 in ntrip for trunk/BNC/RTCM/RTCM2.cpp


Ignore:
Timestamp:
Mar 14, 2008, 4:01:49 PM (16 years ago)
Author:
weber
Message:

* empty log message *

File:
1 edited

Legend:

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

    r725 r728  
    4949//   2008/03/10  AHA  Corrected extraction of antenna serial number
    5050//   2008/03/10  AHA  Corrected buffer length check in getPacket()
    51 //   2008/03/11  AHA  Added checks for data consistency in extraction routines
    5251//   2008/03/11  AHA  isGPS-flag in RTCM2_Obs is now set to false on clear()
     52//   2008/03/13  AHA  Added checks for data consistency in extraction routines
    5353//
    5454// (c) DLR/GSOC
     
    296296   
    297297  if (buf.size()<5) {
    298     // Ignore; users should avoid this case prior to calling get()   
     298    // Ignore; users should avoid this case prior to calling get()
     299   
    299300#if ( DEBUG > 0 )   
    300301    cerr << "Error in get(): packet too short (" << buf.size() <<")" << endl;
    301302#endif
     303       
    302304    return;
    303305  };
     
    341343void ThirtyBitWord::getHeader(string& buf) {
    342344
    343   const int wordLen = 5; // Number of bytes representing a 30-bit word
    344   const int spare   = 1; // Number of spare words for resync of parity
    345                          // (same value as inRTCM2packet::getPacket())
     345  const unsigned int wordLen = 5; // Number of bytes representing a 30-bit word
     346  const unsigned int spare   = 1; // Number of spare words for resync of parity
     347                                  // (same value as inRTCM2packet::getPacket())
    346348  unsigned int i;
    347349 
    348350  i=0;
     351  // append spare word (to get correct parity) and first consecutive word 
     352  while (i<(spare+1)*wordLen) {
     353    // Process byte
     354    append(buf[i]);
     355    // Increment count
     356    i++;
     357  };
     358 
     359  // start searching for preamble in first word after spare word
    349360  while (!isHeader() && i<buf.size() ) {
    350361    // Process byte
     
    445456  unsigned int n;
    446457 
     458  // Does the package content at least spare bytes and first header byte?
     459  if (buf.size()<(spare+1)*wordLen) {
     460      clear();       
     461      return;
     462  };
     463   
    447464  // Try to read a full packet. Processed bytes are removed from the input
    448465  // buffer except for the latest spare*wordLen bytes to restore the parity
    449   // bytes upon subseqeunt calls of getPAcket().
     466  // bytes upon subseqeunt calls of getPacket().
    450467 
    451468  // Locate and read the first header word
     
    456473    // termination of getPacket().
    457474    clear();
     475   
    458476#if ( DEBUG > 0 )
    459477    cerr << "Error in getPacket(): W.isHeader() = false  for H1" << endl;
    460478#endif
     479   
    461480    return;
    462481  };
     
    469488  if (buf.size()<(spare+2)*wordLen) {
    470489    clear();
     490   
    471491#if ( DEBUG > 0 )   
    472492    cerr << "Error in getPacket(): buffer too short for complete H2" << endl;
    473493#endif
     494   
    474495    return;
    475496  };
     
    483504    clear();
    484505    buf.erase(0,1);
     506   
    485507#if ( DEBUG > 0 )   
    486508    cerr << "Error in getPacket(): W.validParity() = false for H2" << endl;
    487509#endif
     510       
    488511    return;
    489512  };
    490513
    491514  n = nDataWords();
    492 
     515 
    493516  // Do we have enough bytes to read the next word? If not, the packet
    494517  // contents is cleared to indicate an unsuccessful termination. The
     
    496519  // for use in the next call of getPacket().
    497520  if (buf.size()<(spare+2+n)*wordLen) {
    498     clear();     
     521    clear();
     522   
    499523#if ( DEBUG > 0 )   
    500524    cerr << "Error in getPacket(): buffer too short for complete " << n
    501525         << " DWs" << endl;
    502526#endif
     527   
    503528    return;
    504529  };
     
    513538      clear();
    514539      buf.erase(0,1);
     540     
    515541#if ( DEBUG > 0 )   
    516542    cerr << "Error in getPacket(): W.validParity() = false for DW"
    517543         << i << endl;
    518544#endif
     545       
    519546      return;
    520547    };
     
    527554 
    528555  buf.erase(0,(n+2)*wordLen);
    529  
     556   
    530557  return;
    531558 
     
    762789void RTCM2_23::extract(const RTCM2packet& P) {
    763790
    764   int  nad, nas;
    765  
    766   // Check validity and packet type
     791  unsigned int       nad, nas;
     792 
     793  const unsigned int nF1  = 8; // bits in first field (R,AF,SF,NAD)
     794  const unsigned int nF2  =16; // bits in second field (SETUP ID,R,NAS)
     795  const unsigned int nBits=24; // data bits in  30bit word
     796 
     797  // Check validity, packet type and number of data words
    767798 
    768799  validMsg = (P.valid());
     
    771802  validMsg = (P.ID()==23); 
    772803  if (!validMsg) return;
    773  
     804
     805  // Check number of data words (can nad be read in?)
     806 
     807  validMsg = (P.nDataWords()>=1); 
     808  if (!validMsg){
     809    cerr << "RTCM2_23::extract: P.nDataWords()>=1" << endl;
     810    return;
     811  }
     812
    774813  // Antenna descriptor
    775814  antType = "";
    776815  nad = P.getUnsignedBits(3,5);
    777   for (int i=0;i<nad;i++)
    778     antType += (char)P.getUnsignedBits(8+i*8,8);
     816 
     817  // Check number of data words (can antenna description be read in?)
     818  validMsg = ( P.nDataWords() >=
     819               (unsigned int)ceil((nF1+nad*8)/(double)nBits) );
     820
     821  if (!validMsg) return;
     822 
     823  for (unsigned int i=0;i<nad;i++)
     824    antType += (char)P.getUnsignedBits(nF1+i*8,8);
    779825
    780826  // Optional antenna serial numbers
    781827  if (P.getUnsignedBits(2,1)==1) {
     828
     829    // Check number of data words (can nas be read in?)
     830   
     831    validMsg = ( P.nDataWords() >=
     832                 (unsigned int)ceil((nF1+nad*8+nF2)/(double)nBits) );
     833    if (!validMsg) return;
     834   
    782835    nas = P.getUnsignedBits(19+8*nad,5);
     836
     837    // Check number of data words (can antenna serial number be read in?)
     838   
     839    validMsg = ( P.nDataWords() >=
     840                 (unsigned int)ceil((nF1+nad*8+nF2+nas*8)/(double)nBits) );
     841    if (!validMsg) return;
     842
    783843    antSN = "";
    784     for (int i=0;i<nas;i++)
    785       antSN += (char)P.getUnsignedBits(24+8*nad+i*8,8);
     844    for (unsigned int i=0;i<nas;i++)
     845      antSN += (char)P.getUnsignedBits(nF1+8*nad+nF2+i*8,8);
    786846  };
    787847
     
    9621022         << P.nDataWords() << ") detected" << endl;
    9631023#endif
     1024   
    9641025    return;
    9651026  };
     
    9721033         << P.nDataWords() << ") detected" << endl;
    9731034#endif
     1035   
    9741036    return;
    9751037  };
     
    10331095    if ( isL1 && !isGPS) availability.set(bit_L1cphGLO);
    10341096    if (!isL1 && !isGPS) availability.set(bit_L2cphGLO);
     1097   
     1098#if ( DEBUG > 0 )
     1099    cerr << "RTCM2_Obs::extract(): availability "
     1100         << bitset<8>(availability) << endl; 
     1101#endif
     1102   
    10351103   
    10361104    // Process all satellites
     
    11481216    if ( isL1 && !isGPS) availability.set(bit_L1rngGLO);
    11491217    if (!isL1 && !isGPS) availability.set(bit_L2rngGLO);
     1218
     1219#if ( DEBUG > 0 )
     1220    cerr << "RTCM2_Obs::extract(): availability "
     1221         << bitset<8>(availability) << endl; 
     1222#endif
    11501223
    11511224    // Process all satellites
Note: See TracChangeset for help on using the changeset viewer.