Dear guru,
I am trying to create a block similar to Vector Source.
My objective is to stop the flow graph when the vector has sent out all
its
elements.
(This is equivalent to “Repeat: No” in Vector Source)
But the function stop() fails to work. The flow graph continue executing
infinitely…
Question:
How to stop the flow graph when this->d_complete == true ?
Below is my code in file: “lib/integer_source_impl.cc”
#include <gr_io_signature.h>
#include “integer_source_impl.h”
namespace gr {
namespace activecat {
integer_source::sptr
integer_source::make(const std::vector <int> &data, bool repeat)
{ return gnuradio::get_initial_sptr (new integer_source_impl( data,
repeat )); }
// private constructor
integer_source_impl::integer_source_impl( const std::vector <int>
&data, bool repeat)
: gr_sync_block(“integer_source”,
gr_make_io_signature( 0, 0, 0 ),
gr_make_io_signature( 1, 1, sizeof(int))),
d_data( data ),
d_repeat( repeat ),
d_count( 0 ),
d_completed( false )
{ }
// virtual destructor
integer_source_impl::~integer_source_impl()
{ }
int
integer_source_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
if ( d_completed )
{
std::cout << "Have completed one cycle!" << std::endl;
stop();
return 0;
}
int *out = (int *) output_items[0];
int size = d_data.size();
for (int i=0; i < noutput_items; i++)
{
out[i] = d_data[ d_count ];
d_count++;
if ( d_count >= size )
d_count = 0;
}
d_completed = true;
// Tell runtime system how many output items we produced.
return noutput_items;
}
} /* namespace activecat /
} / namespace gr */