1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-04 23:40:04 +00:00

Improve CRC computation of ISM

This commit is contained in:
Carles Fernandez 2024-09-21 10:22:32 +02:00
parent e23d171b22
commit bc800dea28
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 26 additions and 15 deletions

View File

@ -1323,8 +1323,6 @@ int32_t Galileo_Inav_Message::page_jk_decoder(const char* data_jk)
DLOG(INFO) << "Word type 22 arrived";
ism_constellation_id = read_octet_unsigned(data_jk_bits, ISM_CONSTELLATION_ID_BIT);
ism_service_level_id = read_octet_unsigned(data_jk_bits, ISM_SERVICE_LEVEL_ID_BIT);
ism_crc = static_cast<uint32_t>(read_navigation_unsigned(data_jk_bits, ISM_CRC_BIT));
gal_ism.set_ism_crc(ism_crc);
if (gal_ism.check_ism_crc(data_jk_bits))
{
DLOG(INFO) << "I/NAV ARAIM Integrity Support Message CRC OK";

View File

@ -187,20 +187,25 @@ uint16_t Galileo_ISM::get_Tvalidity_hours() const
bool Galileo_ISM::check_ism_crc(const std::bitset<GALILEO_DATA_JK_BITS>& bits)
{
std::bitset<GALILEO_ISM_CRC_DATA_BITS> extracted;
std::bitset<GALILEO_ISM_CRC_DATA_BITS> data_bits;
for (int32_t i = 0; i < GALILEO_ISM_CRC_DATA_BITS; ++i)
{
extracted[i] = bits[i + 32];
data_bits[i] = bits[i + 32];
}
std::bitset<32> crc_bits;
for (int32_t i = 0; i < 32; ++i)
{
crc_bits[i] = bits[i];
}
ism_crc = crc_bits.to_ulong();
std::vector<uint8_t> data_bytes((extracted.size() + 7) / 8);
for (size_t i = 0; i < extracted.size(); i += 8)
std::vector<uint8_t> data_bytes((data_bits.size() + 7) / 8);
for (size_t i = 0; i < data_bits.size(); i += 8)
{
uint8_t byte = 0;
for (size_t j = 0; j < 8 && i + j < extracted.size(); ++j)
for (size_t j = 0; j < 8 && i + j < data_bits.size(); ++j)
{
byte |= (extracted[i + j] << j);
byte |= (data_bits[i + j] << j);
}
data_bytes[i / 8] = byte;
}
@ -220,5 +225,7 @@ bool Galileo_ISM::check_ism_crc(const std::bitset<GALILEO_DATA_JK_BITS>& bits)
uint32_t Galileo_ISM::compute_crc(const std::vector<uint8_t>& data)
{
crc32_ism.process_bytes(data.data(), data.size());
return crc32_ism.checksum();
const uint32_t crc = crc32_ism.checksum();
crc32_ism.reset();
return crc;
}

View File

@ -43,7 +43,7 @@ public:
/*!
* Default constructor
*/
Galileo_ISM() : crc32_ism(0x814141AB, 0, 0, false, false){};
Galileo_ISM() = default;
void set_ism_constellation_id(uint8_t const_id);
void set_ism_service_level_id(uint8_t sl_id);
@ -74,7 +74,7 @@ public:
private:
uint32_t compute_crc(const std::vector<uint8_t>& data);
boost::crc_basic<32> crc32_ism;
boost::crc_optimal<32, 0x814141AB, 0, 0, false, false> crc32_ism;
// ICD 2.1 Table 97
std::unordered_map<uint8_t, double> ISM_PCONST_MAP = {

View File

@ -9,7 +9,7 @@
* 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)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -22,9 +22,15 @@ TEST(GalileoISMTest, CRC)
{
// Example from ANNEX G Galileo ICD
Galileo_ISM gal_ism{};
uint32_t expected_crc = 3002390191;
gal_ism.set_ism_crc(expected_crc);
std::bitset<128> input{"01011000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010110010111101001101011010101111"};
bool result = gal_ism.check_ism_crc(input);
EXPECT_TRUE(result);
// Check if it can be used twice
std::bitset<128> input2 = input;
bool result2 = gal_ism.check_ism_crc(input2);
EXPECT_TRUE(result2);
// Check if it fails
input2.set(127);
bool result3 = gal_ism.check_ism_crc(input2);
EXPECT_TRUE(!result3);
}