1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-07-04 11:02:57 +00:00

Add try-catch block to hybrid observables

This commit is contained in:
Antonio Ramos 2018-02-14 11:56:22 +01:00
parent 8885333aa7
commit 28cc4a1a05
4 changed files with 66 additions and 59 deletions

View File

@ -35,7 +35,8 @@
gnss_sdr_sample_counter::gnss_sdr_sample_counter(double _fs) : gr::sync_decimator("sample_counter", gnss_sdr_sample_counter::gnss_sdr_sample_counter(double _fs) : gr::sync_decimator("sample_counter",
gr::io_signature::make(1, 1, sizeof(gr_complex)), gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)), floor(_fs*0.001)) gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)),
static_cast<unsigned int>(floor(_fs * 0.001)))
{ {
this->message_port_register_out(pmt::mp("sample_counter")); this->message_port_register_out(pmt::mp("sample_counter"));
current_T_rx_ms = 0; current_T_rx_ms = 0;
@ -60,7 +61,7 @@ int gnss_sdr_sample_counter::work (int noutput_items __attribute__((unused)),
if ((current_T_rx_ms % report_interval_ms) == 0) if ((current_T_rx_ms % report_interval_ms) == 0)
{ {
std::cout << "Current receiver time: " << static_cast<double>(current_T_rx_ms) / 1000.0 << " [s]" << std::endl; std::cout << "Current receiver time: " << static_cast<double>(current_T_rx_ms) / 1000.0 << " [s]" << std::endl;
if(flag_enable_send_msg == true) if(flag_enable_send_msg)
{ {
this->message_port_pub(pmt::mp("receiver_time"), pmt::from_double(static_cast<double>(current_T_rx_ms) / 1000.0)); this->message_port_pub(pmt::mp("receiver_time"), pmt::from_double(static_cast<double>(current_T_rx_ms) / 1000.0));
} }

View File

@ -28,8 +28,8 @@
* *
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#ifndef GNSS_SDR_sample_counter_H_ #ifndef GNSS_SDR_SAMPLE_COUNTER_H_
#define GNSS_SDR_sample_counter_H_ #define GNSS_SDR_SAMPLE_COUNTER_H_
#include <gnuradio/sync_decimator.h> #include <gnuradio/sync_decimator.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -43,16 +43,19 @@ gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter (double _fs);
class gnss_sdr_sample_counter : public gr::sync_decimator class gnss_sdr_sample_counter : public gr::sync_decimator
{ {
friend gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter(double _fs); private:
gnss_sdr_sample_counter(double _fs); gnss_sdr_sample_counter(double _fs);
long long int current_T_rx_ms; long long int current_T_rx_ms;
int report_interval_ms; int report_interval_ms;
bool flag_enable_send_msg; bool flag_enable_send_msg;
public: public:
friend gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter(double _fs);
int work(int noutput_items, int work(int noutput_items,
gr_vector_const_void_star &input_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items); gr_vector_void_star &output_items);
}; };
#endif /*GNSS_SDR_sample_counter_H_*/ #endif /*GNSS_SDR_SAMPLE_COUNTER_H_*/

View File

@ -39,12 +39,8 @@
using google::LogMessage; using google::LogMessage;
HybridObservables::HybridObservables(ConfigurationInterface* configuration, HybridObservables::HybridObservables(ConfigurationInterface* configuration,
std::string role, std::string role, unsigned int in_streams, unsigned int out_streams) :
unsigned int in_streams, role_(role), in_streams_(in_streams), out_streams_(out_streams)
unsigned int out_streams) :
role_(role),
in_streams_(in_streams),
out_streams_(out_streams)
{ {
std::string default_dump_filename = "./observables.dat"; std::string default_dump_filename = "./observables.dat";
DLOG(INFO) << "role " << role; DLOG(INFO) << "role " << role;
@ -61,18 +57,14 @@ HybridObservables::HybridObservables(ConfigurationInterface* configuration,
} }
unsigned int history_deep = configuration->property(role + ".history_depth", default_depth); unsigned int history_deep = configuration->property(role + ".history_depth", default_depth);
observables_ = hybrid_make_observables_cc(in_streams_, out_streams_, dump_, dump_filename_, history_deep); observables_ = hybrid_make_observables_cc(in_streams_, out_streams_, dump_, dump_filename_, history_deep);
DLOG(INFO) << "pseudorange(" << observables_->unique_id() << ")"; DLOG(INFO) << "Observables block ID (" << observables_->unique_id() << ")";
} }
HybridObservables::~HybridObservables() HybridObservables::~HybridObservables()
{} {}
void HybridObservables::connect(gr::top_block_sptr top_block) void HybridObservables::connect(gr::top_block_sptr top_block)
{ {
if(top_block) { /* top_block is not null */}; if(top_block) { /* top_block is not null */};
@ -81,7 +73,6 @@ void HybridObservables::connect(gr::top_block_sptr top_block)
} }
void HybridObservables::disconnect(gr::top_block_sptr top_block) void HybridObservables::disconnect(gr::top_block_sptr top_block)
{ {
if(top_block) { /* top_block is not null */}; if(top_block) { /* top_block is not null */};
@ -89,16 +80,12 @@ void HybridObservables::disconnect(gr::top_block_sptr top_block)
} }
gr::basic_block_sptr HybridObservables::get_left_block() gr::basic_block_sptr HybridObservables::get_left_block()
{ {
return observables_; return observables_;
} }
gr::basic_block_sptr HybridObservables::get_right_block() gr::basic_block_sptr HybridObservables::get_right_block()
{ {
return observables_; return observables_;

View File

@ -338,10 +338,8 @@ void hybrid_observables_cc::forecast (int noutput_items __attribute__((unused)),
} }
int hybrid_observables_cc::general_work (int noutput_items , int hybrid_observables_cc::general_work(int noutput_items, gr_vector_int &ninput_items,
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{ {
const Gnss_Synchro** in = reinterpret_cast<const Gnss_Synchro**>(&input_items[0]); // Get the input buffer pointer const Gnss_Synchro** in = reinterpret_cast<const Gnss_Synchro**>(&input_items[0]); // Get the input buffer pointer
Gnss_Synchro** out = reinterpret_cast<Gnss_Synchro**>(&output_items[0]); // Get the output buffer pointer Gnss_Synchro** out = reinterpret_cast<Gnss_Synchro**>(&output_items[0]); // Get the output buffer pointer
@ -370,12 +368,17 @@ int hybrid_observables_cc::general_work (int noutput_items ,
} }
bool channel_history_ok; bool channel_history_ok;
do do
{ {
try
{
channel_history_ok = true; channel_history_ok = true;
for(unsigned int i = 0; i < d_nchannels; i++) for(unsigned int i = 0; i < d_nchannels; i++)
{ {
if (d_gnss_synchro_history_queue[i].size() < history_deep && !d_gnss_synchro_history_queue[i].empty()) if (d_gnss_synchro_history_queue.at(i).size() < history_deep && !d_gnss_synchro_history_queue.at(i).empty())
{ {
channel_history_ok = false; channel_history_ok = false;
} }
@ -392,15 +395,15 @@ int hybrid_observables_cc::general_work (int noutput_items ,
std::map<int,Gnss_Synchro> gnss_synchro_map; std::map<int,Gnss_Synchro> gnss_synchro_map;
for (unsigned int i = 0; i < d_nchannels; i++) for (unsigned int i = 0; i < d_nchannels; i++)
{ {
if (!d_gnss_synchro_history_queue[i].empty()) if (!d_gnss_synchro_history_queue.at(i).empty())
{ {
gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].front().Channel_ID, gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue.at(i).front().Channel_ID,
d_gnss_synchro_history_queue[i].front())); d_gnss_synchro_history_queue.at(i).front()));
} }
} }
if (gnss_synchro_map.empty()) break; if(gnss_synchro_map.empty()) { break; } // Breaks the do-while loop
gnss_synchro_map_iter = min_element(gnss_synchro_map.cbegin(), gnss_synchro_map_iter = std::min_element(gnss_synchro_map.cbegin(),
gnss_synchro_map.cend(), gnss_synchro_map.cend(),
Hybrid_pairCompare_gnss_synchro_sample_counter); Hybrid_pairCompare_gnss_synchro_sample_counter);
T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / static_cast<double>(gnss_synchro_map_iter->second.fs); T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / static_cast<double>(gnss_synchro_map_iter->second.fs);
@ -414,13 +417,13 @@ int hybrid_observables_cc::general_work (int noutput_items ,
// shift channels history to match the reference TOW // shift channels history to match the reference TOW
for (unsigned int i = 0; i < d_nchannels; i++) for (unsigned int i = 0; i < d_nchannels; i++)
{ {
if (!d_gnss_synchro_history_queue[i].empty()) if (!d_gnss_synchro_history_queue.at(i).empty())
{ {
gnss_synchro_deque_iter = std::lower_bound(d_gnss_synchro_history_queue[i].cbegin(), gnss_synchro_deque_iter = std::lower_bound(d_gnss_synchro_history_queue.at(i).cbegin(),
d_gnss_synchro_history_queue[i].cend(), d_gnss_synchro_history_queue.at(i).cend(),
T_rx_s, T_rx_s,
Hybrid_valueCompare_gnss_synchro_receiver_time); Hybrid_valueCompare_gnss_synchro_receiver_time);
if (gnss_synchro_deque_iter != d_gnss_synchro_history_queue[i].cend()) if (gnss_synchro_deque_iter != d_gnss_synchro_history_queue.at(i).cend())
{ {
if (gnss_synchro_deque_iter->Flag_valid_word == true) if (gnss_synchro_deque_iter->Flag_valid_word == true)
{ {
@ -432,24 +435,24 @@ int hybrid_observables_cc::general_work (int noutput_items ,
{ {
// record the word structure in a map for pseudorange computation // record the word structure in a map for pseudorange computation
// save the previous observable // save the previous observable
int distance = std::distance(d_gnss_synchro_history_queue[i].cbegin(), gnss_synchro_deque_iter); int distance = std::distance(d_gnss_synchro_history_queue.at(i).cbegin(), gnss_synchro_deque_iter);
if (distance > 0) if (distance > 0)
{ {
if (d_gnss_synchro_history_queue[i].at(distance - 1).Flag_valid_word) if (d_gnss_synchro_history_queue.at(i).at(distance - 1).Flag_valid_word)
{ {
double T_rx_channel_prev = static_cast<double>(d_gnss_synchro_history_queue[i].at(distance - 1).Tracking_sample_counter) / static_cast<double>(gnss_synchro_deque_iter->fs); double T_rx_channel_prev = static_cast<double>(d_gnss_synchro_history_queue.at(i).at(distance - 1).Tracking_sample_counter) / static_cast<double>(gnss_synchro_deque_iter->fs);
double delta_T_rx_s_prev = T_rx_channel_prev - T_rx_s; double delta_T_rx_s_prev = T_rx_channel_prev - T_rx_s;
if (fabs(delta_T_rx_s_prev) < fabs(delta_T_rx_s)) if (fabs(delta_T_rx_s_prev) < fabs(delta_T_rx_s))
{ {
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].at(distance - 1).Channel_ID, realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue.at(i).at(distance - 1).Channel_ID,
d_gnss_synchro_history_queue[i].at(distance - 1))); d_gnss_synchro_history_queue.at(i).at(distance - 1)));
adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter)); adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
} }
else else
{ {
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter)); realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].at(distance - 1).Channel_ID, adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue.at(i).at(distance - 1).Channel_ID,
d_gnss_synchro_history_queue[i].at(distance - 1))); d_gnss_synchro_history_queue.at(i).at(distance - 1)));
} }
} }
@ -472,7 +475,7 @@ int hybrid_observables_cc::general_work (int noutput_items ,
* common RX time algorithm * common RX time algorithm
*/ */
// what is the most recent symbol TOW in the current set? -> this will be the reference symbol // what is the most recent symbol TOW in the current set? -> this will be the reference symbol
gnss_synchro_map_iter = max_element(realigned_gnss_synchro_map.cbegin(), gnss_synchro_map_iter = std::max_element(realigned_gnss_synchro_map.cbegin(),
realigned_gnss_synchro_map.cend(), realigned_gnss_synchro_map.cend(),
Hybrid_pairCompare_gnss_synchro_d_TOW); Hybrid_pairCompare_gnss_synchro_d_TOW);
double ref_fs_hz = static_cast<double>(gnss_synchro_map_iter->second.fs); double ref_fs_hz = static_cast<double>(gnss_synchro_map_iter->second.fs);
@ -575,19 +578,32 @@ int hybrid_observables_cc::general_work (int noutput_items ,
} }
// Move RX time // Move RX time
T_rx_s = T_rx_s + T_rx_step_s; T_rx_s += T_rx_step_s;
// pop old elements from queue // pop old elements from queue
for (unsigned int i = 0; i < d_nchannels; i++) for (unsigned int i = 0; i < d_nchannels; i++)
{ {
if (!d_gnss_synchro_history_queue[i].empty()) if (!d_gnss_synchro_history_queue.at(i).empty())
{ {
while (static_cast<double>(d_gnss_synchro_history_queue[i].front().Tracking_sample_counter) / static_cast<double>(d_gnss_synchro_history_queue[i].front().fs) < (T_rx_s - past_history_s)) while (static_cast<double>(d_gnss_synchro_history_queue.at(i).front().Tracking_sample_counter) / static_cast<double>(d_gnss_synchro_history_queue.at(i).front().fs) < (T_rx_s - past_history_s))
{ {
d_gnss_synchro_history_queue[i].pop_front(); d_gnss_synchro_history_queue.at(i).pop_front();
} }
} }
} }
} }
}// End of try{...}
catch(std::out_of_range& e)
{
LOG(WARNING) << "Out of range exception thrown by Hybrid Observables block. Exception message: " << e.what();
std::cout << "Out of range exception thrown by Hybrid Observables block. Exception message: " << e.what() << std::endl;
}
catch(...)
{
LOG(WARNING) << "Undefined exception thrown by Hybrid Observables block.";
std::cout << "Undefined exception thrown by Hybrid Observables block." << std::endl;
}
}while(channel_history_ok == true && noutput_items > n_outputs); }while(channel_history_ok == true && noutput_items > n_outputs);
// Multi-rate consume! // Multi-rate consume!