mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-31 15:23:04 +00:00 
			
		
		
		
	Improve CRC computation of ISM
This commit is contained in:
		| @@ -15,9 +15,7 @@ | ||||
|  */ | ||||
|  | ||||
| #include "galileo_ism.h" | ||||
| #include <boost/dynamic_bitset.hpp> | ||||
| #include <algorithm> | ||||
| #include <vector> | ||||
|  | ||||
| void Galileo_ISM::set_ism_constellation_id(uint8_t const_id) | ||||
| { | ||||
| @@ -177,12 +175,27 @@ uint16_t Galileo_ISM::get_Tvalidity_hours() const | ||||
|  | ||||
| bool Galileo_ISM::check_ism_crc(const std::bitset<GALILEO_DATA_JK_BITS>& bits) | ||||
| { | ||||
|     boost::dynamic_bitset<unsigned char> frame_bits(bits.to_string().substr(0, GALILEO_ISM_CRC_DATA_BITS)); | ||||
|     std::vector<unsigned char> bytes; | ||||
|     boost::to_block_range(frame_bits, std::back_inserter(bytes)); | ||||
|     std::reverse(bytes.begin(), bytes.end()); | ||||
|     crc32_ism.process_bytes(bytes.data(), GALILEO_ISM_CRC_DATA_BYTES); | ||||
|     const uint32_t crc_computed = crc32_ism.checksum(); | ||||
|     std::bitset<96> extracted; | ||||
|     for (int32_t i = 0; i < GALILEO_ISM_CRC_DATA_BITS; ++i) | ||||
|         { | ||||
|             extracted[i] = bits[i + 32]; | ||||
|         } | ||||
|  | ||||
|     std::vector<uint8_t> data_bytes((extracted.size() + 7) / 8); | ||||
|  | ||||
|     for (size_t i = 0; i < extracted.size(); i += 8) | ||||
|         { | ||||
|             uint8_t byte = 0; | ||||
|             for (size_t j = 0; j < 8 && i + j < extracted.size(); ++j) | ||||
|                 { | ||||
|                     byte |= (extracted[i + j] << j); | ||||
|                 } | ||||
|             data_bytes[i / 8] = byte; | ||||
|         } | ||||
|  | ||||
|     std::reverse(data_bytes.begin(), data_bytes.end()); | ||||
|     const uint32_t crc_computed = this->compute_crc(data_bytes); | ||||
|  | ||||
|     if (this->ism_crc == crc_computed) | ||||
|         { | ||||
|             return true; | ||||
|   | ||||
| @@ -69,10 +69,10 @@ public: | ||||
|     uint16_t get_WN_ISM() const; | ||||
|     uint16_t get_t0_ISM() const; | ||||
|     uint16_t get_Tvalidity_hours() const; | ||||
|     uint32_t compute_crc(const std::vector<uint8_t>& data); | ||||
|  | ||||
| private: | ||||
|     boost::crc_basic<32> crc32_ism; | ||||
|     uint32_t compute_crc(const std::vector<uint8_t>& data); | ||||
|  | ||||
|     // ICD 2.1 Table 97 | ||||
|     std::unordered_map<uint8_t, double> ISM_PCONST_MAP = { | ||||
|   | ||||
| @@ -131,7 +131,7 @@ private: | ||||
| #include "unit-tests/signal-processing-blocks/tracking/tracking_loop_filter_test.cc" | ||||
| #include "unit-tests/system-parameters/galileo_e1b_reed_solomon_test.cc" | ||||
| #include "unit-tests/system-parameters/galileo_e6b_reed_solomon_test.cc" | ||||
| #include "unit-tests/system-parameters/glonass_gnav_crc_test.cc" | ||||
| #include "unit-tests/system-parameters/galileo_ism_test.cc" | ||||
| #include "unit-tests/system-parameters/glonass_gnav_ephemeris_test.cc" | ||||
| #include "unit-tests/system-parameters/glonass_gnav_nav_message_test.cc" | ||||
| #include "unit-tests/system-parameters/has_decoding_test.cc" | ||||
|   | ||||
| @@ -17,27 +17,14 @@ | ||||
|  | ||||
| #include "galileo_ism.h" | ||||
| #include <gtest/gtest.h> | ||||
| #include <algorithm> | ||||
| #include <bitset> | ||||
| #include <vector> | ||||
|  | ||||
| TEST(GalileoISMTest, CRC) | ||||
| { | ||||
|     // Example from ANNEX G Galileo ICD | ||||
|     Galileo_ISM gal_ism{}; | ||||
|     uint32_t expected_crc = 3002390191; | ||||
|     std::bitset<96> input{"010110000010101010101010101010101010101010101010101010101010101010101010101010101010101010101010"}; | ||||
|     std::vector<uint8_t> data_bytes; | ||||
|     for (size_t i = 0; i < input.size(); i += 8) | ||||
|         { | ||||
|             std::bitset<8> byte; | ||||
|             for (size_t j = 0; j < 8; j++) | ||||
|                 { | ||||
|                     byte[j] = input[i + j]; | ||||
|                 } | ||||
|             data_bytes.push_back(static_cast<uint8_t>(byte.to_ulong())); | ||||
|         } | ||||
|  | ||||
|     std::reverse(data_bytes.begin(), data_bytes.end()); | ||||
|     auto computed_crc = gal_ism.compute_crc(data_bytes); | ||||
|     EXPECT_TRUE(computed_crc == expected_crc); | ||||
|     gal_ism.set_ism_crc(expected_crc); | ||||
|     std::bitset<128> input{"01011000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010110010111101001101011010101111"}; | ||||
|     bool result = gal_ism.check_ism_crc(input); | ||||
|     EXPECT_TRUE(result); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez