Skip to content

Commit

Permalink
Glonass ephemeris ECC/validation tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav P <vladisslav2011@gmail.com>
  • Loading branch information
vladisslav2011 committed Sep 11, 2022
1 parent 0abf816 commit 3cbfc6b
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void glonass_l1_ca_telemetry_decoder_gs::decode_string(const double *frame_symbo
if (d_nav.have_new_ephemeris() == true)
{
// get object for this SV (mandatory)
bool is_ecc = d_nav.get_eph_ecc();
d_nav.set_rf_link(d_satellite.get_rf_link());
const std::shared_ptr<Glonass_Gnav_Ephemeris> tmp_obj = std::make_shared<Glonass_Gnav_Ephemeris>(d_nav.get_ephemeris());
static Gnss_Ephemeris::history_set prev(27);
Expand All @@ -242,9 +243,14 @@ void glonass_l1_ca_telemetry_decoder_gs::decode_string(const double *frame_symbo
if (Gnss_Ephemeris::validate(prev, tmp_obj, d_validator_thr, d_validator_accept_first))
{
this->message_port_pub(pmt::mp("telemetry"), pmt::make_any(tmp_obj));
d_nav.reg_eph_pass(true, is_ecc);
LOG(INFO) << "GLONASS GNAV Ephemeris have been received in channel" << d_channel << " from satellite " << d_satellite;
std::cout << "New GLONASS L1 GNAV message received in channel " << d_channel << ": ephemeris from satellite " << d_satellite << '\n';
}
else
{
d_nav.reg_eph_pass(false, is_ecc);
}
}
else
{
Expand Down
75 changes: 74 additions & 1 deletion src/core/system_parameters/glonass_gnav_navigation_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@
#include <cstddef> // for size_t
#include <iostream> // for operator<<

int Glonass_Gnav_Navigation_Message::d_strings_decoded = 0;
int Glonass_Gnav_Navigation_Message::d_strings_corrected = 0;
int Glonass_Gnav_Navigation_Message::d_strings_dropped = 0;
int Glonass_Gnav_Navigation_Message::d_ephemeris_with_ecc = 0;
int Glonass_Gnav_Navigation_Message::d_ephemeris_total = 0;
int Glonass_Gnav_Navigation_Message::d_strings_dropped_csigma = 0;
int Glonass_Gnav_Navigation_Message::d_ephemeris_dropped = 0;
int Glonass_Gnav_Navigation_Message::d_ephemeris_dropped_ecc = 0;

struct ecc_stats_printer
{
ecc_stats_printer() = default;
~ecc_stats_printer()
{
int strings_decoded = 0;
int strings_corrected = 0;
int strings_dropped = 0;
int strings_dropped_csigma = 0;
int ephemeris_with_ecc = 0;
int ephemeris_total = 0;
int ephemeris_dropped = 0;
int ephemeris_dropped_ecc = 0;
Glonass_Gnav_Navigation_Message::get_ecc_stats(strings_decoded, strings_corrected, strings_dropped, strings_dropped_csigma, ephemeris_total, ephemeris_with_ecc, ephemeris_dropped, ephemeris_dropped_ecc);
printf("Glonass_Gnav_Navigation_Message:strings_decoded=%d\n", strings_decoded);
printf("Glonass_Gnav_Navigation_Message:strings_corrected=%d (%3.3f%%)\n", strings_corrected, float(strings_corrected) * 100.0F / float(strings_decoded + strings_corrected + strings_dropped));
printf("Glonass_Gnav_Navigation_Message:strings_dropped=%d (%3.3f%%)\n", strings_dropped, float(strings_dropped) * 100.0F / float(strings_decoded + strings_corrected + strings_dropped));
printf("Glonass_Gnav_Navigation_Message:strings_dropped_csigma=%d (%3.3f%%)\n", strings_dropped_csigma, float(strings_dropped_csigma) * 100.0F / float(strings_decoded + strings_corrected + strings_dropped));
printf("Glonass_Gnav_Navigation_Message:ephemeris_total=%d\n", ephemeris_total);
printf("Glonass_Gnav_Navigation_Message:ephemeris_with_ecc=%d (%3.3f%%)\n", ephemeris_with_ecc, float(ephemeris_with_ecc) * 100.0F / float(ephemeris_total));
printf("Glonass_Gnav_Navigation_Message:ephemeris_dropped=%d (%3.3f%%)\n", ephemeris_dropped, float(ephemeris_dropped) * 100.0F / float(ephemeris_total));
printf("Glonass_Gnav_Navigation_Message:ephemeris_dropped_ecc=%d (%3.3f%%)\n", ephemeris_dropped_ecc, float(ephemeris_dropped_ecc) * 100.0F / float(ephemeris_total));
}
};

static struct ecc_stats_printer stats_printer;


Glonass_Gnav_Navigation_Message::Glonass_Gnav_Navigation_Message() : d_prev_TOW(-1.0)
{
Expand All @@ -36,7 +72,7 @@ Glonass_Gnav_Navigation_Message::Glonass_Gnav_Navigation_Message() : d_prev_TOW(
}


bool Glonass_Gnav_Navigation_Message::CRC_test(std::bitset<GLONASS_GNAV_STRING_BITS>& bits) const
bool Glonass_Gnav_Navigation_Message::CRC_test(std::bitset<GLONASS_GNAV_STRING_BITS>& bits)
{
uint32_t sum_bits = 0;
int32_t sum_hamming = 0;
Expand Down Expand Up @@ -120,14 +156,22 @@ bool Glonass_Gnav_Navigation_Message::CRC_test(std::bitset<GLONASS_GNAV_STRING_B
// (a-i) All checksums (C1,...,C7 and C_Sigma) are equal to zero
if ((C1 + C2 + C3 + C4 + C5 + C6 + C7 + C_Sigma) == 0)
{
d_strings_decoded++;
return true;
}
// (a-ii) Only one of the checksums (C1,...,C7) is equal to 1 and C_Sigma = 1
if (C_Sigma == 1 && C1 + C2 + C3 + C4 + C5 + C6 + C7 == 1)
{
d_strings_decoded++;
return true;
}

if (C_Sigma == 1 && C1 + C2 + C3 + C4 + C5 + C6 + C7 == 0)
{
d_strings_dropped_csigma++;
return false;
}

if (C_Sigma && (sum_bits & 1))
{
int32_t syndrome = C1;
Expand All @@ -141,15 +185,19 @@ bool Glonass_Gnav_Navigation_Message::CRC_test(std::bitset<GLONASS_GNAV_STRING_B
{
const int32_t locator = GLONASS_GNAV_ECC_LOCATOR[syndrome];
bits[locator] = !bits[locator];
d_strings_corrected++;
d_ecc = true;
return true;
}
else
{
d_strings_dropped++;
return false;
}
}

// All other conditions are assumed errors.
d_strings_dropped++;
return false;
}

Expand Down Expand Up @@ -262,9 +310,11 @@ int32_t Glonass_Gnav_Navigation_Message::string_decoder(const std::string& frame
std::bitset<GLONASS_GNAV_STRING_BITS> string_bits(frame_string);

// Perform data verification and exit code if error in bit sequence
d_ecc = false;
flag_CRC_test = CRC_test(string_bits);
if (flag_CRC_test == false)
{
d_strings_corrected_l = 0;
return 0;
}

Expand All @@ -284,6 +334,10 @@ int32_t Glonass_Gnav_Navigation_Message::string_decoder(const std::string& frame
gnav_ephemeris.d_Xn = static_cast<double>(read_navigation_signed(string_bits, X_N)) * TWO_N11;

flag_ephemeris_str_1 = true;
if (d_ecc)
{
d_strings_corrected_l++;
}

break;

Expand All @@ -300,6 +354,10 @@ int32_t Glonass_Gnav_Navigation_Message::string_decoder(const std::string& frame

gnav_ephemeris.d_iode = read_navigation_unsigned(string_bits, T_B);
flag_ephemeris_str_2 = true;
if (d_ecc)
{
d_strings_corrected_l++;
}
}

break;
Expand All @@ -317,6 +375,10 @@ int32_t Glonass_Gnav_Navigation_Message::string_decoder(const std::string& frame
gnav_ephemeris.d_Zn = static_cast<double>(read_navigation_signed(string_bits, Z_N)) * TWO_N11;

flag_ephemeris_str_3 = true;
if (d_ecc)
{
d_strings_corrected_l++;
}
}

break;
Expand All @@ -340,6 +402,10 @@ int32_t Glonass_Gnav_Navigation_Message::string_decoder(const std::string& frame
gnav_ephemeris.PRN = static_cast<uint32_t>(gnav_ephemeris.d_n);

flag_ephemeris_str_4 = true;
if (d_ecc)
{
d_strings_corrected_l++;
}
}

break;
Expand Down Expand Up @@ -677,6 +743,13 @@ bool Glonass_Gnav_Navigation_Message::have_new_ephemeris() // Check if we have
// Update the time of ephemeris information
d_previous_tb = gnav_ephemeris.d_t_b;
DLOG(INFO) << "GLONASS GNAV Ephemeris (1, 2, 3, 4) have been received and belong to the same batch";
if (d_strings_corrected_l)
{
d_ephemeris_with_ecc++;
d_strings_corrected_l = 0;
d_eph_ecc = true;
}
d_ephemeris_total++;
new_eph = true;
}

Expand Down
47 changes: 46 additions & 1 deletion src/core/system_parameters/glonass_gnav_navigation_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Glonass_Gnav_Navigation_Message
* \brief Compute CRC for GLONASS GNAV strings
* \param bits Bits of the string message where to compute CRC
*/
bool CRC_test(std::bitset<GLONASS_GNAV_STRING_BITS>& bits) const;
bool CRC_test(std::bitset<GLONASS_GNAV_STRING_BITS>& bits);

/*!
* \brief Computes the frame number being decoded given the satellite slot number
Expand Down Expand Up @@ -169,6 +169,40 @@ class Glonass_Gnav_Navigation_Message
flag_ephemeris_str_4 = ephemeris_str_4;
}

inline bool get_eph_ecc()
{
bool tmp = d_eph_ecc;
d_eph_ecc = false;
return tmp;
}

inline void reg_eph_pass(bool passed, bool ecc)
{
if (!passed)
{
if (ecc)
{
d_ephemeris_dropped_ecc++;
}
else
{
d_ephemeris_dropped++;
}
}
}

static inline void get_ecc_stats(int& strings_decoded, int& strings_corrected, int& strings_dropped, int& strings_dropped_csigma, int& ephemeris_total, int& ephemeris_with_ecc, int& ephemeris_dropped, int& ephemeris_dropped_ecc)
{
strings_decoded = d_strings_decoded;
strings_corrected = d_strings_corrected;
strings_dropped = d_strings_dropped;
strings_dropped_csigma = d_strings_dropped_csigma;
ephemeris_total = d_ephemeris_total;
ephemeris_with_ecc = d_ephemeris_with_ecc;
ephemeris_dropped = d_ephemeris_dropped;
ephemeris_dropped_ecc = d_ephemeris_dropped_ecc;
}

private:
uint64_t read_navigation_unsigned(const std::bitset<GLONASS_GNAV_STRING_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
int64_t read_navigation_signed(const std::bitset<GLONASS_GNAV_STRING_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& parameter) const;
Expand Down Expand Up @@ -215,6 +249,17 @@ class Glonass_Gnav_Navigation_Message
bool flag_TOW_set{}; // Flag indicating when the TOW has been set
bool flag_TOW_new{}; // Flag indicating when a new TOW has been computed
double d_prev_TOW{};
static int d_strings_decoded;
static int d_strings_corrected;
static int d_strings_dropped;
static int d_strings_dropped_csigma;
static int d_ephemeris_with_ecc;
static int d_ephemeris_total;
static int d_ephemeris_dropped;
static int d_ephemeris_dropped_ecc;
bool d_ecc{false};
bool d_eph_ecc{false};
int d_strings_corrected_l{0};
};


Expand Down

0 comments on commit 3cbfc6b

Please sign in to comment.