1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 04:30:33 +00:00

Rewriting flowgraph with smart pointers

This commit is contained in:
Carles Fernandez 2014-04-12 19:45:45 +02:00
parent 5a79a708a1
commit 6b1c12f111
2 changed files with 57 additions and 48 deletions

View File

@ -102,7 +102,7 @@ void GNSSFlowgraph::stop()
for (unsigned int i = 0; i < channels_count_; i++) for (unsigned int i = 0; i < channels_count_; i++)
{ {
// if(channels_state_[i]==2) channel(i)-> // if(channels_state_[i]==2) channel(i)->
channel(i)->stop(); channels_.at(i)->stop();
} }
for (unsigned int i = 0; i < channels_count_; i++) for (unsigned int i = 0; i < channels_count_; i++)
{ {
@ -130,7 +130,9 @@ void GNSSFlowgraph::connect()
try try
{ {
signal_source()->connect(top_block_); // sig_source_ = signal_source();
sig_source_ = std::move(blocks_->at(0));
sig_source_->connect(top_block_);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -143,7 +145,8 @@ void GNSSFlowgraph::connect()
// Signal Source > Signal conditioner > // Signal Source > Signal conditioner >
try try
{ {
signal_conditioner()->connect(top_block_); sig_conditioner_ = std::move(blocks_->at(1));
sig_conditioner_->connect(top_block_);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -157,7 +160,11 @@ void GNSSFlowgraph::connect()
{ {
try try
{ {
channel(i)->connect(top_block_); auto chan_ = std::move(blocks_->at(i + 5));
std::shared_ptr<ChannelInterface> chan = std::dynamic_pointer_cast<ChannelInterface>(chan_);
channels_.push_back(chan);
channels_.at(i)->connect(top_block_);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -170,7 +177,8 @@ void GNSSFlowgraph::connect()
try try
{ {
observables()->connect(top_block_); observables_ = std::move(blocks_->at(2));
observables_->connect(top_block_);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -183,7 +191,8 @@ void GNSSFlowgraph::connect()
// Signal Source > Signal conditioner >> Channels >> Observables > PVT // Signal Source > Signal conditioner >> Channels >> Observables > PVT
try try
{ {
pvt()->connect(top_block_); pvt_ = std::move(blocks_->at(3));
pvt_->connect(top_block_);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -196,7 +205,8 @@ void GNSSFlowgraph::connect()
// Signal Source > Signal conditioner >> Channels >> Observables > PVT > Output Filter // Signal Source > Signal conditioner >> Channels >> Observables > PVT > Output Filter
try try
{ {
output_filter()->connect(top_block_); output_filter_ = std::move(blocks_->at(4));
output_filter_->connect(top_block_);
std::cout << "helllllout" << std::endl; std::cout << "helllllout" << std::endl;
} }
catch (std::exception& e) catch (std::exception& e)
@ -211,24 +221,24 @@ void GNSSFlowgraph::connect()
// Signal Source > Signal conditioner > // Signal Source > Signal conditioner >
std::cout<< *signal_source()->implementation().c_str() <<std::endl; std::cout<< sig_source_->implementation().c_str() <<std::endl;
try try
{ {
if(signal_source()->implementation().compare("Raw_Array_Signal_Source") == 0) if(sig_source_->implementation().compare("Raw_Array_Signal_Source") == 0)
{ {
//Multichannel Array //Multichannel Array
std::cout << "ARRAY MODE" << std::endl; std::cout << "ARRAY MODE" << std::endl;
for (int i = 0; i < GNSS_SDR_ARRAY_SIGNAL_CONDITIONER_CHANNELS; i++) for (int i = 0; i < GNSS_SDR_ARRAY_SIGNAL_CONDITIONER_CHANNELS; i++)
{ {
std::cout << "connecting ch "<< i << std::endl; std::cout << "connecting ch "<< i << std::endl;
top_block_->connect(signal_source()->get_right_block(), i, signal_conditioner()->get_left_block(), i); top_block_->connect(sig_source_->get_right_block(), i, sig_conditioner_->get_left_block(), i);
} }
} }
else else
{ {
//single channel //single channel
//std::cout<<"NORMAL MODE"<<std::endl; // std::cout<<"NORMAL MODE"<<std::endl;
top_block_->connect(signal_source()->get_right_block(), 0, signal_conditioner()->get_left_block(), 0); top_block_->connect(sig_source_->get_right_block(), 0, sig_conditioner_->get_left_block(), 0);
} }
} }
@ -246,8 +256,8 @@ void GNSSFlowgraph::connect()
{ {
try try
{ {
top_block_->connect(signal_conditioner()->get_right_block(), 0, top_block_->connect(sig_conditioner_->get_right_block(), 0,
channel(i)->get_left_block(), 0); channels_.at(i)->get_left_block(), 0);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -262,8 +272,8 @@ void GNSSFlowgraph::connect()
// Signal Source > Signal conditioner >> Channels >> Observables // Signal Source > Signal conditioner >> Channels >> Observables
try try
{ {
top_block_->connect(channel(i)->get_right_block(), 0, top_block_->connect(channels_.at(i)->get_right_block(), 0,
observables()->get_left_block(), i); observables_->get_left_block(), i);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -272,14 +282,15 @@ void GNSSFlowgraph::connect()
top_block_->disconnect_all(); top_block_->disconnect_all();
return; return;
} }
std::cout<<"NORMAL MODE"<<std::endl;
channel(i)->set_signal(available_GNSS_signals_.front()); channels_.at(i)->set_signal(available_GNSS_signals_.front());
LOG(INFO) << "Channel " << i << " assigned to " << available_GNSS_signals_.front(); LOG(INFO) << "Channel " << i << " assigned to " << available_GNSS_signals_.front();
available_GNSS_signals_.pop_front(); available_GNSS_signals_.pop_front();
channel(i)->start(); channels_.at(i)->start();
std::cout<<"NORMAL MODE"<<std::endl;
if (channels_state_[i] == 1) if (channels_state_[i] == 1)
{ {
channel(i)->start_acquisition(); channels_.at(i)->start_acquisition();
LOG(INFO) << "Channel " << i LOG(INFO) << "Channel " << i
<< " connected to observables and ready for acquisition"; << " connected to observables and ready for acquisition";
} }
@ -297,7 +308,7 @@ void GNSSFlowgraph::connect()
{ {
for (unsigned int i = 0; i < channels_count_; i++) for (unsigned int i = 0; i < channels_count_; i++)
{ {
top_block_->connect(observables()->get_right_block(), i, pvt()->get_left_block(), i); top_block_->connect(observables_->get_right_block(), i, pvt_->get_left_block(), i);
} }
} }
catch (std::exception& e) catch (std::exception& e)
@ -310,7 +321,7 @@ void GNSSFlowgraph::connect()
try try
{ {
top_block_->connect(pvt()->get_right_block(), 0, output_filter()->get_left_block(), 0); top_block_->connect(pvt_->get_right_block(), 0, output_filter_->get_left_block(), 0);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -358,23 +369,23 @@ void GNSSFlowgraph::apply_action(unsigned int who, unsigned int what)
switch (what) switch (what)
{ {
case 0: case 0:
LOG(INFO) << "Channel " << who << " ACQ FAILED satellite " << channel(who)->get_signal().get_satellite(); LOG(INFO) << "Channel " << who << " ACQ FAILED satellite " << channels_.at(who)->get_signal().get_satellite();
available_GNSS_signals_.push_back(channel(who)->get_signal()); available_GNSS_signals_.push_back(channels_.at(who)->get_signal());
while (channel(who)->get_signal().get_satellite().get_system() != available_GNSS_signals_.front().get_satellite().get_system()) while (channels_.at(who)->get_signal().get_satellite().get_system() != available_GNSS_signals_.front().get_satellite().get_system())
{ {
available_GNSS_signals_.push_back(available_GNSS_signals_.front()); available_GNSS_signals_.push_back(available_GNSS_signals_.front());
available_GNSS_signals_.pop_front(); available_GNSS_signals_.pop_front();
} }
channel(who)->set_signal(available_GNSS_signals_.front()); channels_.at(who)->set_signal(available_GNSS_signals_.front());
available_GNSS_signals_.pop_front(); available_GNSS_signals_.pop_front();
channel(who)->start_acquisition(); channels_.at(who)->start_acquisition();
break; break;
// TODO: Tracking messages // TODO: Tracking messages
case 1: case 1:
LOG(INFO) << "Channel " << who << " ACQ SUCCESS satellite " << channel(who)->get_signal().get_satellite(); LOG(INFO) << "Channel " << who << " ACQ SUCCESS satellite " << channels_.at(who)->get_signal().get_satellite();
channels_state_[who] = 2; channels_state_[who] = 2;
acq_channels_count_--; acq_channels_count_--;
if (acq_channels_count_ < max_acq_channels_) if (acq_channels_count_ < max_acq_channels_)
@ -385,7 +396,7 @@ void GNSSFlowgraph::apply_action(unsigned int who, unsigned int what)
{ {
channels_state_[i] = 1; channels_state_[i] = 1;
acq_channels_count_++; acq_channels_count_++;
channel(i)->start_acquisition(); channels_.at(i)->start_acquisition();
break; break;
} }
} }
@ -398,17 +409,17 @@ void GNSSFlowgraph::apply_action(unsigned int who, unsigned int what)
break; break;
case 2: case 2:
LOG(INFO) << "Channel " << who << " TRK FAILED satellite " << channel(who)->get_signal().get_satellite(); LOG(INFO) << "Channel " << who << " TRK FAILED satellite " << channels_.at(who)->get_signal().get_satellite();
if (acq_channels_count_ < max_acq_channels_) if (acq_channels_count_ < max_acq_channels_)
{ {
channels_state_[who] = 1; channels_state_[who] = 1;
acq_channels_count_++; acq_channels_count_++;
channel(who)->start_acquisition(); channels_.at(who)->start_acquisition();
} }
else else
{ {
channels_state_[who] = 0; channels_state_[who] = 0;
channel(who)->standby(); channels_.at(who)->standby();
} }
for (unsigned int i = 0; i < channels_count_; i++) for (unsigned int i = 0; i < channels_count_; i++)
@ -448,9 +459,12 @@ std::shared_ptr<GNSSBlockInterface> GNSSFlowgraph::signal_source()
//return cond_; //return cond_;
//return blocks_->at(0); //return blocks_->at(0);
//std::shared_ptr<GNSSBlockInterface> source_ = std::make_shared<std::shared_ptr<GNSSBlockInterface>>(); //std::shared_ptr<GNSSBlockInterface> source_ = std::make_shared<std::shared_ptr<GNSSBlockInterface>>();
auto source_ = std::move(blocks_->at(0));
//auto source_ = std::move(blocks_->at(0));
sig_source_ = std::move(blocks_->at(0));
//sig_source_ =
//std::cout << source_->implementation().c_str() << std::endl; //std::cout << source_->implementation().c_str() << std::endl;
return std::move(source_); return std::move(sig_source_);
} }
@ -458,9 +472,7 @@ std::shared_ptr<GNSSBlockInterface> GNSSFlowgraph::signal_source()
std::shared_ptr<GNSSBlockInterface> GNSSFlowgraph::signal_conditioner() std::shared_ptr<GNSSBlockInterface> GNSSFlowgraph::signal_conditioner()
{ {
//return blocks_->at(1);
auto cond_ = std::move(blocks_->at(1)); auto cond_ = std::move(blocks_->at(1));
//std::cout << source_->implementation().c_str() << std::endl;
return std::move(cond_); return std::move(cond_);
} }
@ -468,15 +480,9 @@ std::shared_ptr<GNSSBlockInterface> GNSSFlowgraph::signal_conditioner()
std::shared_ptr<ChannelInterface> GNSSFlowgraph::channel(unsigned int index) std::shared_ptr<ChannelInterface> GNSSFlowgraph::channel(unsigned int index)
{ {
//return (ChannelInterface*) blocks_->at(index + 5);
//std::shared_ptr<ChannelInterface> sptr = std::make_shared<GNSSBlockInterface>(blocks_->at(index + 5));
//return blocks_->at(index + 5);
auto chan_ = std::move(blocks_->at(index + 5)); auto chan_ = std::move(blocks_->at(index + 5));
std::shared_ptr<ChannelInterface> chan = std::dynamic_pointer_cast<ChannelInterface>(chan_); std::shared_ptr<ChannelInterface> chan = std::dynamic_pointer_cast<ChannelInterface>(chan_);
return chan; return chan;
//return sptr;
} }
@ -511,10 +517,8 @@ void GNSSFlowgraph::init()
* Instantiates the receiver blocks * Instantiates the receiver blocks
*/ */
std::shared_ptr<GNSSBlockFactory> block_factory_ = std::make_shared<GNSSBlockFactory>(); std::shared_ptr<GNSSBlockFactory> block_factory_ = std::make_shared<GNSSBlockFactory>();
//std::shared_ptr<std::vector<std::shared_ptr<GNSSBlockInterface>>> blocks_ = std::make_shared<std::vector<std::shared_ptr<GNSSBlockInterface>>>();
std::shared_ptr<GNSSBlockInterface> signal_source_ = block_factory_->GetSignalSource(configuration_, queue_); std::shared_ptr<GNSSBlockInterface> signal_source_ = block_factory_->GetSignalSource(configuration_, queue_);
std::shared_ptr<GNSSBlockInterface> cond_ = block_factory_->GetSignalConditioner(configuration_, queue_); std::shared_ptr<GNSSBlockInterface> cond_ = block_factory_->GetSignalConditioner(configuration_, queue_);
std::shared_ptr<GNSSBlockInterface> obs_ = block_factory_->GetObservables(configuration_, queue_); std::shared_ptr<GNSSBlockInterface> obs_ = block_factory_->GetObservables(configuration_, queue_);
std::shared_ptr<GNSSBlockInterface> pvt_ = block_factory_->GetPVT(configuration_, queue_); std::shared_ptr<GNSSBlockInterface> pvt_ = block_factory_->GetPVT(configuration_, queue_);
@ -540,15 +544,15 @@ void GNSSFlowgraph::init()
top_block_ = gr::make_top_block("GNSSFlowgraph"); top_block_ = gr::make_top_block("GNSSFlowgraph");
//delete channels;
// fill the available_GNSS_signals_ queue with the satellites ID's to be searched by the acquisition // fill the available_GNSS_signals_ queue with the satellites ID's to be searched by the acquisition
set_signals_list(); set_signals_list();
set_channels_state(); set_channels_state();
applied_actions_ = 0; applied_actions_ = 0;
std::vector<std::shared_ptr<ChannelInterface>> channels_(channels_count_);
//std::shared_ptr<GNSSBlockInterface> sig_source_ = signal_source();
DLOG(INFO) << "Blocks instantiated. " << channels_count_ << " channels."; DLOG(INFO) << "Blocks instantiated. " << channels_count_ << " channels.";
} }

View File

@ -134,8 +134,13 @@ private:
std::shared_ptr<GNSSBlockFactory> block_factory_; std::shared_ptr<GNSSBlockFactory> block_factory_;
//std::shared_ptr<std::vector<std::shared_ptr<GNSSBlockInterface>>> blocks_; //std::shared_ptr<std::vector<std::shared_ptr<GNSSBlockInterface>>> blocks_;
std::shared_ptr<std::vector<std::shared_ptr<GNSSBlockInterface>>> blocks_ = std::make_shared<std::vector<std::shared_ptr<GNSSBlockInterface>>>(); std::shared_ptr<std::vector<std::shared_ptr<GNSSBlockInterface>>> blocks_ = std::make_shared<std::vector<std::shared_ptr<GNSSBlockInterface>>>();
std::shared_ptr<GNSSBlockInterface> sig_source_;
//std::shared_ptr<std::vector<std::shared_ptr<ChannelInterface>>> channels_; std::shared_ptr<GNSSBlockInterface> sig_conditioner_;
std::shared_ptr<GNSSBlockInterface> observables_;
std::shared_ptr<GNSSBlockInterface> pvt_;
std::shared_ptr<GNSSBlockInterface> output_filter_;
//std::shared_ptr<std::vector<std::shared_ptr<GNSSBlockInterface>>> channels_;
std::vector<std::shared_ptr<ChannelInterface>> channels_;
gr::top_block_sptr top_block_; gr::top_block_sptr top_block_;
boost::shared_ptr<gr::msg_queue> queue_; boost::shared_ptr<gr::msg_queue> queue_;
std::list<Gnss_Signal> available_GNSS_signals_; std::list<Gnss_Signal> available_GNSS_signals_;