diff --git a/src/core/system_parameters/galileo_ism.cc b/src/core/system_parameters/galileo_ism.cc index a601176a0..a8847abfe 100644 --- a/src/core/system_parameters/galileo_ism.cc +++ b/src/core/system_parameters/galileo_ism.cc @@ -15,9 +15,7 @@ */ #include "galileo_ism.h" -#include #include -#include 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& bits) { - boost::dynamic_bitset frame_bits(bits.to_string().substr(0, GALILEO_ISM_CRC_DATA_BITS)); - std::vector 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 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; diff --git a/src/core/system_parameters/galileo_ism.h b/src/core/system_parameters/galileo_ism.h index 39a26f116..37a564de3 100644 --- a/src/core/system_parameters/galileo_ism.h +++ b/src/core/system_parameters/galileo_ism.h @@ -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& data); private: boost::crc_basic<32> crc32_ism; + uint32_t compute_crc(const std::vector& data); // ICD 2.1 Table 97 std::unordered_map ISM_PCONST_MAP = { diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index bdc565e0d..3a0970f9a 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -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" diff --git a/src/tests/unit-tests/system-parameters/galileo_ism_test.cc b/src/tests/unit-tests/system-parameters/galileo_ism_test.cc index 07573603b..b2b36166e 100644 --- a/src/tests/unit-tests/system-parameters/galileo_ism_test.cc +++ b/src/tests/unit-tests/system-parameters/galileo_ism_test.cc @@ -17,27 +17,14 @@ #include "galileo_ism.h" #include -#include -#include -#include 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 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(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); } \ No newline at end of file