From 557a7f7265d23733abc7b31be3407f8b3c30b6eb Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 28 Aug 2024 11:13:54 +0200 Subject: [PATCH 1/2] Add work on ISM --- src/core/system_parameters/galileo_ism.cc | 34 ++++++++++++++++++++++- src/core/system_parameters/galileo_ism.h | 19 +++++++------ src/tests/test_main.cc | 3 ++ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/core/system_parameters/galileo_ism.cc b/src/core/system_parameters/galileo_ism.cc index 847a4ecd6..24b5b6d82 100644 --- a/src/core/system_parameters/galileo_ism.cc +++ b/src/core/system_parameters/galileo_ism.cc @@ -184,7 +184,7 @@ bool Galileo_ISM::check_ism_crc(const std::bitset& bits) c boost::to_block_range(frame_bits, std::back_inserter(bytes)); std::reverse(bytes.begin(), bytes.end()); - boost::crc_32_type crc32_ism; + boost::crc_optimal<32, 0xC0A0A0D5, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc32_ism; crc32_ism.process_bytes(bytes.data(), GALILEO_ISM_CRC_DATA_BYTES); const uint32_t crc_computed = crc32_ism.checksum(); if (this->ism_crc == crc_computed) @@ -193,4 +193,36 @@ bool Galileo_ISM::check_ism_crc(const std::bitset& bits) c } return false; +} + + +bool Galileo_ISM::ism_apply_to_sat(uint32_t prn) const +{ + if (prn == 0 || prn > 63) + { + return false; + } + std::bitset<32> bs(this->ism_mask); + if (this->ism_mask_msb == 0) + { + if (prn <= 32) + { + return bs[prn - 1]; + } + else + { + return false; + } + } + else + { + if (prn > 32) + { + return bs[prn - 32]; + } + else + { + return false; + } + } } \ No newline at end of file diff --git a/src/core/system_parameters/galileo_ism.h b/src/core/system_parameters/galileo_ism.h index 12436a606..2066fe0ac 100644 --- a/src/core/system_parameters/galileo_ism.h +++ b/src/core/system_parameters/galileo_ism.h @@ -57,16 +57,17 @@ public: void set_ism_Tvalidity(uint8_t tvalidity); void set_ism_crc(uint32_t crc); - bool check_ism_crc(const std::bitset& bits) const; + bool check_ism_crc(const std::bitset& bits) const; //!< Requires ism_crc to be already set + bool ism_apply_to_sat(uint32_t prn) const; //!< Returns true if ISM parameters apply to the prn satellite, false otherwise - double get_pconst_value() const; - double get_psat_value() const; - float get_ura_m() const; - float get_ure_m() const; - float get_bnom_m() const; - uint16_t get_WN_ISM() const; - uint16_t get_t0_ISM() const; - uint16_t get_Tvalidity_hours() const; + double get_pconst_value() const; //!< A priori constellation fault probability + double get_psat_value() const; //!< A priori satellite fault probability + float get_ura_m() const; //!< User Range Accuracy, in m, used for integrity + float get_ure_m() const; //!< User Range Error, in m, used for accuracy + float get_bnom_m() const; //!< Maximum nominal bias for a satellite, in m + uint16_t get_WN_ISM() const; //!< ISM Week Number, in weeks + uint16_t get_t0_ISM() const; //!< ISM Time of Week, in seconds + uint16_t get_Tvalidity_hours() const; //!< Validity duration of ISM content, in hours private: // ICD 2.1 Table 97 diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index 3769756aa..00f1f9458 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -95,6 +95,9 @@ DECLARE_string(log_dir); #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" +#include "unit-tests/system-parameters/galileo_ism_test.cc" + + #ifndef EXCLUDE_TESTS_REQUIRING_BINARIES #include "unit-tests/control-plane/control_thread_test.cc" From 583ae6df0d5255e033d087fbfbdfe746d3d4472b Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 20 Sep 2024 14:50:31 +0200 Subject: [PATCH 2/2] Fix CRC computation in ISM --- src/core/system_parameters/galileo_ism.cc | 40 ++---------- src/core/system_parameters/galileo_ism.h | 28 +++++---- src/tests/test_main.cc | 62 ++++++++++++++++--- .../system-parameters/galileo_ism_test.cc | 43 +++++++++++++ 4 files changed, 119 insertions(+), 54 deletions(-) create mode 100644 src/tests/unit-tests/system-parameters/galileo_ism_test.cc diff --git a/src/core/system_parameters/galileo_ism.cc b/src/core/system_parameters/galileo_ism.cc index 24b5b6d82..a601176a0 100644 --- a/src/core/system_parameters/galileo_ism.cc +++ b/src/core/system_parameters/galileo_ism.cc @@ -15,7 +15,6 @@ */ #include "galileo_ism.h" -#include #include #include #include @@ -176,15 +175,12 @@ uint16_t Galileo_ISM::get_Tvalidity_hours() const } -bool Galileo_ISM::check_ism_crc(const std::bitset& bits) 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()); - - boost::crc_optimal<32, 0xC0A0A0D5, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc32_ism; crc32_ism.process_bytes(bytes.data(), GALILEO_ISM_CRC_DATA_BYTES); const uint32_t crc_computed = crc32_ism.checksum(); if (this->ism_crc == crc_computed) @@ -196,33 +192,9 @@ bool Galileo_ISM::check_ism_crc(const std::bitset& bits) c } -bool Galileo_ISM::ism_apply_to_sat(uint32_t prn) const +uint32_t Galileo_ISM::compute_crc(const std::vector& data) { - if (prn == 0 || prn > 63) - { - return false; - } - std::bitset<32> bs(this->ism_mask); - if (this->ism_mask_msb == 0) - { - if (prn <= 32) - { - return bs[prn - 1]; - } - else - { - return false; - } - } - else - { - if (prn > 32) - { - return bs[prn - 32]; - } - else - { - return false; - } - } -} \ No newline at end of file + crc32_ism.process_bytes(data.data(), data.size()); + uint32_t result = crc32_ism.checksum(); + return result; +} diff --git a/src/core/system_parameters/galileo_ism.h b/src/core/system_parameters/galileo_ism.h index 2066fe0ac..39a26f116 100644 --- a/src/core/system_parameters/galileo_ism.h +++ b/src/core/system_parameters/galileo_ism.h @@ -19,9 +19,11 @@ #define GNSS_SDR_GALILEO_ISM_H #include "Galileo_INAV.h" +#include #include #include #include +#include /** \addtogroup Core * \{ */ @@ -41,7 +43,7 @@ public: /*! * Default constructor */ - Galileo_ISM() = default; + Galileo_ISM() : crc32_ism(0x814141AB, 0, 0, false, false) {}; void set_ism_constellation_id(uint8_t const_id); void set_ism_service_level_id(uint8_t sl_id); @@ -57,19 +59,21 @@ public: void set_ism_Tvalidity(uint8_t tvalidity); void set_ism_crc(uint32_t crc); - bool check_ism_crc(const std::bitset& bits) const; //!< Requires ism_crc to be already set - bool ism_apply_to_sat(uint32_t prn) const; //!< Returns true if ISM parameters apply to the prn satellite, false otherwise + bool check_ism_crc(const std::bitset& bits); - double get_pconst_value() const; //!< A priori constellation fault probability - double get_psat_value() const; //!< A priori satellite fault probability - float get_ura_m() const; //!< User Range Accuracy, in m, used for integrity - float get_ure_m() const; //!< User Range Error, in m, used for accuracy - float get_bnom_m() const; //!< Maximum nominal bias for a satellite, in m - uint16_t get_WN_ISM() const; //!< ISM Week Number, in weeks - uint16_t get_t0_ISM() const; //!< ISM Time of Week, in seconds - uint16_t get_Tvalidity_hours() const; //!< Validity duration of ISM content, in hours + double get_pconst_value() const; + double get_psat_value() const; + float get_ura_m() const; + float get_ure_m() const; + float get_bnom_m() const; + 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; + // ICD 2.1 Table 97 std::unordered_map ISM_PCONST_MAP = { {0, 1.0e-8}, @@ -146,7 +150,6 @@ private: {14, 3.75}, {15, 4.00}}; - // ICD 2.1 Table 101 std::unordered_map ISM_BNOM_MAP = { {0, 0.0}, @@ -166,7 +169,6 @@ private: {14, 2.0}, {15, 2.4}}; - // ICD 2.1 Table 102 std::unordered_map ISM_TVALIDITY_MAP = { {0, 1}, diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index 00f1f9458..bdc565e0d 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -18,19 +18,59 @@ #include "concurrent_map.h" #include "concurrent_queue.h" #include "gps_acq_assist.h" +#include +#include +#include +#include +#include + +#if USE_GLOG_AND_GFLAGS #include #include -#include -#include - #if GFLAGS_OLD_NAMESPACE namespace gflags { using namespace google; } +DECLARE_string(log_dir); +#endif +#else +#include "gnss_sdr_flags.h" +#include +#include +#include +#include +#include +#include +#include +#include + +class TestingLogSink : public absl::LogSink +{ +public: + TestingLogSink() + { + if (!absl::GetFlag(FLAGS_log_dir).empty()) + { + filename = std::string(absl::GetFlag(FLAGS_log_dir) + "/run_tests.log"); + } + else + { + filename = std::string(GetTempDir() + "/run_tests.log"); + } + logfile.open(filename); + } + void Send(const absl::LogEntry &entry) override + { + logfile << entry.text_message_with_prefix_and_newline() << std::flush; + } + +private: + std::ofstream logfile; + std::string filename; +}; #endif -DECLARE_string(log_dir); #if UNIT_TESTING_MINIMAL #include "unit-tests/arithmetic/matio_test.cc" @@ -95,9 +135,6 @@ DECLARE_string(log_dir); #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" -#include "unit-tests/system-parameters/galileo_ism_test.cc" - - #ifndef EXCLUDE_TESTS_REQUIRING_BINARIES #include "unit-tests/control-plane/control_thread_test.cc" @@ -177,8 +214,15 @@ int main(int argc, char **argv) catch (...) { } // catch the "testing::internal::::ClassUniqueToAlwaysTrue" from gtest +#if USE_GLOG_AND_GFLAGS gflags::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); +#else + absl::ParseCommandLine(argc, argv); + absl::LogSink *testLogSink = new TestingLogSink; + absl::AddLogSink(testLogSink); + absl::InitializeLog(); +#endif try { res = RUN_ALL_TESTS(); @@ -187,6 +231,10 @@ int main(int argc, char **argv) { LOG(WARNING) << "Unexpected catch"; } +#if USE_GLOG_AND_GFLAGS gflags::ShutDownCommandLineFlags(); +#else + absl::FlushLogSinks(); +#endif return res; } diff --git a/src/tests/unit-tests/system-parameters/galileo_ism_test.cc b/src/tests/unit-tests/system-parameters/galileo_ism_test.cc new file mode 100644 index 000000000..07573603b --- /dev/null +++ b/src/tests/unit-tests/system-parameters/galileo_ism_test.cc @@ -0,0 +1,43 @@ +/*! + * \file galileo_ism_test.cc + * \brief Tests for Galileo Integrity Support Message + * \author Carles Fernandez-Prades, 2024. cfernandez(at)cttc.es + * + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2023 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "galileo_ism.h" +#include +#include +#include +#include + +TEST(GalileoISMTest, CRC) +{ + 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); +} \ No newline at end of file