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

Improve const correctness

This commit is contained in:
Carles Fernandez 2021-12-07 08:21:14 +01:00
parent c41ea05137
commit 4b1c6a2b35
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
7 changed files with 41 additions and 49 deletions

View File

@ -622,6 +622,7 @@ void hybrid_observables_gs::smooth_pseudoranges(std::vector<Gnss_Synchro> &data)
}
}
void hybrid_observables_gs::set_tag_timestamp_in_sdr_timeframe(const std::vector<Gnss_Synchro> &data, uint64_t rx_clock)
{
// it transforms the HW sample tag timestamp from a relative samplestamp (from receiver start)
@ -652,14 +653,13 @@ void hybrid_observables_gs::set_tag_timestamp_in_sdr_timeframe(const std::vector
}
while (delta_rxtime_to_tag >= 0.1 and !d_TimeChannelTagTimestamps.empty());
if (delta_rxtime_to_tag >= 0 and delta_rxtime_to_tag <= 0.1)
{
// std::cout << "[Time ch][" << delta_rxtime_to_tag
// << "] OBS RX TimeTag Week: " << current_tag.week
// << ", TOW: " << current_tag.tow_ms
// << " [ms], TOW fraction: " << current_tag.tow_ms_fraction
// << " [ms], DELTA TLM TOW: " << last_rx_clock_round20ms_error + delta_rxtime_to_tag * 1000.0 + static_cast<double>(current_tag.tow_ms) - static_cast<double>(d_T_rx_TOW_ms) + current_tag.tow_ms_fraction << " [ms] \n";
// std::cout << "[Time ch][" << delta_rxtime_to_tag
// << "] OBS RX TimeTag Week: " << current_tag.week
// << ", TOW: " << current_tag.tow_ms
// << " [ms], TOW fraction: " << current_tag.tow_ms_fraction
// << " [ms], DELTA TLM TOW: " << last_rx_clock_round20ms_error + delta_rxtime_to_tag * 1000.0 + static_cast<double>(current_tag.tow_ms) - static_cast<double>(d_T_rx_TOW_ms) + current_tag.tow_ms_fraction << " [ms] \n";
const std::shared_ptr<GnssTime> tmp_obj = std::make_shared<GnssTime>(GnssTime());
*tmp_obj = current_tag;
double intpart;
@ -671,6 +671,7 @@ void hybrid_observables_gs::set_tag_timestamp_in_sdr_timeframe(const std::vector
}
}
int hybrid_observables_gs::general_work(int noutput_items __attribute__((unused)),
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
@ -684,16 +685,16 @@ int hybrid_observables_gs::general_work(int noutput_items __attribute__((unused)
{
d_Rx_clock_buffer.push_back(in[d_nchannels_in - 1][0].Tracking_sample_counter);
//**************** time tags ****************
// time tags
std::vector<gr::tag_t> tags_vec;
this->get_tags_in_range(tags_vec, d_nchannels_in - 1, this->nitems_read(d_nchannels_in - 1), this->nitems_read(d_nchannels_in - 1) + 1);
for (std::vector<gr::tag_t>::iterator it = tags_vec.begin(); it != tags_vec.end(); ++it)
for (const auto &it : tags_vec)
{
try
{
if (pmt::any_ref(it->value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
if (pmt::any_ref(it.value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
{
const std::shared_ptr<GnssTime> timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it->value));
const auto timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it.value));
// std::cout << "[Time ch ] timetag: " << timetag->rx_time << "\n";
d_TimeChannelTagTimestamps.push(*timetag);
}
@ -708,9 +709,6 @@ int hybrid_observables_gs::general_work(int noutput_items __attribute__((unused)
}
}
//************* end time tags **************
// Consume one item from the clock channel (last of the input channels)
consume(static_cast<int32_t>(d_nchannels_in) - 1, 1);
}

View File

@ -686,18 +686,18 @@ int galileo_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
}
d_sample_counter++; // count for the processed symbols
// ******* Time Tags from signal source (optional feature) *******
// Time Tags from signal source (optional feature)
std::vector<gr::tag_t> tags_vec;
this->get_tags_in_range(tags_vec, 0, this->nitems_read(0), this->nitems_read(0) + 1); // telemetry decoder consumes symbols one-by-one
if (!tags_vec.empty())
{
for (std::vector<gr::tag_t>::iterator it = tags_vec.begin(); it != tags_vec.end(); ++it)
for (const auto &it : tags_vec)
{
try
{
if (pmt::any_ref(it->value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
if (pmt::any_ref(it.value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
{
const std::shared_ptr<GnssTime> timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it->value));
const auto timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it.value));
// std::cout << "Old tow: " << d_current_timetag.tow_ms << " new tow: " << timetag->tow_ms << "\n";
d_current_timetag = *timetag;
d_valid_timetag = true;
@ -728,7 +728,6 @@ int galileo_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
}
}
}
// ***********************************************
consume_each(1);
d_flag_preamble = false;

View File

@ -102,6 +102,8 @@ private:
Galileo_Fnav_Message d_fnav_nav;
Nav_Message_Packet d_nav_msg_packet;
GnssTime d_current_timetag;
std::unique_ptr<Tlm_CRC_Stats> d_Tlm_CRC_Stats;
double d_delta_t; // GPS-GALILEO time offset
@ -145,7 +147,6 @@ private:
bool d_dump_crc_stats;
bool d_enable_reed_solomon_inav;
bool d_valid_timetag;
GnssTime d_current_timetag;
};

View File

@ -115,13 +115,12 @@ gps_l1_ca_telemetry_decoder_gs::gps_l1_ca_telemetry_decoder_gs(
if (GPS_CA_PREAMBLE[i] == '1')
{
d_preamble_samples[n] = 1;
n++;
}
else
{
d_preamble_samples[n] = -1;
n++;
}
n++;
}
d_symbol_history.set_capacity(d_required_symbols);
@ -597,19 +596,18 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__
current_symbol.Flag_PLL_180_deg_phase_locked = false;
}
//**************** time tags ****************
// time tags
std::vector<gr::tag_t> tags_vec;
this->get_tags_in_range(tags_vec, 0, this->nitems_read(0), this->nitems_read(0) + 1);
for (std::vector<gr::tag_t>::iterator it = tags_vec.begin(); it != tags_vec.end(); ++it)
for (const auto &it : tags_vec)
{
try
{
if (pmt::any_ref(it->value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
if (pmt::any_ref(it.value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
{
const std::shared_ptr<GnssTime> timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it->value));
// std::cout << "[" << this->nitems_written(0) + 1 << "] TLM RX TimeTag Week: " << timetag->week << ", TOW: " << timetag->tow_ms << " [ms], TOW fraction: " << timetag->tow_ms_fraction
// << " [ms], DELTA TLM TOW: " << static_cast<double>(timetag->tow_ms - current_symbol.TOW_at_current_symbol_ms) + timetag->tow_ms_fraction << " [ms] \n";
const auto timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it.value));
// std::cout << "[" << this->nitems_written(0) + 1 << "] TLM RX TimeTag Week: " << timetag->week << ", TOW: " << timetag->tow_ms << " [ms], TOW fraction: " << timetag->tow_ms_fraction
// << " [ms], DELTA TLM TOW: " << static_cast<double>(timetag->tow_ms - current_symbol.TOW_at_current_symbol_ms) + timetag->tow_ms_fraction << " [ms] \n";
add_item_tag(0, this->nitems_written(0) + 1, pmt::mp("timetag"), pmt::make_any(timetag));
}
else
@ -623,8 +621,6 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__
}
}
//************* end time tags **************
if (d_dump == true)
{
// MULTIPLEXED FILE RECORDING - Record results to file

View File

@ -1702,11 +1702,12 @@ void dll_pll_veml_tracking::stop_tracking()
d_state = 0;
}
int64_t dll_pll_veml_tracking::uint64diff(uint64_t first, uint64_t second)
{
uint64_t abs_diff = (first > second) ? (first - second) : (second - first);
assert(abs_diff <= INT64_MAX);
return (first > second) ? (int64_t)abs_diff : -(int64_t)abs_diff;
return (first > second) ? static_cast<int64_t>(abs_diff) : -static_cast<int64_t>(abs_diff);
}
@ -2012,21 +2013,20 @@ int dll_pll_veml_tracking::general_work(int noutput_items __attribute__((unused)
}
}
//**************** time tags ****************
// time tags
std::vector<gr::tag_t> tags_vec;
this->get_tags_in_range(tags_vec, 0, this->nitems_read(0), this->nitems_read(0) + d_current_prn_length_samples);
for (std::vector<gr::tag_t>::iterator it = tags_vec.begin(); it != tags_vec.end(); ++it)
for (const auto &it : tags_vec)
{
try
{
if (pmt::any_ref(it->value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
if (pmt::any_ref(it.value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
{
// std::cout << "ch[" << d_acquisition_gnss_synchro->Channel_ID << "] tracking time tag with offset " << it->offset << " vs. counter " << d_sample_counter << " vs. nread " << this->nitems_read(0) << " containing ";
// std::cout << "ch[" << d_acquisition_gnss_synchro->Channel_ID << "] tracking time tag with offset " << it->offset << " vs. nread " << this->nitems_read(0) << " containing ";
const std::shared_ptr<GnssTime> last_timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it->value));
const auto last_timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it.value));
d_last_timetag = *last_timetag;
d_last_timetag_samplecounter = it->offset;
d_last_timetag_samplecounter = it.offset;
d_timetag_waiting = true;
}
else
@ -2044,9 +2044,6 @@ int dll_pll_veml_tracking::general_work(int noutput_items __attribute__((unused)
}
}
//************* end time tags **************
consume_each(d_current_prn_length_samples);
// d_sample_counter += static_cast<uint64_t>(d_current_prn_length_samples);
if (current_synchro_data.Flag_valid_symbol_output || loss_of_lock)

View File

@ -616,7 +616,7 @@ void kf_vtl_tracking::msg_handler_pvt_to_trk(const pmt::pmt_t &msg)
{
if (pmt::any_ref(msg).type().hash_code() == typeid(const std::shared_ptr<TrackingCmd>).hash_code())
{
const std::shared_ptr<TrackingCmd> cmd = boost::any_cast<const std::shared_ptr<TrackingCmd>>(pmt::any_ref(msg));
const auto cmd = boost::any_cast<const std::shared_ptr<TrackingCmd>>(pmt::any_ref(msg));
// std::cout << "RX pvt-to-trk cmd with delay: "
// << static_cast<double>(nitems_read(0) - cmd->sample_counter) / d_trk_parameters.fs_in << " [s]\n";
}
@ -829,7 +829,6 @@ void kf_vtl_tracking::start_tracking()
// Initialize tracking ==========================================
// DEBUG OUTPUT
std::cout << "Tracking of " << d_systemName << " " << d_signal_pretty_name << " signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(d_systemName, d_acquisition_gnss_synchro->PRN) << '\n';
DLOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(d_systemName, d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel;
@ -895,9 +894,7 @@ void kf_vtl_tracking::init_kf(double acq_code_phase_chips, double acq_doppler_hz
<< 0 << 0 << 0 << pow(d_trk_parameters.init_carrier_freq_rate_sd_hz_s, 2.0) << 0 << arma::endr
<< 0 << 0 << 0 << 0 << pow(d_trk_parameters.init_code_rate_sd_chips_s, 2.0) << arma::endr;
// init state vector
x_old_old = arma::vec(5);
// states: code_phase_chips, carrier_phase_rads, carrier_freq_hz, carrier_freq_rate_hz_s, code_freq_rate_chips_s
x_old_old << acq_code_phase_chips << 0 << acq_doppler_hz << 0 << 0 << arma::endr;
@ -910,6 +907,7 @@ void kf_vtl_tracking::init_kf(double acq_code_phase_chips, double acq_doppler_hz
// std::cout << "x: " << x_old_old << "\n";
}
void kf_vtl_tracking::update_kf_narrow_intgration_time()
{
// Kalman Filter class variables
@ -946,6 +944,7 @@ void kf_vtl_tracking::update_kf_narrow_intgration_time()
<< 0 << 0 << 0 << 0 << pow(d_trk_parameters.narrow_code_rate_sd_chips_s, 2.0) << arma::endr;
}
void kf_vtl_tracking::update_kf_cn0(double current_cn0_dbhz)
{
// Kalman Filter class variables
@ -968,6 +967,7 @@ void kf_vtl_tracking::update_kf_cn0(double current_cn0_dbhz)
<< 0 << Sigma2_Phase << arma::endr;
}
kf_vtl_tracking::~kf_vtl_tracking()
{
if (d_dump_file.is_open())
@ -1834,7 +1834,6 @@ int kf_vtl_tracking::general_work(int noutput_items __attribute__((unused)), gr_
DLOG(INFO) << "PULL-IN Doppler [Hz] = " << d_carrier_doppler_kf_hz
<< ". PULL-IN Code Phase [samples] = " << d_acq_code_phase_samples;
consume_each(samples_offset); // shift input to perform alignment with local replica
return 0;
}

View File

@ -62,6 +62,7 @@ gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter(double _fs, int32_t _i
return sample_counter_;
}
int64_t gnss_sdr_sample_counter::uint64diff(uint64_t first, uint64_t second)
{
uint64_t abs_diff = (first > second) ? (first - second) : (second - first);
@ -69,6 +70,7 @@ int64_t gnss_sdr_sample_counter::uint64diff(uint64_t first, uint64_t second)
return (first > second) ? (int64_t)abs_diff : -(int64_t)abs_diff;
}
int gnss_sdr_sample_counter::work(int noutput_items __attribute__((unused)),
gr_vector_const_void_star &input_items __attribute__((unused)),
gr_vector_void_star &output_items)
@ -145,15 +147,15 @@ int gnss_sdr_sample_counter::work(int noutput_items __attribute__((unused)),
std::vector<gr::tag_t> tags_vec;
// notice that nitems_read is updated in decimation blocks after leaving work() with return 1, equivalent to call consume_each
this->get_tags_in_range(tags_vec, 0, this->nitems_read(0), this->nitems_read(0) + samples_per_output);
for (std::vector<gr::tag_t>::iterator it = tags_vec.begin(); it != tags_vec.end(); ++it)
for (const auto &it : tags_vec)
{
try
{
if (pmt::any_ref(it->value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
if (pmt::any_ref(it.value).type().hash_code() == typeid(const std::shared_ptr<GnssTime>).hash_code())
{
// recompute timestamp to match the last sample in the consumed samples in this batch
int64_t diff_samplecount = uint64diff(out[0].Tracking_sample_counter, it->offset);
const std::shared_ptr<GnssTime> last_timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it->value));
int64_t diff_samplecount = uint64diff(out[0].Tracking_sample_counter, it.offset);
const auto last_timetag = boost::any_cast<const std::shared_ptr<GnssTime>>(pmt::any_ref(it.value));
double intpart;
last_timetag->tow_ms_fraction += modf(1000.0 * static_cast<double>(diff_samplecount) / fs, &intpart);