Changeset 1434 in ntrip for trunk/BNC/GPSS


Ignore:
Timestamp:
Jan 3, 2009, 12:53:57 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/GPSS/gpssDecoder.cpp

    r1433 r1434  
    3939} EPOCHHEADER;
    4040
     41// Cyclic Redundancy Check
     42////////////////////////////////////////////////////////////////////////////
     43unsigned short cal_crc(char *buf, int num) {
     44  unsigned short polynomial = 0x8408;
     45  unsigned short crc = 0;
     46  int i;
     47  while ( num-- ) {
     48    crc = ( crc & 0xFF00 ) | ( *buf++^( crc & 0x00FF ) );
     49    for( i=0; i<8; i++ ){
     50      if( crc & 0x0001 ){
     51        crc >>= 1;
     52        crc ^= polynomial;
     53      }
     54      else{
     55        crc >>= 1;
     56      }
     57    }
     58  }
     59  return (crc);
     60}
     61
    4162// Constructor
    4263////////////////////////////////////////////////////////////////////////////
     
    6182  _buffer += QByteArray(data, dataLen);
    6283
     84  cout << "Decode: buffer length = " << _buffer.length() << endl;
     85
    6386  int iBeg;
    6487  while ( (iBeg = _buffer.indexOf(0x02)) != -1) {
     
    7497      int reqLength = 2 + sizeof(recordSize) + sizeof(EPOCHHEADER);
    7598
    76       cout << "Obs: " << _buffer.length() << " " << reqLength << endl;
    77 
    7899      if (_buffer.length() >= reqLength) {
    79100        EPOCHHEADER epochHdr;
     
    84105
    85106        if (_buffer.length() >= reqLength) {
     107
     108          int checkLen = 2 + sizeof(recordSize) + sizeof(EPOCHHEADER) +
     109                         epochHdr.n_svs * sizeof(t_obsInternal);
     110          memcpy(&crc, _buffer.data() + checkLen, sizeof(crc));
     111          int crdCal = cal_crc(_buffer.data(), checkLen);
     112
     113          cout << "Obs: " << crc << " " << crdCal << endl;
     114
    86115          for (int is = 0; is < epochHdr.n_svs; is++) {
    87116            t_obs* obs = new t_obs();
     
    102131        sizeof(crc) + 1;
    103132
    104       cout << "Eph: " << _buffer.length() << " " << reqLength << endl;
     133      if (_buffer.length() >= reqLength) {
    105134
    106       if (_buffer.length() >= reqLength) {
     135        int checkLen = 2 + sizeof(recordSize) + sizeof(gpsephemeris);
     136        memcpy(&crc, _buffer.data() + checkLen, sizeof(crc));
     137        int crdCal = cal_crc(_buffer.data(), checkLen);
     138
     139        cout << "Obs: " << crc << " " << crdCal << endl;
     140
    107141        gpsephemeris* gpsEph = new gpsephemeris;
    108142        memcpy(gpsEph, _buffer.data() + 2 + sizeof(recordSize),
Note: See TracChangeset for help on using the changeset viewer.