Changeset 1425 in ntrip for trunk/BNC/GPSS
- Timestamp:
- Jan 2, 2009, 5:50:32 PM (16 years ago)
- Location:
- trunk/BNC/GPSS
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/GPSS/gpssDecoder.cpp
r1315 r1425 41 41 gpssDecoder::gpssDecoder() : GPSDecoder() { 42 42 _mode = MODE_SEARCH; 43 _recordSize = 0;44 43 45 44 connect(this, SIGNAL(newGPSEph(gpsephemeris*)), … … 58 57 errmsg.clear(); 59 58 60 if (_mode == MODE_SEARCH) {61 _buffer.clear();62 _recordSize = 0;63 }64 59 _buffer.append(data, dataLen); 65 60 66 unsigned offset = 0; 67 for (offset = 0; offset < _buffer.size(); offset++) { 61 for (;;) { 68 62 69 switch(_mode) { 63 if (_mode == MODE_SEARCH) { 64 if (_buffer.size() < 1) return success; 65 if (_buffer[0] == 0x02) { 66 _mode = MODE_TYPE; 67 } 68 _buffer.erase(0,1); 69 } 70 70 71 case MODE_SEARCH: 72 if (_buffer[offset] == 0x02) { 73 _mode = MODE_TYPE; 74 } 75 continue; 71 else if (_mode == MODE_TYPE) { 72 if (_buffer.size() < 1) return success; 73 if (_buffer[0] == 0x00) { 74 _mode = MODE_EPOCH; 75 } else if (_buffer[0] == 0x01) { 76 _mode = MODE_EPH; 77 } else { 78 errmsg.push_back("Unknown record type"); 79 _mode = MODE_SEARCH; 80 } 81 _buffer.erase(0,1); 82 } 76 83 77 case MODE_TYPE: 78 if (_buffer[offset] == 0x00) { 79 _mode = MODE_EPOCH; 80 } else if (_buffer[offset] == 0x01) { 81 _mode = MODE_EPH; 82 } else { 83 errmsg.push_back("Unknown record type"); 84 _mode = MODE_SEARCH; 85 } 86 continue; 84 else if (_mode == MODE_EPOCH || _mode == MODE_EPH) { 85 int recordSize; 86 if (_buffer.size() < sizeof(recordSize)) return success; 87 memcpy(&recordSize, _buffer.data(), sizeof(recordSize)); 88 if (_mode == MODE_EPOCH) { 89 _mode = MODE_EPOCH_BODY; 90 } 91 if (_mode == MODE_EPH) { 92 _mode = MODE_EPH_BODY; 93 } 94 _buffer.erase(0,sizeof(recordSize)); 95 } 87 96 88 case MODE_EPOCH: 89 case MODE_EPH: 90 if (offset+sizeof(_recordSize) > _buffer.size()) { 91 errmsg.push_back("Record size too large (A)"); 92 _mode = MODE_SEARCH; 93 } else { 94 memcpy(&_recordSize, &_buffer[offset], sizeof(_recordSize)); 95 if (_mode == MODE_EPOCH) { 96 _mode = MODE_EPOCH_BODY; 97 } 98 if (_mode == MODE_EPH) { 99 _mode = MODE_EPH_BODY; 100 } 101 offset += sizeof(_recordSize) - 1; 102 } 103 continue; 97 else if (_mode == MODE_EPOCH_BODY) { 98 EPOCHHEADER epochHdr; 99 if (_buffer.size() < sizeof(epochHdr)) return success; 100 memcpy(&epochHdr, _buffer.data(), sizeof(epochHdr)); 101 _buffer.erase(0,sizeof(epochHdr)); 102 for (int is = 1; is <= epochHdr.n_svs; is++) { 103 if (_buffer.size() < sizeof(t_obsInternal)) return success; 104 t_obs* obs = new t_obs(); 105 memcpy(&(obs->_o), _buffer.data(), sizeof(t_obsInternal)); 106 _obsList.push_back(obs); 107 _buffer.erase(0, sizeof(t_obsInternal)); 108 } 109 _mode = MODE_EPOCH_CRC; 110 } 104 111 105 case MODE_EPOCH_BODY: 106 if (offset + _recordSize > _buffer.size()) { 107 errmsg.push_back("Record size too large (B)"); 108 _mode = MODE_SEARCH; 109 } else { 110 EPOCHHEADER epochHdr; 111 memcpy(&epochHdr, &_buffer[offset], sizeof(epochHdr)); 112 offset += sizeof(epochHdr); 113 for (int is = 1; is <= epochHdr.n_svs; is++) { 114 t_obs* obs = new t_obs(); 115 memcpy(&(obs->_o), &_buffer[offset], sizeof(obs->_o)); 116 _obsList.push_back(obs); 117 offset += sizeof(obs->_o); 118 } 119 _mode = MODE_EPOCH_CRC; 120 --offset; 121 } 122 continue; 112 else if (_mode == MODE_EPH_BODY) { 113 if (_buffer.size() < sizeof(gpsephemeris)) return success; 114 gpsephemeris* gpsEph = new gpsephemeris; 115 memcpy(gpsEph, _buffer.data(), sizeof(gpsephemeris)); 116 emit newGPSEph(gpsEph); 117 _buffer.erase(0, sizeof(gpsephemeris)); 118 _mode = MODE_EPH_CRC; 119 } 123 120 124 case MODE_EPH_BODY: 125 if (offset + _recordSize > _buffer.size()) { 126 errmsg.push_back("Record size too large (C)"); 127 _mode = MODE_SEARCH; 128 } else { 129 gpsephemeris* gpsEph = new gpsephemeris; 130 memcpy(gpsEph, &_buffer[offset], sizeof(gpsephemeris)); 131 emit newGPSEph(gpsEph); 132 offset += sizeof(gpsephemeris) - 1; 133 _mode = MODE_EPH_CRC; 134 } 135 continue; 136 137 case MODE_EPOCH_CRC: 138 _mode = MODE_EPOCH_ETX; // TODO: CRC check 139 continue; 140 141 case MODE_EPH_CRC: 142 _mode = MODE_EPH_ETX; // TODO: CRC check 143 continue; 144 145 case MODE_EPOCH_ETX: 146 _mode = MODE_SEARCH; 147 continue; 148 149 case MODE_EPH_ETX: 150 _mode = MODE_SEARCH; 151 continue; 121 else { 122 if (_buffer.size() < 1) return success; 123 _buffer.erase(0,1); 124 _mode = MODE_SEARCH; 152 125 } 153 126 } 154 127 155 if (errmsg.size() == 0) { 156 return success; 157 } 158 else { 159 return failure; 160 } 128 return success; 161 129 } -
trunk/BNC/GPSS/gpssDecoder.h
r1315 r1425 22 22 private: 23 23 int _mode; 24 int _recordSize;25 24 std::string _buffer; 26 25 } ;
Note:
See TracChangeset
for help on using the changeset viewer.