Changeset 728 in ntrip for trunk/BNC/RTCM
- Timestamp:
- Mar 14, 2008, 4:01:49 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/BNC/RTCM/RTCM2.cpp ¶
r725 r728 49 49 // 2008/03/10 AHA Corrected extraction of antenna serial number 50 50 // 2008/03/10 AHA Corrected buffer length check in getPacket() 51 // 2008/03/11 AHA Added checks for data consistency in extraction routines52 51 // 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 53 53 // 54 54 // (c) DLR/GSOC … … 296 296 297 297 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 299 300 #if ( DEBUG > 0 ) 300 301 cerr << "Error in get(): packet too short (" << buf.size() <<")" << endl; 301 302 #endif 303 302 304 return; 303 305 }; … … 341 343 void ThirtyBitWord::getHeader(string& buf) { 342 344 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()) 346 348 unsigned int i; 347 349 348 350 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 349 360 while (!isHeader() && i<buf.size() ) { 350 361 // Process byte … … 445 456 unsigned int n; 446 457 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 447 464 // Try to read a full packet. Processed bytes are removed from the input 448 465 // buffer except for the latest spare*wordLen bytes to restore the parity 449 // bytes upon subseqeunt calls of getP Acket().466 // bytes upon subseqeunt calls of getPacket(). 450 467 451 468 // Locate and read the first header word … … 456 473 // termination of getPacket(). 457 474 clear(); 475 458 476 #if ( DEBUG > 0 ) 459 477 cerr << "Error in getPacket(): W.isHeader() = false for H1" << endl; 460 478 #endif 479 461 480 return; 462 481 }; … … 469 488 if (buf.size()<(spare+2)*wordLen) { 470 489 clear(); 490 471 491 #if ( DEBUG > 0 ) 472 492 cerr << "Error in getPacket(): buffer too short for complete H2" << endl; 473 493 #endif 494 474 495 return; 475 496 }; … … 483 504 clear(); 484 505 buf.erase(0,1); 506 485 507 #if ( DEBUG > 0 ) 486 508 cerr << "Error in getPacket(): W.validParity() = false for H2" << endl; 487 509 #endif 510 488 511 return; 489 512 }; 490 513 491 514 n = nDataWords(); 492 515 493 516 // Do we have enough bytes to read the next word? If not, the packet 494 517 // contents is cleared to indicate an unsuccessful termination. The … … 496 519 // for use in the next call of getPacket(). 497 520 if (buf.size()<(spare+2+n)*wordLen) { 498 clear(); 521 clear(); 522 499 523 #if ( DEBUG > 0 ) 500 524 cerr << "Error in getPacket(): buffer too short for complete " << n 501 525 << " DWs" << endl; 502 526 #endif 527 503 528 return; 504 529 }; … … 513 538 clear(); 514 539 buf.erase(0,1); 540 515 541 #if ( DEBUG > 0 ) 516 542 cerr << "Error in getPacket(): W.validParity() = false for DW" 517 543 << i << endl; 518 544 #endif 545 519 546 return; 520 547 }; … … 527 554 528 555 buf.erase(0,(n+2)*wordLen); 529 556 530 557 return; 531 558 … … 762 789 void RTCM2_23::extract(const RTCM2packet& P) { 763 790 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 767 798 768 799 validMsg = (P.valid()); … … 771 802 validMsg = (P.ID()==23); 772 803 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 774 813 // Antenna descriptor 775 814 antType = ""; 776 815 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); 779 825 780 826 // Optional antenna serial numbers 781 827 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 782 835 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 783 843 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); 786 846 }; 787 847 … … 962 1022 << P.nDataWords() << ") detected" << endl; 963 1023 #endif 1024 964 1025 return; 965 1026 }; … … 972 1033 << P.nDataWords() << ") detected" << endl; 973 1034 #endif 1035 974 1036 return; 975 1037 }; … … 1033 1095 if ( isL1 && !isGPS) availability.set(bit_L1cphGLO); 1034 1096 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 1035 1103 1036 1104 // Process all satellites … … 1148 1216 if ( isL1 && !isGPS) availability.set(bit_L1rngGLO); 1149 1217 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 1150 1223 1151 1224 // Process all satellites
Note:
See TracChangeset
for help on using the changeset viewer.