pms: no eof port, quit variable

This commit is contained in:
Bastian Bloessl
2014-08-26 11:07:22 +02:00
parent 0af0f5750f
commit 43b460a2ae
4 changed files with 25 additions and 30 deletions
+15 -8
View File
@@ -6,7 +6,7 @@
<category>Foo</category>
<import>import foo</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>
<name>Message PMT</name>
<key>msg</key>
@@ -19,6 +19,20 @@
<value>1000</value>
<type>real</type>
</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>
<name>Debug</name>
<key>debug</key>
@@ -39,13 +53,6 @@
<value>-1</value>
<type>int</type>
</param>
<sink>
<name>eof in</name>
<type>message</type>
<optional>1</optional>
</sink>
<source>
<name>out</name>
<type>message</type>
+2 -1
View File
@@ -28,7 +28,8 @@ class FOO_API periodic_msg_source : virtual public gr::block
public:
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 int get_nmsg() = 0;
+5 -19
View File
@@ -25,7 +25,7 @@ using namespace gr::foo;
#define dout d_debug && std::cout
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",
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_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));
}
@@ -53,19 +50,6 @@ periodic_msg_source_impl::~periodic_msg_source_impl() {
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
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);
if(d_finished || !d_nmsg_left) {
d_finished = true;
if(d_quit) post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1)));
break;
}
@@ -100,6 +85,7 @@ periodic_msg_source_impl::run(periodic_msg_source_impl *instance) {
gr::thread::scoped_lock(d_mutex);
dout << "PMS: thread interrupted" << std::endl;
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::make(pmt::pmt_t msg, float interval, int num_msg, bool debug) {
return gnuradio::get_initial_sptr(new periodic_msg_source_impl(msg, interval, num_msg, 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, quit, debug));
}
+3 -2
View File
@@ -25,11 +25,11 @@ namespace foo {
class periodic_msg_source_impl : public periodic_msg_source {
private:
void run(periodic_msg_source_impl *instance);
void eof_in(pmt::pmt_t msg);
int d_nmsg_total;
int d_nmsg_left;
bool d_debug;
bool d_quit;
bool d_finished;
float d_interval;
pmt::pmt_t d_msg;
@@ -38,7 +38,8 @@ namespace foo {
public:
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();
void set_nmsg(int nmsg);