pms: no eof port, quit variable
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<category>Foo</category>
|
<category>Foo</category>
|
||||||
<import>import foo</import>
|
<import>import foo</import>
|
||||||
<import>import pmt</import>
|
<import>import pmt</import>
|
||||||
<make>foo.periodic_msg_source($msg, $interval, $num, $debug)</make>
|
<make>foo.periodic_msg_source($msg, $interval, $num, $quit, $debug)</make>
|
||||||
<param>
|
<param>
|
||||||
<name>Message PMT</name>
|
<name>Message PMT</name>
|
||||||
<key>msg</key>
|
<key>msg</key>
|
||||||
@@ -19,6 +19,20 @@
|
|||||||
<value>1000</value>
|
<value>1000</value>
|
||||||
<type>real</type>
|
<type>real</type>
|
||||||
</param>
|
</param>
|
||||||
|
<param>
|
||||||
|
<name>Quit</name>
|
||||||
|
<key>quit</key>
|
||||||
|
<value>True</value>
|
||||||
|
<type>bool</type>
|
||||||
|
<option>
|
||||||
|
<name>Enable</name>
|
||||||
|
<key>True</key>
|
||||||
|
</option>
|
||||||
|
<option>
|
||||||
|
<name>Disable</name>
|
||||||
|
<key>False</key>
|
||||||
|
</option>
|
||||||
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<name>Debug</name>
|
<name>Debug</name>
|
||||||
<key>debug</key>
|
<key>debug</key>
|
||||||
@@ -39,13 +53,6 @@
|
|||||||
<value>-1</value>
|
<value>-1</value>
|
||||||
<type>int</type>
|
<type>int</type>
|
||||||
</param>
|
</param>
|
||||||
|
|
||||||
<sink>
|
|
||||||
<name>eof in</name>
|
|
||||||
<type>message</type>
|
|
||||||
<optional>1</optional>
|
|
||||||
</sink>
|
|
||||||
|
|
||||||
<source>
|
<source>
|
||||||
<name>out</name>
|
<name>out</name>
|
||||||
<type>message</type>
|
<type>message</type>
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ class FOO_API periodic_msg_source : virtual public gr::block
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
typedef boost::shared_ptr<periodic_msg_source> sptr;
|
typedef boost::shared_ptr<periodic_msg_source> sptr;
|
||||||
static sptr make(pmt::pmt_t msg, float interval, int num_msg = -1, bool debug = false);
|
static sptr make(pmt::pmt_t msg, float interval, int num_msg = -1,
|
||||||
|
bool quit = true, bool debug = false);
|
||||||
|
|
||||||
virtual void set_nmsg(int nmsg) = 0;
|
virtual void set_nmsg(int nmsg) = 0;
|
||||||
virtual int get_nmsg() = 0;
|
virtual int get_nmsg() = 0;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ using namespace gr::foo;
|
|||||||
#define dout d_debug && std::cout
|
#define dout d_debug && std::cout
|
||||||
|
|
||||||
periodic_msg_source_impl::periodic_msg_source_impl(pmt::pmt_t msg,
|
periodic_msg_source_impl::periodic_msg_source_impl(pmt::pmt_t msg,
|
||||||
float interval, int num_msg, bool debug) :
|
float interval, int num_msg, bool quit, bool debug) :
|
||||||
block("periodic_msg_source",
|
block("periodic_msg_source",
|
||||||
gr::io_signature::make(0, 0, 0),
|
gr::io_signature::make(0, 0, 0),
|
||||||
gr::io_signature::make(0, 0, 0)),
|
gr::io_signature::make(0, 0, 0)),
|
||||||
@@ -38,9 +38,6 @@ periodic_msg_source_impl::periodic_msg_source_impl(pmt::pmt_t msg,
|
|||||||
|
|
||||||
message_port_register_out(pmt::mp("out"));
|
message_port_register_out(pmt::mp("out"));
|
||||||
|
|
||||||
message_port_register_in(pmt::mp("eof in"));
|
|
||||||
set_msg_handler(pmt::mp("eof in"), boost::bind(&periodic_msg_source_impl::eof_in, this, _1));
|
|
||||||
|
|
||||||
d_thread = new boost::thread(boost::bind(&periodic_msg_source_impl::run, this, this));
|
d_thread = new boost::thread(boost::bind(&periodic_msg_source_impl::run, this, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,19 +50,6 @@ periodic_msg_source_impl::~periodic_msg_source_impl() {
|
|||||||
delete d_thread;
|
delete d_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
periodic_msg_source_impl::eof_in (pmt::pmt_t msg) {
|
|
||||||
|
|
||||||
if(pmt::is_eof_object(msg)) {
|
|
||||||
detail().get()->set_done(true);
|
|
||||||
dout << "PMS: stopping msg source" << std::endl;
|
|
||||||
message_port_pub(pmt::mp("out"), pmt::PMT_EOF);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
dout << "PMS: non EOF message at eof port!" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
periodic_msg_source_impl::run(periodic_msg_source_impl *instance) {
|
periodic_msg_source_impl::run(periodic_msg_source_impl *instance) {
|
||||||
|
|
||||||
@@ -80,6 +64,7 @@ periodic_msg_source_impl::run(periodic_msg_source_impl *instance) {
|
|||||||
gr::thread::scoped_lock(d_mutex);
|
gr::thread::scoped_lock(d_mutex);
|
||||||
if(d_finished || !d_nmsg_left) {
|
if(d_finished || !d_nmsg_left) {
|
||||||
d_finished = true;
|
d_finished = true;
|
||||||
|
if(d_quit) post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +85,7 @@ periodic_msg_source_impl::run(periodic_msg_source_impl *instance) {
|
|||||||
gr::thread::scoped_lock(d_mutex);
|
gr::thread::scoped_lock(d_mutex);
|
||||||
dout << "PMS: thread interrupted" << std::endl;
|
dout << "PMS: thread interrupted" << std::endl;
|
||||||
d_finished = true;
|
d_finished = true;
|
||||||
|
if(d_quit) post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +139,7 @@ periodic_msg_source_impl::is_running() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
periodic_msg_source::sptr
|
periodic_msg_source::sptr
|
||||||
periodic_msg_source::make(pmt::pmt_t msg, float interval, int num_msg, bool debug) {
|
periodic_msg_source::make(pmt::pmt_t msg, float interval, int num_msg, bool quit, bool debug) {
|
||||||
return gnuradio::get_initial_sptr(new periodic_msg_source_impl(msg, interval, num_msg, debug));
|
return gnuradio::get_initial_sptr(new periodic_msg_source_impl(msg, interval, num_msg, quit, debug));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ namespace foo {
|
|||||||
class periodic_msg_source_impl : public periodic_msg_source {
|
class periodic_msg_source_impl : public periodic_msg_source {
|
||||||
private:
|
private:
|
||||||
void run(periodic_msg_source_impl *instance);
|
void run(periodic_msg_source_impl *instance);
|
||||||
void eof_in(pmt::pmt_t msg);
|
|
||||||
|
|
||||||
int d_nmsg_total;
|
int d_nmsg_total;
|
||||||
int d_nmsg_left;
|
int d_nmsg_left;
|
||||||
bool d_debug;
|
bool d_debug;
|
||||||
|
bool d_quit;
|
||||||
bool d_finished;
|
bool d_finished;
|
||||||
float d_interval;
|
float d_interval;
|
||||||
pmt::pmt_t d_msg;
|
pmt::pmt_t d_msg;
|
||||||
@@ -38,7 +38,8 @@ namespace foo {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
periodic_msg_source_impl(pmt::pmt_t msg,
|
periodic_msg_source_impl(pmt::pmt_t msg,
|
||||||
float interval, int num_msg, bool debug);
|
float interval, int num_msg,
|
||||||
|
bool quit, bool debug);
|
||||||
virtual ~periodic_msg_source_impl();
|
virtual ~periodic_msg_source_impl();
|
||||||
|
|
||||||
void set_nmsg(int nmsg);
|
void set_nmsg(int nmsg);
|
||||||
|
|||||||
Reference in New Issue
Block a user