- Timestamp:
- Mar 8, 2008, 1:43:17 PM (17 years ago)
- Location:
- trunk/BNC/RTCM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/RTCM/RTCM2.cpp
r709 r711 45 45 // 2008/03/04 AHA Fixed problems with PRN 32 46 46 // 2008/03/05 AHA Implemeted fix for Trimble 4000SSI receivers 47 // 2008/03/07 AHA Major revision of input buffer handling48 // 2008/03/07 AHA Removed unnecessary failure flag49 47 // 50 48 // (c) DLR/GSOC … … 65 63 // undersized packets in get(Unsigned)Bits 66 64 67 #define DEBUG 0 65 #define DEBUG 0 68 66 69 67 // Activate (1) or deactivate (0) rounding of measurement epochs to 100ms … … 138 136 void ThirtyBitWord::clear() { 139 137 W = 0; 138 }; 139 140 // Failure indicator for input operations 141 142 bool ThirtyBitWord::fail() const { 143 return failure; 140 144 }; 141 145 … … 255 259 256 260 261 257 262 // Append a byte with six data bits 258 263 … … 270 275 // Bits 7 and 6 (of 0..7) must be "01" for valid data bytes 271 276 if ( (b & 0x40) != 0x40 ) { 272 // We simply skip the invalid input byte and leave the word unchanged277 failure = true; 273 278 return; 274 279 }; … … 285 290 // Get next 30bit word from string 286 291 287 void ThirtyBitWord::get( conststring& buf) {292 void ThirtyBitWord::get(string& buf) { 288 293 289 294 // Check if string is long enough 290 295 291 296 if (buf.size()<5) { 292 // Ignore; users should avoid this case prior to calling get()297 failure = true; 293 298 return; 294 299 }; … … 297 302 298 303 for (int i=0; i<5; i++) append(buf[i]); 304 buf.erase(0,5); 299 305 300 306 #if (DEBUG>0) 301 307 if (!validParity()) { 302 cerr << "Parity error in get()"308 cerr << "Parity error " 303 309 << bitset<32>(all()) << endl; 304 310 }; 305 311 #endif 312 failure = false; 306 313 307 314 }; … … 321 328 #if (DEBUG>0) 322 329 if (!validParity()) { 323 cerr << "Parity error in get()"330 cerr << "Parity error " 324 331 << bitset<32>(all()) << endl; 325 332 }; 326 333 #endif 334 failure = false; 327 335 328 336 }; … … 332 340 void ThirtyBitWord::getHeader(string& buf) { 333 341 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; 337 343 unsigned int i; 338 344 339 345 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 }; 341 353 // 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); 350 360 351 361 #if (DEBUG>0) 352 362 if (!validParity()) { 353 cerr << "Parity error in getHeader()"363 cerr << "Parity error " 354 364 << bitset<32>(all()) << endl; 355 365 }; 356 366 #endif 357 367 failure = false; 368 358 369 }; 359 370 … … 374 385 #if (DEBUG>0) 375 386 if (!validParity()) { 376 cerr << "Parity error in getHeader()"387 cerr << "Parity error " 377 388 << bitset<32>(all()) << endl; 378 389 }; 379 390 #endif 391 failure = false; 380 392 381 393 }; … … 431 443 void RTCM2packet::getPacket(std::string& buf) { 432 444 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; }; 469 464 470 465 n = nDataWords(); 471 472 // Do we have enough bytes to read the next word? If not, the packet473 // contents is cleared to indicate an unsuccessful termination. The474 // previously read spare and header bytes are retained in the buffer475 // for use in the next call of getPacket().476 if (buf.size()<(spare+2+n)*wordLen) { clear(); return; };477 478 466 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 498 474 return; 499 475 … … 511 487 W.getHeader(inp); 512 488 H1 = W.value(); 513 if ( inp.fail() || !W.isHeader()) { clear(); return; }489 if (W.fail() || !W.validParity()) { clear(); return; } 514 490 515 491 W.get(inp); 516 492 H2 = W.value(); 517 if ( inp.fail() || !W.validParity()) { clear(); return; }493 if (W.fail() || !W.validParity()) { clear(); return; } 518 494 519 495 n = nDataWords(); … … 522 498 W.get(inp); 523 499 DW[i] = W.value(); 524 if ( inp.fail() || !W.validParity()) { clear(); return; }500 if (W.fail() || !W.validParity()) { clear(); return; } 525 501 }; 526 502 -
trunk/BNC/RTCM/RTCM2.h
r709 r711 28 28 // 2006/10/17 OMO Removed obsolete check of multiple message indicator 29 29 // 2006/11/25 OMO Revised check for presence of GLONASS data 30 // 2008/03/07 AHA Removed unnecessary failure flag31 30 // 32 31 // (c) DLR/GSOC … … 82 81 // Input 83 82 84 void get( conststd::string& buf);83 void get(std::string& buf); 85 84 void get(std::istream& inp); 86 85 void getHeader(std::string& buf); … … 95 94 private: 96 95 97 //bool failure;96 bool failure; 98 97 99 98 //
Note:
See TracChangeset
for help on using the changeset viewer.