1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-13 19:50:34 +00:00

Avoid segmentation faults if the SignalConditioner is not well defined in the configuration

This commit is contained in:
Carles Fernandez 2021-01-26 23:11:06 +01:00
parent 24041058a6
commit d249a7efcf
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
8 changed files with 52 additions and 21 deletions

View File

@ -57,6 +57,26 @@ void SignalConditioner::connect(gr::top_block_sptr top_block)
in_filt_->connect(top_block);
res_->connect(top_block);
if (in_filt_->item_size() == 0)
{
throw std::invalid_argument("itemsize mismatch: Invalid input/ouput data type configuration for the InputFilter");
}
const size_t data_type_adapter_output_size = data_type_adapt_->get_right_block()->output_signature()->sizeof_stream_item(0);
const size_t input_filter_input_size = in_filt_->get_left_block()->input_signature()->sizeof_stream_item(0);
const size_t input_filter_output_size = in_filt_->get_right_block()->output_signature()->sizeof_stream_item(0);
const size_t resampler_input_size = res_->get_left_block()->input_signature()->sizeof_stream_item(0);
if (data_type_adapter_output_size != input_filter_input_size)
{
throw std::invalid_argument("itemsize mismatch: Invalid input/ouput data type configuration for the DataTypeAdapter/InputFilter connection");
}
if (input_filter_output_size != resampler_input_size)
{
throw std::invalid_argument("itemsize mismatch: Invalid input/ouput data type configuration for the Input Filter/Resampler connection");
}
top_block->connect(data_type_adapt_->get_right_block(), 0, in_filt_->get_left_block(), 0);
DLOG(INFO) << "data_type_adapter -> input_filter";

View File

@ -43,7 +43,7 @@ BeamformerFilter::BeamformerFilter(
{
LOG(WARNING) << item_type_
<< " unrecognized item type for beamformer";
item_size_ = sizeof(gr_complex);
item_size_ = 0;
}
if (dump_)
{

View File

@ -159,8 +159,8 @@ FreqXlatingFirFilter::FreqXlatingFirFilter(const ConfigurationInterface* configu
else
{
LOG(ERROR) << " Unknown input filter input/output item type conversion";
item_size = sizeof(gr_complex); // avoids uninitialization
input_size_ = sizeof(gr_complex); // avoids uninitialization
item_size = sizeof(gr_complex); // avoids uninitialization
input_size_ = 0; // notifies wrong configuration
}
if (dump_)

View File

@ -51,7 +51,7 @@ NotchFilter::NotchFilter(const ConfigurationInterface* configuration, const std:
else
{
LOG(WARNING) << item_type_ << " unrecognized item type for notch filter";
item_size_ = sizeof(gr_complex);
item_size_ = 0; // notify wrong configuration
}
if (dump_)
{

View File

@ -58,7 +58,7 @@ NotchFilterLite::NotchFilterLite(const ConfigurationInterface* configuration, co
else
{
LOG(WARNING) << item_type_ << " unrecognized item type for notch filter";
item_size_ = sizeof(gr_complex);
item_size_ = 0;
}
if (dump_)
{

View File

@ -31,14 +31,12 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
{
size_t item_size;
xlat_ = false;
const std::string default_input_item_type("gr_complex");
const std::string default_output_item_type("gr_complex");
const std::string default_item_type("gr_complex");
const std::string default_dump_filename("../data/input_filter.dat");
DLOG(INFO) << "role " << role_;
input_item_type_ = configuration->property(role_ + ".input_item_type", default_input_item_type);
output_item_type_ = configuration->property(role_ + ".output_item_type", default_output_item_type);
item_type_ = configuration->property(role_ + ".item_type", default_item_type);
dump_ = configuration->property(role_ + ".dump", false);
dump_filename_ = configuration->property(role_ + ".dump_filename", default_dump_filename);
const float default_pfa_ = 0.04;
@ -49,7 +47,7 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
const int n_segments_est = configuration->property(role_ + ".segments_est", default_n_segments_est);
const int default_n_segments_reset = 5000000;
const int n_segments_reset = configuration->property(role_ + ".segments_reset", default_n_segments_reset);
if (input_item_type_ == "gr_complex")
if (item_type_ == "gr_complex")
{
item_size = sizeof(gr_complex); // output
input_size_ = sizeof(gr_complex); // input
@ -57,9 +55,9 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
}
else
{
LOG(ERROR) << " Unknown input filter input/output item type conversion";
item_size = sizeof(gr_complex); // avoids uninitialization
input_size_ = sizeof(gr_complex); // avoids uninitialization
LOG(ERROR) << "Unknown input filter item_types conversion";
item_size = sizeof(gr_complex); // avoids uninitialization
input_size_ = 0; // notify wrong configuration
}
const double default_if = 0.0;
const double if_aux = configuration->property(role_ + ".if", default_if);
@ -95,7 +93,7 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
void PulseBlankingFilter::connect(gr::top_block_sptr top_block)
{
if (input_item_type_ == "gr_complex")
if (item_type_ == "gr_complex")
{
if (dump_)
{
@ -116,7 +114,7 @@ void PulseBlankingFilter::connect(gr::top_block_sptr top_block)
void PulseBlankingFilter::disconnect(gr::top_block_sptr top_block)
{
if (input_item_type_ == "gr_complex")
if (item_type_ == "gr_complex")
{
if (dump_)
{
@ -136,7 +134,7 @@ void PulseBlankingFilter::disconnect(gr::top_block_sptr top_block)
gr::basic_block_sptr PulseBlankingFilter::get_left_block()
{
if (input_item_type_ == "gr_complex")
if (item_type_ == "gr_complex")
{
if (xlat_)
{
@ -151,7 +149,7 @@ gr::basic_block_sptr PulseBlankingFilter::get_left_block()
gr::basic_block_sptr PulseBlankingFilter::get_right_block()
{
if (input_item_type_ == "gr_complex")
if (item_type_ == "gr_complex")
{
return pulse_blanking_cc_;
}

View File

@ -71,8 +71,7 @@ private:
gr::filter::freq_xlating_fir_filter_ccf::sptr freq_xlating_;
gr::blocks::file_sink::sptr file_sink_;
std::string dump_filename_;
std::string input_item_type_;
std::string output_item_type_;
std::string item_type_;
std::string role_;
size_t input_size_;
unsigned int in_streams_;

View File

@ -753,12 +753,26 @@ int GNSSFlowgraph::connect_signal_conditioners()
}
if (std::string::npos != reported_error.find(std::string("InputFilter")))
{
help_hint_ += " * The InputFilter implementation set in the configuration file does not exist\n";
if (std::string::npos != reported_error.find(std::string("itemsize mismatch")))
{
help_hint_ += " * The configured InputFilter input/output item types are not well defined.\n";
}
else
{
help_hint_ += " * The InputFilter implementation set in the configuration file does not exist\n";
}
help_hint_ += " Check the InputFilter documentation at https://gnss-sdr.org/docs/sp-blocks/input-filter/\n";
}
if (std::string::npos != reported_error.find(std::string("Resampler")))
{
help_hint_ += " * The Resampler implementation set in the configuration file does not exist\n";
if (std::string::npos != reported_error.find(std::string("itemsize mismatch")))
{
help_hint_ += " * The configured Resampler item type is not well defined.\n";
}
else
{
help_hint_ += " * The Resampler implementation set in the configuration file does not exist\n";
}
help_hint_ += " Check the Resampler documentation at https://gnss-sdr.org/docs/sp-blocks/resampler/\n";
}
return 1;