mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2026-11-24 16:17:22 +00:00
Merge branch 'MrCry0-fix/beidou-glonass-pll-180-flag-next' into next
This commit is contained in:
18 files changed
+673
-42
No files matched your search
@@ -25,6 +25,14 @@ All notable changes to GNSS-SDR will be documented in this file.
|
||||
- Fixed the Galileo E5b BGD scaling and the ionospheric scaling of E5b
|
||||
measurements in GPS L5 + Galileo E5b receivers, where the factors were
|
||||
referenced to the E5a wavelength held in the first slot instead of to E1.
|
||||
- Fixed the half-cycle ambiguity of the carrier phase measurements for BeiDou
|
||||
B1I and B3I and GLONASS L1 and L2 C/A signals, which their telemetry decoders
|
||||
left unresolved.
|
||||
- Fixed the half-cycle ambiguity of the carrier phase measurements for the
|
||||
BeiDou B2a signal, which its telemetry decoder left unresolved.
|
||||
- Fixed the half-cycle ambiguity of the carrier phase measurements for GPS L2C
|
||||
and for GPS and QZSS L5 tracked on the data component, which the CNAV
|
||||
telemetry decoder resolved wrongly for some satellites.
|
||||
|
||||
### Improvements in Availability:
|
||||
|
||||
@@ -55,6 +63,13 @@ All notable changes to GNSS-SDR will be documented in this file.
|
||||
- Fixed the preamble search of the GPS CNAV message decoder used by the GPS L2C
|
||||
and L5 telemetry decoders, which could miss the first message after the start
|
||||
of tracking. Contributed by @BenGant.
|
||||
- The GPS CNAV message decoder now follows a half-cycle slip of the carrier
|
||||
tracking loop at the next message. Before, it decoded no more messages, and
|
||||
the GPS L2C or L5 satellite was dropped one minute later.
|
||||
- Fixed the tracking of the data component (`track_pilot=false`) of GPS L5,
|
||||
Galileo E5a and E5b, and QZSS L5 signals, which did not remove the secondary
|
||||
code from the symbols delivered to the telemetry decoder. This weakened them,
|
||||
and left the Galileo E5b carrier phase half a cycle off.
|
||||
|
||||
### Improvements in Efficiency:
|
||||
|
||||
@@ -144,6 +159,10 @@ All notable changes to GNSS-SDR will be documented in this file.
|
||||
Before, the signals of a satellite in the same band group shared one lock time
|
||||
(GPS L2C with L5, Galileo E5a with E5b), and lock times never restarted, so
|
||||
rovers could not detect cycle slips from them.
|
||||
- Carrier phases are now aligned to the reference signal of the RINEX phase
|
||||
alignment: those measured on the pilot component of GPS L5, Galileo E5a and
|
||||
E5b, BeiDou B1C and B2a, and QZSS L5 signals to their data component, and GPS
|
||||
L1C to L1 C/A. They were a quarter of a cycle off.
|
||||
|
||||
### Improvements in Maintainability:
|
||||
|
||||
@@ -183,6 +202,8 @@ All notable changes to GNSS-SDR will be documented in this file.
|
||||
`Tracking_XX.max_carrier_lock_fail` was set above 300000 or 200000,
|
||||
respectively, so a false lock that the carrier lock test did not drop kept its
|
||||
channel until the end of the run.
|
||||
- Fixed `TelemetryDecoder_XX.dump_crc_stats=true` in the GPS L2C and L5
|
||||
telemetry decoders, which never counted a failed CRC check.
|
||||
|
||||
### Improvements in Reproducibility:
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "beidou_b2a_telemetry_decoder_gs.h"
|
||||
#include "Beidou_B2a.h"
|
||||
#include "Beidou_DNAV.h"
|
||||
#include "MATH_CONSTANTS.h"
|
||||
#include "beidou_cnav1_ephemeris.h"
|
||||
#include "display.h"
|
||||
#include "gnss_satellite.h"
|
||||
@@ -115,6 +116,7 @@ void beidou_b2a_telemetry_decoder_gs::reset()
|
||||
d_symbol_history.clear();
|
||||
d_flag_frame_sync = false;
|
||||
d_flag_valid_word = false;
|
||||
d_flag_PLL_180_deg_phase_locked = false;
|
||||
d_CRC_error_counter = 0;
|
||||
d_sample_counter = 0;
|
||||
d_preamble_index = 0;
|
||||
@@ -246,6 +248,7 @@ int beidou_b2a_telemetry_decoder_gs::general_work(
|
||||
d_flag_frame_sync = true;
|
||||
d_CRC_error_counter = 0;
|
||||
d_flag_valid_word = true;
|
||||
d_flag_PLL_180_deg_phase_locked = d_nav.last_frame_inverted();
|
||||
d_preamble_index = d_sample_counter;
|
||||
const int32_t sow = d_nav.last_sow();
|
||||
LOG(INFO) << "B-CNAV2 CRC ok ch " << d_channel
|
||||
@@ -301,6 +304,16 @@ int beidou_b2a_telemetry_decoder_gs::general_work(
|
||||
{
|
||||
current.Flag_valid_word = true;
|
||||
current.TOW_at_current_symbol_ms = d_TOW_at_current_symbol_ms;
|
||||
if (d_flag_PLL_180_deg_phase_locked)
|
||||
{
|
||||
// correct the accumulated phase for the Costas loop phase shift, if required
|
||||
current.Carrier_phase_rads += GNSS_PI;
|
||||
current.Flag_PLL_180_deg_phase_locked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
current.Flag_PLL_180_deg_phase_locked = false;
|
||||
}
|
||||
if (d_tow_to_trk)
|
||||
{
|
||||
const auto tow_obj = std::make_shared<TOW_to_trk>(TOW_to_trk(
|
||||
|
||||
@@ -66,6 +66,7 @@ private:
|
||||
uint32_t d_TOW_at_current_symbol_ms{};
|
||||
bool d_flag_frame_sync{false};
|
||||
bool d_flag_valid_word{false};
|
||||
bool d_flag_PLL_180_deg_phase_locked{false}; // Preamble of the last decoded frame came inverted
|
||||
bool d_dump{false};
|
||||
bool d_dump_mat{false};
|
||||
bool d_remove_dat{false};
|
||||
|
||||
@@ -82,6 +82,7 @@ beidou_dnav_telemetry_decoder_gs::beidou_dnav_telemetry_decoder_gs(const Tlm_Con
|
||||
d_flag_SOW_set(false),
|
||||
d_flag_frame_sync(false),
|
||||
d_flag_preamble(false),
|
||||
d_flag_PLL_180_deg_phase_locked(false),
|
||||
d_flag_valid_word(false),
|
||||
d_sent_tlm_failed_msg(false),
|
||||
d_dump(conf.dump),
|
||||
@@ -502,6 +503,7 @@ int beidou_dnav_telemetry_decoder_gs::general_work(int noutput_items __attribute
|
||||
if (d_nav.get_flag_CRC_test() == true)
|
||||
{
|
||||
d_CRC_error_counter = 0;
|
||||
d_flag_PLL_180_deg_phase_locked = corr_value < 0;
|
||||
d_flag_preamble = true; // valid preamble indicator (initialized to false every work())
|
||||
d_preamble_index = d_sample_counter; // record the preamble sample stamp (t_P)
|
||||
if (!d_flag_frame_sync)
|
||||
@@ -560,6 +562,7 @@ int beidou_dnav_telemetry_decoder_gs::general_work(int noutput_items __attribute
|
||||
if (d_nav.get_flag_CRC_test() == true)
|
||||
{
|
||||
d_CRC_error_counter = 0;
|
||||
d_flag_PLL_180_deg_phase_locked = corr_value < 0;
|
||||
d_flag_preamble = true; // valid preamble indicator (initialized to false every work())
|
||||
d_preamble_index = d_sample_counter; // record the preamble sample stamp (t_P)
|
||||
if (!d_flag_frame_sync)
|
||||
@@ -637,6 +640,16 @@ int beidou_dnav_telemetry_decoder_gs::general_work(int noutput_items __attribute
|
||||
{
|
||||
current_symbol.TOW_at_current_symbol_ms = d_TOW_at_current_symbol_ms;
|
||||
current_symbol.Flag_valid_word = d_flag_valid_word;
|
||||
if (d_flag_PLL_180_deg_phase_locked == true)
|
||||
{
|
||||
// correct the accumulated phase for the Costas loop phase shift, if required
|
||||
current_symbol.Carrier_phase_rads += GNSS_PI;
|
||||
current_symbol.Flag_PLL_180_deg_phase_locked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_symbol.Flag_PLL_180_deg_phase_locked = false;
|
||||
}
|
||||
|
||||
if (d_dump == true)
|
||||
{
|
||||
|
||||
@@ -112,9 +112,10 @@ private:
|
||||
|
||||
const char d_band; // Frequency band the block is configured for ('1' for B1I, '3' for B3I)
|
||||
|
||||
bool d_flag_SOW_set; // Indicates when time of week is set
|
||||
bool d_flag_frame_sync; // Indicate when a frame sync is achieved
|
||||
bool d_flag_preamble; // Flag indicating when preamble was found
|
||||
bool d_flag_SOW_set; // Indicates when time of week is set
|
||||
bool d_flag_frame_sync; // Indicate when a frame sync is achieved
|
||||
bool d_flag_preamble; // Flag indicating when preamble was found
|
||||
bool d_flag_PLL_180_deg_phase_locked; // Preamble of the last decoded frame came inverted
|
||||
|
||||
bool d_flag_valid_word;
|
||||
bool d_sent_tlm_failed_msg;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
|
||||
#include "glonass_gnav_telemetry_decoder_gs.h"
|
||||
#include "MATH_CONSTANTS.h"
|
||||
#include "display.h"
|
||||
#include "dump_logger_helper.h"
|
||||
#include "glonass_gnav_almanac.h"
|
||||
@@ -69,6 +70,7 @@ glonass_gnav_telemetry_decoder_gs::glonass_gnav_telemetry_decoder_gs(const Tlm_C
|
||||
d_band(frequency_band == 2 ? '2' : '1'),
|
||||
d_flag_frame_sync(false),
|
||||
d_flag_preamble(false),
|
||||
d_flag_PLL_180_deg_phase_locked(false),
|
||||
d_dump(conf.dump),
|
||||
d_dump_mat(conf.dump_mat),
|
||||
d_remove_dat(conf.remove_dat),
|
||||
@@ -239,6 +241,7 @@ void glonass_gnav_telemetry_decoder_gs::reset()
|
||||
d_CRC_error_counter = 0;
|
||||
d_flag_frame_sync = false;
|
||||
d_flag_preamble = false;
|
||||
d_flag_PLL_180_deg_phase_locked = false;
|
||||
d_TOW_at_current_symbol = 0;
|
||||
// Invalidate the propagated TOW until a new string 5 is decoded; otherwise
|
||||
// Flag_valid_word would remain true with a TOW offset by the outage duration
|
||||
@@ -355,6 +358,7 @@ int glonass_gnav_telemetry_decoder_gs::general_work(int noutput_items __attribut
|
||||
if (crc_ok == true)
|
||||
{
|
||||
d_CRC_error_counter = 0;
|
||||
d_flag_PLL_180_deg_phase_locked = corr_value < 0;
|
||||
d_flag_preamble = true; // valid preamble indicator (initialized to false every work())
|
||||
d_preamble_index = d_sample_counter; // record the preamble sample stamp (t_P)
|
||||
if (!d_flag_frame_sync)
|
||||
@@ -413,6 +417,16 @@ int glonass_gnav_telemetry_decoder_gs::general_work(int noutput_items __attribut
|
||||
if (d_flag_frame_sync == true && d_nav.is_flag_TOW_set() == true)
|
||||
{
|
||||
current_symbol.Flag_valid_word = true;
|
||||
if (d_flag_PLL_180_deg_phase_locked == true)
|
||||
{
|
||||
// correct the accumulated phase for the Costas loop phase shift, if required
|
||||
current_symbol.Carrier_phase_rads += GNSS_PI;
|
||||
current_symbol.Flag_PLL_180_deg_phase_locked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_symbol.Flag_PLL_180_deg_phase_locked = false;
|
||||
}
|
||||
if (d_enable_navdata_monitor && !d_nav_msg_packet.nav_message.empty())
|
||||
{
|
||||
d_nav_msg_packet.prn = static_cast<int32_t>(current_symbol.PRN);
|
||||
|
||||
+3
-2
@@ -98,8 +98,9 @@ private:
|
||||
|
||||
const char d_band; // Frequency band the block is configured for ('1' or '2')
|
||||
|
||||
bool d_flag_frame_sync; // Indicate when a frame sync is achieved
|
||||
bool d_flag_preamble; // Flag indicating when preamble was found
|
||||
bool d_flag_frame_sync; // Indicate when a frame sync is achieved
|
||||
bool d_flag_preamble; // Flag indicating when preamble was found
|
||||
bool d_flag_PLL_180_deg_phase_locked; // Preamble of the last decoded frame came inverted
|
||||
const bool d_dump;
|
||||
const bool d_dump_mat;
|
||||
const bool d_remove_dat;
|
||||
|
||||
@@ -133,6 +133,7 @@ void gps_l2c_telemetry_decoder_gs::reset()
|
||||
d_TOW_at_current_symbol = 0;
|
||||
d_sent_tlm_failed_msg = false;
|
||||
d_flag_valid_word = false;
|
||||
d_flag_PLL_180_deg_phase_locked = false;
|
||||
DLOG(INFO) << "Telemetry decoder reset for satellite " << d_satellite;
|
||||
}
|
||||
|
||||
@@ -153,12 +154,17 @@ int gps_l2c_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
|
||||
// add the symbol to the decoder
|
||||
const uint8_t symbol_clip = static_cast<uint8_t>(in[0].Prompt_I > 0) * 255;
|
||||
flag_new_cnav_frame = cnav_msg_decoder_add_symbol(&d_cnav_decoder, symbol_clip, &msg, &delay);
|
||||
if (d_dump_crc_stats && (d_cnav_decoder.part1.message_lock || d_cnav_decoder.part2.message_lock))
|
||||
if (d_dump_crc_stats)
|
||||
{
|
||||
// update CRC statistics
|
||||
d_Tlm_CRC_Stats->update_CRC_stats((d_cnav_decoder.part1.crc_ok || d_cnav_decoder.part2.crc_ok));
|
||||
d_cnav_decoder.part1.message_lock = false;
|
||||
d_cnav_decoder.part2.message_lock = false;
|
||||
// update CRC statistics: one test per message checked under message lock
|
||||
if (d_cnav_decoder.crc_failed)
|
||||
{
|
||||
d_Tlm_CRC_Stats->update_CRC_stats(false);
|
||||
}
|
||||
if (flag_new_cnav_frame)
|
||||
{
|
||||
d_Tlm_CRC_Stats->update_CRC_stats(true);
|
||||
}
|
||||
}
|
||||
|
||||
consume_each(1); // one by one
|
||||
@@ -193,14 +199,8 @@ int gps_l2c_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
|
||||
// check if new CNAV frame is available
|
||||
if (flag_new_cnav_frame == true)
|
||||
{
|
||||
if (d_cnav_decoder.part1.invert == true || d_cnav_decoder.part2.invert == true)
|
||||
{
|
||||
d_flag_PLL_180_deg_phase_locked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_flag_PLL_180_deg_phase_locked = false;
|
||||
}
|
||||
// polarity of the symbols of this message, which has passed the CRC check
|
||||
d_flag_PLL_180_deg_phase_locked = msg.inverted;
|
||||
std::bitset<GPS_L2_CNAV_DATA_PAGE_BITS> raw_bits;
|
||||
// Expand packet bits to bitsets. Notice the reverse order of the bits sequence, required by the CNAV message decoder
|
||||
for (uint32_t i = 0; i < GPS_L2_CNAV_DATA_PAGE_BITS; i++)
|
||||
|
||||
@@ -152,6 +152,7 @@ void gps_l5_telemetry_decoder_gs::reset()
|
||||
d_TOW_at_current_symbol_ms = 0;
|
||||
d_sent_tlm_failed_msg = false;
|
||||
d_flag_valid_word = false;
|
||||
d_flag_PLL_180_deg_phase_locked = false;
|
||||
DLOG(INFO) << "Telemetry decoder reset for satellite " << d_satellite;
|
||||
}
|
||||
|
||||
@@ -199,24 +200,23 @@ int gps_l5_telemetry_decoder_gs::general_work(int noutput_items __attribute__((u
|
||||
// 2. Add the telemetry decoder information
|
||||
// check if new CNAV frame is available
|
||||
bool new_page = cnav_msg_decoder_add_symbol(&d_cnav_decoder, symbol_clip, &msg, &delay);
|
||||
if (d_dump_crc_stats && (d_cnav_decoder.part1.message_lock || d_cnav_decoder.part2.message_lock))
|
||||
if (d_dump_crc_stats)
|
||||
{
|
||||
// update CRC statistics
|
||||
d_Tlm_CRC_Stats->update_CRC_stats((d_cnav_decoder.part1.crc_ok || d_cnav_decoder.part2.crc_ok));
|
||||
d_cnav_decoder.part1.message_lock = false;
|
||||
d_cnav_decoder.part2.message_lock = false;
|
||||
// update CRC statistics: one test per message checked under message lock
|
||||
if (d_cnav_decoder.crc_failed)
|
||||
{
|
||||
d_Tlm_CRC_Stats->update_CRC_stats(false);
|
||||
}
|
||||
if (new_page)
|
||||
{
|
||||
d_Tlm_CRC_Stats->update_CRC_stats(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_page)
|
||||
{
|
||||
if (d_cnav_decoder.part1.invert == true || d_cnav_decoder.part2.invert == true)
|
||||
{
|
||||
d_flag_PLL_180_deg_phase_locked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_flag_PLL_180_deg_phase_locked = false;
|
||||
}
|
||||
// polarity of the symbols of this message, which has passed the CRC check
|
||||
d_flag_PLL_180_deg_phase_locked = msg.inverted;
|
||||
std::bitset<GPS_L5_CNAV_DATA_PAGE_BITS> raw_bits;
|
||||
// Expand packet bits to bitsets. Notice the reverse order of the bits sequence, required by the CNAV message decoder
|
||||
for (uint32_t i = 0; i < GPS_L5_CNAV_DATA_PAGE_BITS; i++)
|
||||
|
||||
@@ -153,6 +153,40 @@ static void cnav_rescan_preamble_(cnav_v27_part_t *part, bool skip_first)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a message that fails the CRC check is a valid message with
|
||||
* the opposite symbol polarity.
|
||||
* This is what a decoder component with message lock gets after a half-cycle
|
||||
* slip of the carrier tracking loop: the message starts with the other preamble
|
||||
* and its CRC matches once the bits are inverted. When that is the case, the
|
||||
* polarity of the component is updated.
|
||||
*
|
||||
* \param[in,out] part Decoder component with 300 bits of a message.
|
||||
*
|
||||
* \retval true The message is valid with the opposite polarity, and the
|
||||
* component now uses it.
|
||||
* \retval false The message is not valid with the opposite polarity either.
|
||||
*
|
||||
* \private
|
||||
*/
|
||||
static bool cnav_polarity_changed_(cnav_v27_part_t *part)
|
||||
{
|
||||
const uint32_t preamble = getbitu(part->decoded, 0, GPS_CNAV_PREAMBLE_LENGTH);
|
||||
const uint32_t other_preamble = part->invert ? GPS_CNAV_PREAMBLE1 : GPS_CNAV_PREAMBLE2;
|
||||
if (preamble != other_preamble)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
part->invert = !part->invert;
|
||||
if (cnav_compute_crc_(part) == cnav_extract_crc_(part))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
part->invert = !part->invert;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Feed a symbol into Viterbi decoder instance.
|
||||
*
|
||||
@@ -163,12 +197,15 @@ static void cnav_rescan_preamble_(cnav_v27_part_t *part, bool skip_first)
|
||||
* \param[in,out] part Decoder object
|
||||
* \param[in] s Symbol (0x00 - Hard 0, 0xFF - Hard 1)
|
||||
*
|
||||
* \return None
|
||||
* \retval true A message has failed the CRC check while the component had
|
||||
* message lock.
|
||||
* \retval false Otherwise.
|
||||
*
|
||||
* \private
|
||||
*/
|
||||
static void cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
static bool cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
{
|
||||
bool crc_failed = false;
|
||||
part->symbols[part->n_symbols++] = ch;
|
||||
|
||||
if (part->init)
|
||||
@@ -176,14 +213,14 @@ static void cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
/* Initial step - load more symbols without decoding. */
|
||||
if (part->n_symbols < (GPS_L2C_V27_INIT_BITS + GPS_L2C_V27_DECODE_BITS) * 2)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
part->init = false;
|
||||
}
|
||||
else if (part->n_symbols < GPS_L2C_V27_DECODE_BITS * 2)
|
||||
{
|
||||
/* Wait until decoding block is accumulated */
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Feed accumulated symbols into the buffer, reset the number of accumulated
|
||||
@@ -219,6 +256,8 @@ static void cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
* - If message lock
|
||||
* - If 300 bits collected, compute CRC
|
||||
* - If CRC is OK, message can be decoded
|
||||
* - If CRC is OK with the opposite polarity, the polarity is updated
|
||||
* and the message can be decoded
|
||||
* - If CRC is not OK, discard data
|
||||
*/
|
||||
|
||||
@@ -244,8 +283,10 @@ static void cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
|
||||
if (part->message_lock)
|
||||
{
|
||||
/* We have message lock */
|
||||
part->crc_ok = (crc == crc2);
|
||||
/* We have message lock. A message that only passes the CRC
|
||||
* check with the opposite polarity follows a half-cycle slip
|
||||
* of the carrier tracking loop. */
|
||||
part->crc_ok = (crc == crc2) || cnav_polarity_changed_(part);
|
||||
if (part->crc_ok)
|
||||
{
|
||||
/* Reset message lock counter */
|
||||
@@ -253,6 +294,7 @@ static void cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
}
|
||||
else
|
||||
{
|
||||
crc_failed = true;
|
||||
/* Increment message lock counter */
|
||||
part->n_crc_fail++;
|
||||
if (part->n_crc_fail > GPS_CNAV_LOCK_MAX_CRC_FAILS)
|
||||
@@ -291,6 +333,7 @@ static void cnav_add_symbol_(cnav_v27_part_t *part, uint8_t ch)
|
||||
/* No preamble or preamble and less than 300 bits decoded */
|
||||
}
|
||||
}
|
||||
return crc_failed;
|
||||
}
|
||||
|
||||
|
||||
@@ -322,7 +365,7 @@ static void cnav_msg_invert_(cnav_v27_part_t *part)
|
||||
* - Message data CRC matches one in the buffer.
|
||||
*
|
||||
* In case the message starts with inverted preamble, the data is inverted
|
||||
* before parsing.
|
||||
* before parsing, and \a msg reports it.
|
||||
*
|
||||
* \param[in,out] part Decoder component.
|
||||
* \param[out] msg Container for a decoded message.
|
||||
@@ -350,6 +393,10 @@ static bool cnav_msg_decode_(cnav_v27_part_t *part, cnav_msg_t *msg, uint32_t *d
|
||||
msg->msg_id = getbitu(part->decoded, 14, 6);
|
||||
msg->tow = getbitu(part->decoded, 20, 17);
|
||||
msg->alert = getbitu(part->decoded, 37, 1) ? true : false;
|
||||
/* Polarity of the decoder component that delivers the message. The
|
||||
* other component is not aligned to the symbol pairs, and its
|
||||
* invert flag only holds the last chance preamble match. */
|
||||
msg->inverted = part->invert;
|
||||
|
||||
/* copy RAW message for GNSS-SDR */
|
||||
memcpy(msg->raw_msg, part->decoded, GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS);
|
||||
@@ -399,7 +446,7 @@ void cnav_msg_decoder_init(cnav_msg_decoder_t *dec)
|
||||
0);
|
||||
dec->part1.init = true;
|
||||
dec->part2.init = true;
|
||||
cnav_add_symbol_(&dec->part2, 0x80);
|
||||
(void)cnav_add_symbol_(&dec->part2, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,6 +461,8 @@ void cnav_msg_decoder_init(cnav_msg_decoder_t *dec)
|
||||
* symbolTime_ms = msg->tow * 6000 + *pdelay * 20 (L2)
|
||||
* symbolTime_ms = msg->tow * 6000 + *pdelay * 10 (L5)
|
||||
* \endcode
|
||||
* Every message checked under message lock is reported once: a pass by the
|
||||
* return value, a failure by the \a crc_failed flag of \a dec.
|
||||
*
|
||||
* \param[in,out] dec Decoder object.
|
||||
* \param[in] symbol Symbol value probability, where 0x00 - 100% of 0,
|
||||
@@ -430,8 +479,9 @@ bool cnav_msg_decoder_add_symbol(cnav_msg_decoder_t *dec,
|
||||
cnav_msg_t *msg,
|
||||
uint32_t *pdelay)
|
||||
{
|
||||
cnav_add_symbol_(&dec->part1, symbol);
|
||||
cnav_add_symbol_(&dec->part2, symbol);
|
||||
const bool crc_failed1 = cnav_add_symbol_(&dec->part1, symbol);
|
||||
const bool crc_failed2 = cnav_add_symbol_(&dec->part2, symbol);
|
||||
dec->crc_failed = crc_failed1 || crc_failed2;
|
||||
|
||||
if (dec->part1.message_lock)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,7 @@ typedef struct
|
||||
uint8_t msg_id; /**< Message id. 0..31 */
|
||||
uint32_t tow; /**< GPS ToW in 6-second units. Multiply to 6 to get seconds. */
|
||||
bool alert; /**< CNAV message alert flag */
|
||||
bool inverted; /**< When true, the symbols of this message were received inverted */
|
||||
uint8_t raw_msg[GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS]; /**< RAW MSG for GNSS-SDR */
|
||||
} cnav_msg_t;
|
||||
|
||||
@@ -96,6 +97,8 @@ typedef struct
|
||||
{
|
||||
cnav_v27_part_t part1; /**< Decoder for odd symbol pairs */
|
||||
cnav_v27_part_t part2; /**< Decoder for even symbol pairs */
|
||||
bool crc_failed; /**< When true, the last symbol completed a message
|
||||
* that failed the CRC check under message lock. */
|
||||
} cnav_msg_decoder_t;
|
||||
|
||||
const v27_poly_t *cnav_msg_decoder_get_poly(void);
|
||||
|
||||
@@ -118,6 +118,7 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_)
|
||||
d_cfo_phase_step_rad(0.0),
|
||||
d_carrier_doppler_hz(0.0),
|
||||
d_acc_carrier_phase_rad(0.0),
|
||||
d_ref_carrier_phase_offset_rad(0.0),
|
||||
d_rem_code_phase_chips(0.0),
|
||||
d_T_chip_seconds(0.0),
|
||||
d_T_prn_seconds(0.0),
|
||||
@@ -280,6 +281,8 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_)
|
||||
// remove Neuman-Hofman Code (see IS-GPS-705D)
|
||||
d_secondary_code_length = static_cast<uint32_t>(GPS_L5I_NH_CODE_LENGTH);
|
||||
d_secondary_code_string = GPS_L5I_NH_CODE_STR;
|
||||
d_data_secondary_code_length = static_cast<uint32_t>(GPS_L5I_NH_CODE_LENGTH);
|
||||
d_data_secondary_code_string = GPS_L5I_NH_CODE_STR;
|
||||
d_signal_pretty_name = d_signal_pretty_name + "I";
|
||||
d_interchange_iq = true;
|
||||
}
|
||||
@@ -385,6 +388,8 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_)
|
||||
// synchronize and remove data secondary code
|
||||
d_secondary_code_length = static_cast<uint32_t>(GALILEO_E5A_I_SECONDARY_CODE_LENGTH);
|
||||
d_secondary_code_string = GALILEO_E5A_I_SECONDARY_CODE;
|
||||
d_data_secondary_code_length = static_cast<uint32_t>(GALILEO_E5A_I_SECONDARY_CODE_LENGTH);
|
||||
d_data_secondary_code_string = GALILEO_E5A_I_SECONDARY_CODE;
|
||||
d_signal_pretty_name = d_signal_pretty_name + "I";
|
||||
}
|
||||
}
|
||||
@@ -416,6 +421,8 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_)
|
||||
// synchronize and remove data secondary code
|
||||
d_secondary_code_length = static_cast<uint32_t>(GALILEO_E5B_I_SECONDARY_CODE_LENGTH);
|
||||
d_secondary_code_string = GALILEO_E5B_I_SECONDARY_CODE;
|
||||
d_data_secondary_code_length = static_cast<uint32_t>(GALILEO_E5B_I_SECONDARY_CODE_LENGTH);
|
||||
d_data_secondary_code_string = GALILEO_E5B_I_SECONDARY_CODE;
|
||||
d_signal_pretty_name = d_signal_pretty_name + "I";
|
||||
}
|
||||
}
|
||||
@@ -673,6 +680,8 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_)
|
||||
// remove Neuman-Hofman Code
|
||||
d_secondary_code_length = static_cast<uint32_t>(QZSS_L5I_NH_CODE_LENGTH);
|
||||
d_secondary_code_string = QZSS_L5I_NH_CODE_STR;
|
||||
d_data_secondary_code_length = static_cast<uint32_t>(QZSS_L5I_NH_CODE_LENGTH);
|
||||
d_data_secondary_code_string = QZSS_L5I_NH_CODE_STR;
|
||||
d_signal_pretty_name = d_signal_pretty_name + "I";
|
||||
d_interchange_iq = true;
|
||||
}
|
||||
@@ -742,6 +751,29 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_)
|
||||
d_symbols_per_bit = 0;
|
||||
}
|
||||
|
||||
// The carrier phase is reported for the reference signal of the RINEX phase
|
||||
// alignment, which is the data component of the signals with a pilot. When
|
||||
// the pilot is tracked and the telemetry symbols are read from the
|
||||
// quadrature output of the data correlator, the data carrier is in
|
||||
// quadrature with the NCO: a quarter of a cycle is added here, and the
|
||||
// telemetry decoder resolves the remaining half cycle from the polarity of
|
||||
// the data symbols, as it does when the data component is tracked. Pilots
|
||||
// in phase or in antiphase with the data component (Galileo E1 and E6, GPS
|
||||
// L1C) only need the decoder's half cycle.
|
||||
if (d_trk_parameters.track_pilot &&
|
||||
(d_signal_type == "L5" || d_signal_type == "J5" || d_signal_type == "5X" || d_signal_type == "7X" || d_signal_type == "5D" ||
|
||||
(d_signal_type == "1D" && d_trk_parameters.b1c_prompt_use_data_q)))
|
||||
{
|
||||
d_ref_carrier_phase_offset_rad = HALF_PI;
|
||||
}
|
||||
else if (d_signal_type == "1S")
|
||||
{
|
||||
// The reference signal of GPS L1C is L1 C/A, whose carrier is a
|
||||
// quarter of a cycle behind the L1CD and L1CP ones (+1/4 cycle for
|
||||
// L1S, L1L and L1X in RINEX 3.05, Table A23)
|
||||
d_ref_carrier_phase_offset_rad = -HALF_PI;
|
||||
}
|
||||
|
||||
// Initial code frequency basis of NCO
|
||||
d_code_freq_chips = d_code_chip_rate;
|
||||
|
||||
@@ -1645,7 +1677,7 @@ void dll_pll_veml_tracking::check_carrier_phase_coherent_initialization()
|
||||
{
|
||||
if (d_acc_carrier_phase_initialized == false)
|
||||
{
|
||||
d_acc_carrier_phase_rad = -d_rem_carr_phase_rad;
|
||||
d_acc_carrier_phase_rad = -(d_rem_carr_phase_rad + d_ref_carrier_phase_offset_rad);
|
||||
d_acc_carrier_phase_initialized = true;
|
||||
d_carrier_phase_discontinuity = true; // the carrier phase ambiguity starts again
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ private:
|
||||
double d_cfo_phase_step_rad;
|
||||
double d_carrier_doppler_hz;
|
||||
double d_acc_carrier_phase_rad;
|
||||
double d_ref_carrier_phase_offset_rad;
|
||||
double d_rem_code_phase_chips;
|
||||
double d_T_chip_seconds;
|
||||
double d_T_prn_seconds;
|
||||
|
||||
@@ -164,6 +164,7 @@ bool Beidou_Cnav2_Navigation_Message::decode_frame_symbols(const float* symbols,
|
||||
return false;
|
||||
}
|
||||
d_last_crc_ok = true;
|
||||
d_last_frame_inverted = corr < 0.0;
|
||||
d_last_nav_bits.clear();
|
||||
d_last_nav_bits.reserve(static_cast<size_t>(BEIDOU_CNAV2_INFO_BITS));
|
||||
for (int32_t i = 0; i < BEIDOU_CNAV2_INFO_BITS; i++)
|
||||
@@ -234,6 +235,7 @@ void Beidou_Cnav2_Navigation_Message::reset()
|
||||
d_have_published = false;
|
||||
d_flag_new_eph = false;
|
||||
d_last_crc_ok = false;
|
||||
d_last_frame_inverted = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
void clear_flags() { d_flag_new_eph = false; }
|
||||
void reset();
|
||||
bool last_crc_ok() const { return d_last_crc_ok; }
|
||||
bool last_frame_inverted() const { return d_last_frame_inverted; } //!< Symbol polarity of the last frame that passed its CRC
|
||||
int32_t last_mes_type() const { return d_last_mes_type; }
|
||||
int32_t last_sow() const { return d_last_sow; }
|
||||
uint32_t last_frame_prn() const { return d_last_frame_prn; }
|
||||
@@ -76,6 +77,7 @@ private:
|
||||
bool d_have_published{false};
|
||||
bool d_flag_new_eph{false};
|
||||
bool d_last_crc_ok{false};
|
||||
bool d_last_frame_inverted{false};
|
||||
};
|
||||
|
||||
/** \} */
|
||||
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
/*!
|
||||
* \file beidou_dnav_telemetry_decoder_test.cc
|
||||
* \brief Checks the 180-degree carrier phase lock reported by the BeiDou DNAV
|
||||
* telemetry decoder
|
||||
* \author Oleksandr Suvorov, 2026. github(at)say.od.ua
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* Copyright (C) 2010-2026 (see AUTHORS file for a list of contributors)
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "Beidou_DNAV.h"
|
||||
#include "MATH_CONSTANTS.h"
|
||||
#include "beidou_dnav_telemetry_decoder_gs.h"
|
||||
#include "gnss_satellite.h"
|
||||
#include "gnss_synchro.h"
|
||||
#include "tlm_conf.h"
|
||||
#include <gnuradio/blocks/null_sink.h>
|
||||
#include <gnuradio/top_block.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#ifdef GR_GREATER_38
|
||||
#include <gnuradio/blocks/vector_source.h>
|
||||
#else
|
||||
#include <gnuradio/blocks/vector_source_b.h>
|
||||
#endif
|
||||
|
||||
|
||||
class BeidouDnavTelemetryDecoderTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
decoder = beidou_dnav_make_telemetry_decoder_gs(Tlm_Conf{}, 1);
|
||||
decoder->set_satellite(Gnss_Satellite("Beidou", 10)); // D1 (non-GEO) satellite
|
||||
// Allocate GNU Radio buffers, then drive work directly without scheduler threads.
|
||||
auto source = gr::blocks::vector_source_b::make(std::vector<uint8_t>(sizeof(Gnss_Synchro), 0), false, sizeof(Gnss_Synchro));
|
||||
auto sink = gr::blocks::null_sink::make(sizeof(Gnss_Synchro));
|
||||
top_block = gr::make_top_block("beidou_dnav_telemetry_decoder_test");
|
||||
top_block->connect(source, 0, decoder, 0);
|
||||
top_block->connect(decoder, 0, sink, 0);
|
||||
top_block->run();
|
||||
decoder->reset();
|
||||
symbol.System = 'C';
|
||||
symbol.Signal[0] = 'B';
|
||||
symbol.Signal[1] = '1';
|
||||
symbol.PRN = 10;
|
||||
symbol.Flag_valid_symbol_output = true;
|
||||
symbol.fs = 25000000;
|
||||
symbol.CN0_dB_hz = 40.0;
|
||||
symbol.Carrier_phase_rads = CARRIER_PHASE_RADS;
|
||||
}
|
||||
|
||||
// Symbols (+1 for a bit 1) of a D1 subframe 4 with the given SOW and no
|
||||
// almanac page, encoded as transmitted: BCH(15,11) and, from word 2 on,
|
||||
// the two codewords of each word interleaved bit by bit.
|
||||
static std::vector<float> subframe(uint32_t sow, bool inverted = false)
|
||||
{
|
||||
std::array<uint8_t, BEIDOU_DNAV_SUBFRAME_DATA_BITS> bits{};
|
||||
const char* preamble = BEIDOU_DNAV_PREAMBLE;
|
||||
for (int32_t i = 0; i < BEIDOU_DNAV_PREAMBLE_LENGTH_BITS; i++)
|
||||
{
|
||||
bits[i] = static_cast<uint8_t>(preamble[i] == '1');
|
||||
}
|
||||
set_field(bits, D1_FRAID, 4);
|
||||
set_field(bits, D1_SOW, sow);
|
||||
|
||||
std::vector<float> symbols;
|
||||
symbols.reserve(BEIDOU_DNAV_SUBFRAME_SYMBOLS);
|
||||
// Word 1: 15 bits sent as they are, then one codeword
|
||||
for (int32_t i = 0; i < 15; i++)
|
||||
{
|
||||
symbols.push_back(bits[i] ? 1.0F : -1.0F);
|
||||
}
|
||||
for (const auto bit : bch_encode(&bits[15]))
|
||||
{
|
||||
symbols.push_back(bit ? 1.0F : -1.0F);
|
||||
}
|
||||
// Words 2-10: 22 information bits in two interleaved codewords
|
||||
for (uint32_t word = 1; word < BEIDOU_DNAV_WORDS_SUBFRAME; word++)
|
||||
{
|
||||
const auto first = bch_encode(&bits[word * 30]);
|
||||
const auto second = bch_encode(&bits[word * 30 + 11]);
|
||||
for (int32_t i = 0; i < 15; i++)
|
||||
{
|
||||
symbols.push_back(first[i] ? 1.0F : -1.0F);
|
||||
symbols.push_back(second[i] ? 1.0F : -1.0F);
|
||||
}
|
||||
}
|
||||
if (inverted)
|
||||
{
|
||||
for (auto& value : symbols)
|
||||
{
|
||||
value = -value;
|
||||
}
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
// Feeds the symbols and returns the decoder output for the last one
|
||||
Gnss_Synchro feed(const std::vector<float>& symbols)
|
||||
{
|
||||
Gnss_Synchro output{};
|
||||
gr_vector_const_void_star inputs{&symbol};
|
||||
gr_vector_void_star outputs{&output};
|
||||
gr_vector_int available{1};
|
||||
for (const auto value : symbols)
|
||||
{
|
||||
symbol.Prompt_I = value;
|
||||
symbol.Tracking_sample_counter += 500000;
|
||||
EXPECT_EQ(decoder->general_work(1, available, inputs, outputs), 1);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// Feeds subframes with consecutive SOWs, the given ones inverted, and
|
||||
// returns the output at the end of each
|
||||
std::vector<Gnss_Synchro> feed_subframes(int32_t count, const std::vector<bool>& inverted = {})
|
||||
{
|
||||
std::vector<Gnss_Synchro> outputs;
|
||||
for (int32_t i = 0; i < count; i++)
|
||||
{
|
||||
const bool invert = i < static_cast<int32_t>(inverted.size()) && inverted[i];
|
||||
outputs.push_back(feed(subframe(FIRST_SOW + static_cast<uint32_t>(i) * 6, invert)));
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
// TOW reported with the last symbol of subframe n: the end of that
|
||||
// subframe, which is the SOW of the next one, in GPS time
|
||||
static uint32_t tow_at_end_of_subframe(int32_t n)
|
||||
{
|
||||
return (FIRST_SOW + static_cast<uint32_t>(n + 1) * 6 + BEIDOU_DNAV_BDT2GPST_LEAP_SEC_OFFSET) * 1000;
|
||||
}
|
||||
|
||||
static constexpr double CARRIER_PHASE_RADS = 1.0;
|
||||
static constexpr uint32_t FIRST_SOW = 345600;
|
||||
Gnss_Synchro symbol{};
|
||||
|
||||
private:
|
||||
template <size_t N>
|
||||
static void set_field(std::array<uint8_t, N>& bits, const std::vector<std::pair<int32_t, int32_t>>& field, uint32_t value)
|
||||
{
|
||||
int32_t length = 0;
|
||||
for (const auto& part : field)
|
||||
{
|
||||
length += part.second;
|
||||
}
|
||||
for (const auto& part : field)
|
||||
{
|
||||
for (int32_t i = 0; i < part.second; i++)
|
||||
{
|
||||
length--;
|
||||
bits[part.first - 1 + i] = static_cast<uint8_t>((value >> length) & 1U);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Systematic BCH(15,11) codeword with generator x^4 + x + 1
|
||||
static std::array<uint8_t, 15> bch_encode(const uint8_t* info)
|
||||
{
|
||||
std::array<uint8_t, 15> codeword{};
|
||||
std::array<uint8_t, 4> reg{};
|
||||
for (int32_t i = 0; i < 11; i++)
|
||||
{
|
||||
codeword[i] = info[i];
|
||||
const uint8_t feedback = info[i] ^ reg[3];
|
||||
reg[3] = reg[2];
|
||||
reg[2] = reg[1];
|
||||
reg[1] = reg[0] ^ feedback;
|
||||
reg[0] = feedback;
|
||||
}
|
||||
for (int32_t i = 0; i < 4; i++)
|
||||
{
|
||||
codeword[11 + i] = reg[3 - i];
|
||||
}
|
||||
return codeword;
|
||||
}
|
||||
|
||||
beidou_dnav_telemetry_decoder_gs_sptr decoder;
|
||||
gr::top_block_sptr top_block;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(BeidouDnavTelemetryDecoderTest, NormalPolarityClearsTheTrackingFlag)
|
||||
{
|
||||
symbol.Flag_PLL_180_deg_phase_locked = true;
|
||||
const auto outputs = feed_subframes(6);
|
||||
const auto& output = outputs.back();
|
||||
ASSERT_TRUE(output.Flag_valid_word);
|
||||
EXPECT_EQ(output.TOW_at_current_symbol_ms, tow_at_end_of_subframe(5));
|
||||
EXPECT_FALSE(output.Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(output.Carrier_phase_rads, CARRIER_PHASE_RADS);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(BeidouDnavTelemetryDecoderTest, InvertedPolaritySetsTheFlagAndAddsHalfACycle)
|
||||
{
|
||||
const auto outputs = feed_subframes(6, std::vector<bool>(6, true));
|
||||
const auto& output = outputs.back();
|
||||
ASSERT_TRUE(output.Flag_valid_word);
|
||||
EXPECT_EQ(output.TOW_at_current_symbol_ms, tow_at_end_of_subframe(5));
|
||||
EXPECT_TRUE(output.Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(output.Carrier_phase_rads, CARRIER_PHASE_RADS + GNSS_PI);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(BeidouDnavTelemetryDecoderTest, PolarityChangeIsReportedFromTheNextDecodedSubframe)
|
||||
{
|
||||
// The decoder decodes a subframe once it has received the preamble of the
|
||||
// next one, so the output at the end of subframe n reflects subframe n - 1.
|
||||
const auto outputs = feed_subframes(8, {false, false, false, false, false, true, true, true});
|
||||
ASSERT_TRUE(outputs[5].Flag_valid_word);
|
||||
EXPECT_FALSE(outputs[5].Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(outputs[5].Carrier_phase_rads, CARRIER_PHASE_RADS);
|
||||
ASSERT_TRUE(outputs[7].Flag_valid_word);
|
||||
EXPECT_EQ(outputs[7].TOW_at_current_symbol_ms, tow_at_end_of_subframe(7));
|
||||
EXPECT_TRUE(outputs[7].Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(outputs[7].Carrier_phase_rads, CARRIER_PHASE_RADS + GNSS_PI);
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
/*!
|
||||
* \file glonass_gnav_telemetry_decoder_test.cc
|
||||
* \brief Checks the 180-degree carrier phase lock reported by the GLONASS GNAV
|
||||
* telemetry decoder
|
||||
* \author Oleksandr Suvorov, 2026. github(at)say.od.ua
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* Copyright (C) 2010-2026 (see AUTHORS file for a list of contributors)
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "GLONASS_L1_L2_CA.h"
|
||||
#include "MATH_CONSTANTS.h"
|
||||
#include "glonass_gnav_telemetry_decoder_gs.h"
|
||||
#include "gnss_satellite.h"
|
||||
#include "gnss_synchro.h"
|
||||
#include "tlm_conf.h"
|
||||
#include <gnuradio/blocks/null_sink.h>
|
||||
#include <gnuradio/top_block.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#ifdef GR_GREATER_38
|
||||
#include <gnuradio/blocks/vector_source.h>
|
||||
#else
|
||||
#include <gnuradio/blocks/vector_source_b.h>
|
||||
#endif
|
||||
|
||||
|
||||
class GlonassGnavTelemetryDecoderTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
decoder = glonass_gnav_make_telemetry_decoder_gs(Tlm_Conf{}, 1);
|
||||
decoder->set_satellite(Gnss_Satellite("Glonass", 1));
|
||||
// Allocate GNU Radio buffers, then drive work directly without scheduler threads.
|
||||
auto source = gr::blocks::vector_source_b::make(std::vector<uint8_t>(sizeof(Gnss_Synchro), 0), false, sizeof(Gnss_Synchro));
|
||||
auto sink = gr::blocks::null_sink::make(sizeof(Gnss_Synchro));
|
||||
top_block = gr::make_top_block("glonass_gnav_telemetry_decoder_test");
|
||||
top_block->connect(source, 0, decoder, 0);
|
||||
top_block->connect(decoder, 0, sink, 0);
|
||||
top_block->run();
|
||||
decoder->reset();
|
||||
symbol.System = 'R';
|
||||
symbol.Signal[0] = '1';
|
||||
symbol.Signal[1] = 'G';
|
||||
symbol.PRN = 1;
|
||||
symbol.Flag_valid_symbol_output = true;
|
||||
symbol.fs = 6625000;
|
||||
symbol.CN0_dB_hz = 40.0;
|
||||
symbol.Carrier_phase_rads = CARRIER_PHASE_RADS;
|
||||
}
|
||||
|
||||
// Symbols of a time mark followed by a string with the given number, as
|
||||
// transmitted: Hamming code, relative code and meander. The decoder takes
|
||||
// the time decoded from strings 1, 4 and 5. A string with a damaged
|
||||
// Hamming code has two data bits flipped, which the code cannot correct.
|
||||
static std::vector<float> string_after_time_mark(uint32_t string_id, bool inverted = false, bool damaged = false)
|
||||
{
|
||||
std::array<uint8_t, GLONASS_GNAV_STRING_BITS> bits{}; // bits[0] is the first (idle) bit
|
||||
set_field(bits, STRING_ID, string_id);
|
||||
switch (string_id)
|
||||
{
|
||||
case 1:
|
||||
set_field(bits, T_K_HR, 12);
|
||||
break;
|
||||
case 4:
|
||||
set_field(bits, N_T, 100);
|
||||
set_field(bits, N, 1);
|
||||
break;
|
||||
case 5:
|
||||
set_field(bits, N_4, 8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
add_hamming_code(bits);
|
||||
if (damaged)
|
||||
{
|
||||
bits[10] ^= 1U;
|
||||
bits[11] ^= 1U;
|
||||
}
|
||||
|
||||
std::vector<float> symbols(GLONASS_GNAV_PREAMBLE_SAMPLES);
|
||||
uint8_t relative = 0;
|
||||
for (int32_t i = 0; i < GLONASS_GNAV_STRING_BITS; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
relative ^= bits[i];
|
||||
}
|
||||
symbols.push_back(relative ? 1.0F : -1.0F);
|
||||
symbols.push_back(relative ? -1.0F : 1.0F);
|
||||
}
|
||||
if (inverted)
|
||||
{
|
||||
for (auto& value : symbols)
|
||||
{
|
||||
value = -value;
|
||||
}
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
// Feeds the symbols and returns the decoder output for the last one
|
||||
Gnss_Synchro feed(const std::vector<float>& symbols)
|
||||
{
|
||||
Gnss_Synchro output{};
|
||||
gr_vector_const_void_star inputs{&symbol};
|
||||
gr_vector_void_star outputs{&output};
|
||||
gr_vector_int available{1};
|
||||
for (const auto value : symbols)
|
||||
{
|
||||
symbol.Prompt_I = value;
|
||||
symbol.Tracking_sample_counter += 66250;
|
||||
EXPECT_EQ(decoder->general_work(1, available, inputs, outputs), 1);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// Feeds strings and returns the output at the end of each. The decoder
|
||||
// first decodes the fifth string, so strings 1 to 5 go from there on;
|
||||
// string 5 is not repeated afterwards, as a new one would carry a new time.
|
||||
std::vector<Gnss_Synchro> feed_strings(int32_t count, const std::vector<bool>& inverted = {}, int32_t damaged = -1)
|
||||
{
|
||||
std::vector<Gnss_Synchro> outputs;
|
||||
for (int32_t i = 0; i < count; i++)
|
||||
{
|
||||
uint32_t string_id = 1;
|
||||
if (i >= FIRST_DECODED_STRING && i < FIRST_DECODED_STRING + 5)
|
||||
{
|
||||
string_id = static_cast<uint32_t>(i - FIRST_DECODED_STRING + 1);
|
||||
}
|
||||
else if (i >= FIRST_DECODED_STRING + 5)
|
||||
{
|
||||
string_id = static_cast<uint32_t>((i - FIRST_DECODED_STRING - 5) % 4 + 1);
|
||||
}
|
||||
const bool invert = i < static_cast<int32_t>(inverted.size()) && inverted[i];
|
||||
outputs.push_back(feed(string_after_time_mark(string_id, invert, i == damaged)));
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
static constexpr double CARRIER_PHASE_RADS = 1.0;
|
||||
static constexpr int32_t FIRST_DECODED_STRING = 4;
|
||||
static constexpr int32_t TIME_SET_STRING = FIRST_DECODED_STRING + 4;
|
||||
Gnss_Synchro symbol{};
|
||||
|
||||
private:
|
||||
static void set_field(std::array<uint8_t, GLONASS_GNAV_STRING_BITS>& bits, const std::vector<std::pair<int32_t, int32_t>>& field, uint32_t value)
|
||||
{
|
||||
const int32_t start = field[0].first - 1;
|
||||
const int32_t length = field[0].second;
|
||||
for (int32_t i = 0; i < length; i++)
|
||||
{
|
||||
bits[start + i] = static_cast<uint8_t>((value >> (length - i - 1)) & 1U);
|
||||
}
|
||||
}
|
||||
|
||||
// Check bits 1 to 8 (the last eight bits of the string) of the Hamming
|
||||
// code. ICD bit k is bits[GLONASS_GNAV_STRING_BITS - k].
|
||||
static void add_hamming_code(std::array<uint8_t, GLONASS_GNAV_STRING_BITS>& bits)
|
||||
{
|
||||
const auto icd_bit = [&bits](int32_t k) -> uint8_t& { return bits[GLONASS_GNAV_STRING_BITS - k]; };
|
||||
const auto parity = [&icd_bit](const std::vector<int32_t>& indexes) {
|
||||
uint8_t sum = 0;
|
||||
for (const auto k : indexes)
|
||||
{
|
||||
sum ^= icd_bit(k);
|
||||
}
|
||||
return sum;
|
||||
};
|
||||
const std::array<const std::vector<int32_t>*, 7> checks{&GLONASS_GNAV_CRC_I_INDEX, &GLONASS_GNAV_CRC_J_INDEX,
|
||||
&GLONASS_GNAV_CRC_K_INDEX, &GLONASS_GNAV_CRC_L_INDEX, &GLONASS_GNAV_CRC_M_INDEX, &GLONASS_GNAV_CRC_N_INDEX,
|
||||
&GLONASS_GNAV_CRC_P_INDEX};
|
||||
uint8_t check_sum = 0;
|
||||
for (int32_t k = 1; k <= 7; k++)
|
||||
{
|
||||
icd_bit(k) = parity(*checks[k - 1]);
|
||||
check_sum ^= icd_bit(k);
|
||||
}
|
||||
icd_bit(8) = check_sum ^ parity(GLONASS_GNAV_CRC_Q_INDEX);
|
||||
}
|
||||
|
||||
glonass_gnav_telemetry_decoder_gs_sptr decoder;
|
||||
gr::top_block_sptr top_block;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(GlonassGnavTelemetryDecoderTest, NormalPolarityClearsTheTrackingFlag)
|
||||
{
|
||||
symbol.Flag_PLL_180_deg_phase_locked = true;
|
||||
const auto outputs = feed_strings(TIME_SET_STRING + 2);
|
||||
EXPECT_FALSE(outputs[TIME_SET_STRING - 1].Flag_valid_word);
|
||||
const auto& output = outputs.back();
|
||||
ASSERT_TRUE(output.Flag_valid_word);
|
||||
EXPECT_FALSE(output.Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(output.Carrier_phase_rads, CARRIER_PHASE_RADS);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(GlonassGnavTelemetryDecoderTest, InvertedPolaritySetsTheFlagAndAddsHalfACycle)
|
||||
{
|
||||
const auto outputs = feed_strings(TIME_SET_STRING + 2, std::vector<bool>(TIME_SET_STRING + 2, true));
|
||||
const auto& output = outputs.back();
|
||||
ASSERT_TRUE(output.Flag_valid_word);
|
||||
EXPECT_TRUE(output.Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(output.Carrier_phase_rads, CARRIER_PHASE_RADS + GNSS_PI);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(GlonassGnavTelemetryDecoderTest, PolarityChangeIsReportedFromTheNextValidString)
|
||||
{
|
||||
// The string after a time mark is decoded once its last symbol arrives
|
||||
std::vector<bool> inverted(TIME_SET_STRING + 3, false);
|
||||
inverted[TIME_SET_STRING + 2] = true;
|
||||
const auto outputs = feed_strings(TIME_SET_STRING + 3, inverted);
|
||||
ASSERT_TRUE(outputs[TIME_SET_STRING + 1].Flag_valid_word);
|
||||
EXPECT_FALSE(outputs[TIME_SET_STRING + 1].Flag_PLL_180_deg_phase_locked);
|
||||
ASSERT_TRUE(outputs[TIME_SET_STRING + 2].Flag_valid_word);
|
||||
EXPECT_TRUE(outputs[TIME_SET_STRING + 2].Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(outputs[TIME_SET_STRING + 2].Carrier_phase_rads, CARRIER_PHASE_RADS + GNSS_PI);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(GlonassGnavTelemetryDecoderTest, StringFailingTheHammingCheckKeepsThePreviousDecision)
|
||||
{
|
||||
std::vector<bool> inverted(TIME_SET_STRING + 4, false);
|
||||
inverted[TIME_SET_STRING + 2] = true;
|
||||
inverted[TIME_SET_STRING + 3] = true;
|
||||
const auto outputs = feed_strings(TIME_SET_STRING + 4, inverted, TIME_SET_STRING + 2);
|
||||
ASSERT_TRUE(outputs[TIME_SET_STRING + 2].Flag_valid_word);
|
||||
EXPECT_FALSE(outputs[TIME_SET_STRING + 2].Flag_PLL_180_deg_phase_locked);
|
||||
EXPECT_DOUBLE_EQ(outputs[TIME_SET_STRING + 2].Carrier_phase_rads, CARRIER_PHASE_RADS);
|
||||
ASSERT_TRUE(outputs[TIME_SET_STRING + 3].Flag_valid_word);
|
||||
EXPECT_TRUE(outputs[TIME_SET_STRING + 3].Flag_PLL_180_deg_phase_locked);
|
||||
}
|
||||
@@ -49,8 +49,10 @@
|
||||
#include "unit-tests/signal-processing-blocks/resampler/mmse_resampler_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/sources/gnss_sdr_valve_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/sources/unpack_2bit_samples_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/beidou_dnav_telemetry_decoder_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/deterministic_telemetry_fault_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/galileo_fnav_inav_decoder_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/glonass_gnav_telemetry_decoder_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/gps_cnav_msg_decoder_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/gps_l1c_telemetry_decoder_test.cc"
|
||||
#include "unit-tests/signal-processing-blocks/telemetry_decoder/sbas_l1_telemetry_decoder_test.cc"
|
||||
|
||||
Reference in new issue
Block a user