mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-04 23:40:04 +00:00
Fix CRC computation in ISM
This commit is contained in:
parent
557a7f7265
commit
583ae6df0d
@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
#include "galileo_ism.h"
|
||||
#include <boost/crc.hpp>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
@ -176,15 +175,12 @@ uint16_t Galileo_ISM::get_Tvalidity_hours() const
|
||||
}
|
||||
|
||||
|
||||
bool Galileo_ISM::check_ism_crc(const std::bitset<GALILEO_DATA_JK_BITS>& bits) 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());
|
||||
|
||||
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<GALILEO_DATA_JK_BITS>& bits) c
|
||||
}
|
||||
|
||||
|
||||
bool Galileo_ISM::ism_apply_to_sat(uint32_t prn) const
|
||||
uint32_t Galileo_ISM::compute_crc(const std::vector<uint8_t>& 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
crc32_ism.process_bytes(data.data(), data.size());
|
||||
uint32_t result = crc32_ism.checksum();
|
||||
return result;
|
||||
}
|
||||
|
@ -19,9 +19,11 @@
|
||||
#define GNSS_SDR_GALILEO_ISM_H
|
||||
|
||||
#include "Galileo_INAV.h"
|
||||
#include <boost/crc.hpp>
|
||||
#include <bitset>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** \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<GALILEO_DATA_JK_BITS>& 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<GALILEO_DATA_JK_BITS>& 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<uint8_t>& data);
|
||||
|
||||
private:
|
||||
boost::crc_basic<32> crc32_ism;
|
||||
|
||||
// ICD 2.1 Table 97
|
||||
std::unordered_map<uint8_t, double> 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<uint8_t, float> 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<uint8_t, uint16_t> ISM_TVALIDITY_MAP = {
|
||||
{0, 1},
|
||||
|
@ -18,19 +18,59 @@
|
||||
#include "concurrent_map.h"
|
||||
#include "concurrent_queue.h"
|
||||
#include "gps_acq_assist.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#if USE_GLOG_AND_GFLAGS
|
||||
#include <gflags/gflags.h>
|
||||
#include <glog/logging.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#if GFLAGS_OLD_NAMESPACE
|
||||
namespace gflags
|
||||
{
|
||||
using namespace google;
|
||||
}
|
||||
DECLARE_string(log_dir);
|
||||
#endif
|
||||
#else
|
||||
#include "gnss_sdr_flags.h"
|
||||
#include <absl/flags/flag.h>
|
||||
#include <absl/flags/parse.h>
|
||||
#include <absl/log/flags.h>
|
||||
#include <absl/log/globals.h>
|
||||
#include <absl/log/initialize.h>
|
||||
#include <absl/log/log.h>
|
||||
#include <absl/log/log_sink.h>
|
||||
#include <absl/log/log_sink_registry.h>
|
||||
|
||||
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::<unnamed>::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;
|
||||
}
|
||||
|
43
src/tests/unit-tests/system-parameters/galileo_ism_test.cc
Normal file
43
src/tests/unit-tests/system-parameters/galileo_ism_test.cc
Normal file
@ -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 <gtest/gtest.h>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <vector>
|
||||
|
||||
TEST(GalileoISMTest, CRC)
|
||||
{
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user