summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/general
diff options
context:
space:
mode:
authorJosh Blum2013-03-17 23:12:31 -0700
committerJosh Blum2013-03-17 23:12:31 -0700
commitbfefd11011987fe9755dd72d86ad4f052b3d263e (patch)
tree73b3960d46caed9996dfeff4856c3bcc546c9006 /gnuradio-core/src/lib/general
parentcb5ff01c491d4558a096fc1649b85283c36ccf91 (diff)
parent3693ee3259fa8bf2d9ad393842a80cd1fc330863 (diff)
downloadgnuradio-bfefd11011987fe9755dd72d86ad4f052b3d263e.tar.gz
gnuradio-bfefd11011987fe9755dd72d86ad4f052b3d263e.tar.bz2
gnuradio-bfefd11011987fe9755dd72d86ad4f052b3d263e.zip
Merge branch 'maint' of https://github.com/guruofquality/gnuradio into v3.6.4git_gras_support
Conflicts: gnuradio-core/src/lib/runtime/gr_block.cc gnuradio-core/src/lib/runtime/gr_block.h gnuradio-core/src/lib/runtime/gr_types.h
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r--gnuradio-core/src/lib/general/CMakeLists.txt1
-rw-r--r--gnuradio-core/src/lib/general/general.i2
-rw-r--r--gnuradio-core/src/lib/general/gr_block_gateway.h52
-rw-r--r--gnuradio-core/src/lib/general/gr_feval.cc16
-rw-r--r--gnuradio-core/src/lib/general/gr_feval.h29
-rw-r--r--gnuradio-core/src/lib/general/gr_feval.i29
-rw-r--r--gnuradio-core/src/lib/general/gr_prefs.cc165
-rw-r--r--gnuradio-core/src/lib/general/gr_prefs.h32
-rw-r--r--gnuradio-core/src/lib/general/gr_prefs.i25
-rw-r--r--gnuradio-core/src/lib/general/gr_random_pdu.cc84
-rw-r--r--gnuradio-core/src/lib/general/gr_random_pdu.h64
-rw-r--r--gnuradio-core/src/lib/general/gr_random_pdu.i30
12 files changed, 492 insertions, 37 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt
index 4c99acfc3..ce9a80f37 100644
--- a/gnuradio-core/src/lib/general/CMakeLists.txt
+++ b/gnuradio-core/src/lib/general/CMakeLists.txt
@@ -259,6 +259,7 @@ set(gr_core_general_triple_threats
gr_pwr_squelch_cc
gr_pwr_squelch_ff
gr_quadrature_demod_cf
+ gr_random_pdu
gr_rail_ff
gr_regenerate_bb
gr_remez
diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i
index 1446088a2..b727bc8a6 100644
--- a/gnuradio-core/src/lib/general/general.i
+++ b/gnuradio-core/src/lib/general/general.i
@@ -70,6 +70,7 @@
#include <gr_agc_cc.h>
#include <gr_agc2_ff.h>
#include <gr_agc2_cc.h>
+#include <gr_random_pdu.h>
#include <gr_rms_cf.h>
#include <gr_rms_ff.h>
#include <gr_nlog10_ff.h>
@@ -194,6 +195,7 @@
%include "gr_agc_cc.i"
%include "gr_agc2_ff.i"
%include "gr_agc2_cc.i"
+%include "gr_random_pdu.i"
%include "gr_rms_cf.i"
%include "gr_rms_ff.i"
%include "gr_nlog10_ff.i"
diff --git a/gnuradio-core/src/lib/general/gr_block_gateway.h b/gnuradio-core/src/lib/general/gr_block_gateway.h
index ae91d41b5..2452b1045 100644
--- a/gnuradio-core/src/lib/general/gr_block_gateway.h
+++ b/gnuradio-core/src/lib/general/gr_block_gateway.h
@@ -188,6 +188,58 @@ public:
gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end, key);
return tags;
}
+
+ /* Message passing interface */
+ void gr_block__message_port_register_in(pmt::pmt_t port_id){
+ gr_block::message_port_register_in(port_id);
+ }
+
+ void gr_block__message_port_register_out(pmt::pmt_t port_id){
+ gr_block::message_port_register_out(port_id);
+ }
+
+ void gr_block__message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg){
+ gr_block::message_port_pub(port_id, msg);
+ }
+
+ void gr_block__message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target){
+ gr_block::message_port_sub(port_id, target);
+ }
+
+ void gr_block__message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target){
+ gr_block::message_port_unsub(port_id, target);
+ }
+
+ pmt::pmt_t gr_block__message_ports_in(){
+ return gr_block::message_ports_in();
+ }
+
+ pmt::pmt_t gr_block__message_ports_out(){
+ return gr_block::message_ports_out();
+ }
+
+ void set_msg_handler_feval(pmt::pmt_t which_port, gr_feval_p *msg_handler)
+ {
+ if(msg_queue.find(which_port) == msg_queue.end()){
+ throw std::runtime_error("attempt to set_msg_handler_feval() on bad input message port!");
+ }
+ d_msg_handlers_feval[which_port] = msg_handler;
+ }
+
+protected:
+ typedef std::map<pmt::pmt_t, gr_feval_p *, pmt::pmt_comperator> msg_handlers_feval_t;
+ msg_handlers_feval_t d_msg_handlers_feval;
+
+ void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg){
+ // Is there a handler?
+ if (d_msg_handlers_feval.find(which_port) != d_msg_handlers_feval.end()){
+ d_msg_handlers_feval[which_port]->calleval(msg); // Yes, invoke it.
+ }
+ else {
+ // Pass to generic dispatcher if not found
+ gr_block::dispatch_msg(which_port, msg);
+ }
+ }
};
/*!
diff --git a/gnuradio-core/src/lib/general/gr_feval.cc b/gnuradio-core/src/lib/general/gr_feval.cc
index ca5714a79..89f09984c 100644
--- a/gnuradio-core/src/lib/general/gr_feval.cc
+++ b/gnuradio-core/src/lib/general/gr_feval.cc
@@ -88,6 +88,22 @@ gr_feval::calleval(void)
eval();
}
+// ----------------------------------------------------------------
+
+gr_feval_p::~gr_feval_p(){}
+
+void
+gr_feval_p::eval(pmt::pmt_t x)
+{
+ // nop
+}
+
+void
+gr_feval_p::calleval(pmt::pmt_t x)
+{
+ eval(x);
+}
+
/*
* Trivial examples showing C++ (transparently) calling Python
*/
diff --git a/gnuradio-core/src/lib/general/gr_feval.h b/gnuradio-core/src/lib/general/gr_feval.h
index 1726a8a7f..a9bccfe51 100644
--- a/gnuradio-core/src/lib/general/gr_feval.h
+++ b/gnuradio-core/src/lib/general/gr_feval.h
@@ -24,6 +24,7 @@
#include <gr_core_api.h>
#include <gr_complex.h>
+#include <gruel/pmt.h>
/*!
* \brief base class for evaluating a function: double -> double
@@ -138,6 +139,34 @@ public:
};
/*!
+ * \brief base class for evaluating a function: pmt -> void
+ * \ingroup misc
+ *
+ * This class is designed to be subclassed in Python or C++
+ * and is callable from both places. It uses SWIG's
+ * "director" feature to implement the magic.
+ * It's slow. Don't use it in a performance critical path.
+ *
+ * Override eval to define the behavior.
+ * Use calleval to invoke eval (this kludge is required to allow a
+ * python specific "shim" to be inserted.
+ */
+class GR_CORE_API gr_feval_p
+{
+protected:
+ /*!
+ * \brief override this to define the function
+ */
+ virtual void eval(pmt::pmt_t x);
+
+public:
+ gr_feval_p() {}
+ virtual ~gr_feval_p();
+
+ virtual void calleval(pmt::pmt_t x); // invoke "eval"
+};
+
+/*!
* \brief trivial examples / test cases showing C++ calling Python code
*/
GR_CORE_API double gr_feval_dd_example(gr_feval_dd *f, double x);
diff --git a/gnuradio-core/src/lib/general/gr_feval.i b/gnuradio-core/src/lib/general/gr_feval.i
index bc219a643..bcf4f1e64 100644
--- a/gnuradio-core/src/lib/general/gr_feval.i
+++ b/gnuradio-core/src/lib/general/gr_feval.i
@@ -45,23 +45,28 @@
// Directors are only supported in Python, Java and C#
#ifdef SWIGPYTHON
+%include "pmt_swig.i"
+using namespace pmt;
// Enable SWIG directors for these classes
%feature("director") gr_py_feval_dd;
%feature("director") gr_py_feval_cc;
%feature("director") gr_py_feval_ll;
%feature("director") gr_py_feval;
+%feature("director") gr_py_feval_p;
%feature("nodirector") gr_py_feval_dd::calleval;
%feature("nodirector") gr_py_feval_cc::calleval;
%feature("nodirector") gr_py_feval_ll::calleval;
%feature("nodirector") gr_py_feval::calleval;
+%feature("nodirector") gr_py_feval_p::calleval;
%rename(feval_dd) gr_py_feval_dd;
%rename(feval_cc) gr_py_feval_cc;
%rename(feval_ll) gr_py_feval_ll;
%rename(feval) gr_py_feval;
+%rename(feval_p) gr_py_feval_p;
//%exception {
// try { $action }
@@ -136,12 +141,26 @@ public:
virtual void calleval();
};
+%ignore gr_feval_p;
+class gr_feval_p
+{
+protected:
+ virtual void eval(pmt_t x);
+
+public:
+ gr_feval_p() {}
+ virtual ~gr_feval_p();
+
+ virtual void calleval(pmt_t x);
+};
+
/*
* These are the ones to derive from in Python. They have the magic shim
* that ensures that we're holding the Python GIL when we enter Python land...
*/
%inline %{
+#include <gruel/pmt.h>
class gr_py_feval_dd : public gr_feval_dd
{
@@ -183,6 +202,16 @@ class gr_py_feval : public gr_feval
}
};
+class gr_py_feval_p : public gr_feval_p
+{
+ public:
+ void calleval(pmt::pmt_t x)
+ {
+ ensure_py_gil_state _lock;
+ eval(x);
+ }
+};
+
%}
diff --git a/gnuradio-core/src/lib/general/gr_prefs.cc b/gnuradio-core/src/lib/general/gr_prefs.cc
index 20aead8e3..9705eed4f 100644
--- a/gnuradio-core/src/lib/general/gr_prefs.cc
+++ b/gnuradio-core/src/lib/general/gr_prefs.cc
@@ -25,6 +25,14 @@
#endif
#include <gr_prefs.h>
+#include <gr_sys_paths.h>
+#include <gr_constants.h>
+#include <algorithm>
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/fstream.hpp>
+namespace fs = boost::filesystem;
/*
* Stub implementations
@@ -45,44 +53,177 @@ gr_prefs::set_singleton(gr_prefs *p)
s_singleton = p;
}
+gr_prefs::gr_prefs()
+{
+ _read_files();
+}
+
gr_prefs::~gr_prefs()
{
// nop
}
+std::vector<std::string>
+gr_prefs::_sys_prefs_filenames()
+{
+ std::vector<std::string> fnames;
+
+ fs::path dir = gr_prefsdir();
+ if(!fs::is_directory(dir))
+ return fnames;
+
+ fs::directory_iterator diritr(dir);
+ while(diritr != fs::directory_iterator()) {
+ fs::path p = *diritr++;
+ fnames.push_back(p.string());
+ }
+ std::sort(fnames.begin(), fnames.end());
+
+ // Find if there is a ~/.gnuradio/config file and add this to the
+ // beginning of the file list to override any preferences in the
+ // installed path config files.
+ fs::path homedir = fs::path(gr_appdata_path());
+ homedir = homedir/".gnuradio/config.conf";
+ if(fs::exists(homedir)) {
+ fnames.insert(fnames.begin(), homedir.string());
+ }
+
+ return fnames;
+}
+
+void
+gr_prefs::_read_files()
+{
+ std::vector<std::string> filenames = _sys_prefs_filenames();
+ std::vector<std::string>::iterator sitr;
+ char tmp[1024];
+ for(sitr = filenames.begin(); sitr != filenames.end(); sitr++) {
+ fs::ifstream fin(*sitr);
+ while(!fin.eof()) {
+ fin.getline(tmp, 1024);
+ std::string t(tmp);
+ // ignore empty lines or lines of just comments
+ if((t.size() > 0) && (t[0] != '#')) {
+ // remove any comments in the line
+ size_t hash = t.find("#");
+
+ // Use hash marks at the end of each segment as a delimiter
+ d_configs += t.substr(0, hash) + '#';
+ }
+ }
+ fin.close();
+ }
+
+ // Remove all whitespace
+ d_configs.erase(std::remove_if(d_configs.begin(), d_configs.end(), ::isspace), d_configs.end());
+}
+
bool
-gr_prefs::has_section(const std::string section)
+gr_prefs::has_section(const std::string &section)
{
- return false;
+ size_t t = d_configs.find("[" + section + "]#");
+ return t != std::string::npos;
}
bool
-gr_prefs::has_option(const std::string section, const std::string option)
+gr_prefs::has_option(const std::string &section, const std::string &option)
{
- return false;
+ if(has_section(section)) {
+ size_t sec = d_configs.find("[" + section + "]#");
+ size_t opt = d_configs.find("#" + option + "=", sec);
+ return opt != std::string::npos;
+ }
+ else {
+ return false;
+ }
}
const std::string
-gr_prefs::get_string(const std::string section, const std::string option, const std::string default_val)
+gr_prefs::get_string(const std::string &section, const std::string &option,
+ const std::string &default_val)
{
- return default_val;
+ std::stringstream envname;
+ std::string secname=section, optname=option;
+
+ std::transform(section.begin(), section.end(), secname.begin(), ::toupper);
+ std::transform(option.begin(), option.end(), optname.begin(), ::toupper);
+ envname << "GR_CONF_" << secname << "_" << optname;
+
+ char *v = getenv(envname.str().c_str());
+ if(v) {
+ return std::string(v);
+ }
+
+ if(has_option(section, option)) {
+ std::string optname = "#" + option + "=";
+ size_t sec = d_configs.find("[" + section + "]#");
+ size_t opt = d_configs.find(optname, sec);
+
+ size_t start = opt + optname.size();
+ size_t end = d_configs.find("#", start);
+ size_t len = end - start;
+
+ return d_configs.substr(start, len);
+ }
+ else {
+ return default_val;
+ }
}
bool
-gr_prefs::get_bool(const std::string section, const std::string option, bool default_val)
+gr_prefs::get_bool(const std::string &section, const std::string &option, bool default_val)
{
- return default_val;
+ if(has_option(section, option)) {
+ std::string str = get_string(section, option, "");
+ if(str == "") {
+ return default_val;
+ }
+ std::transform(str.begin(), str.end(), str.begin(), ::tolower);
+ if((str == "true") || (str == "on") || (str == "1"))
+ return true;
+ else if((str == "false") || (str == "off") || (str == "0"))
+ return false;
+ else
+ return default_val;
+ }
+ else {
+ return default_val;
+ }
}
long
-gr_prefs::get_long(const std::string section, const std::string option, long default_val)
+gr_prefs::get_long(const std::string &section, const std::string &option, long default_val)
{
- return default_val;
+ if(has_option(section, option)) {
+ std::string str = get_string(section, option, "");
+ if(str == "") {
+ return default_val;
+ }
+ std::stringstream sstr(str);
+ long n;
+ sstr >> n;
+ return n;
+ }
+ else {
+ return default_val;
+ }
}
double
-gr_prefs::get_double(const std::string section, const std::string option, double default_val)
+gr_prefs::get_double(const std::string &section, const std::string &option, double default_val)
{
- return default_val;
+ if(has_option(section, option)) {
+ std::string str = get_string(section, option, "");
+ if(str == "") {
+ return default_val;
+ }
+ std::stringstream sstr(str);
+ double n;
+ sstr >> n;
+ return n;
+ }
+ else {
+ return default_val;
+ }
}
diff --git a/gnuradio-core/src/lib/general/gr_prefs.h b/gnuradio-core/src/lib/general/gr_prefs.h
index b1c354bd3..dc2745d16 100644
--- a/gnuradio-core/src/lib/general/gr_prefs.h
+++ b/gnuradio-core/src/lib/general/gr_prefs.h
@@ -24,6 +24,7 @@
#include <gr_core_api.h>
#include <string>
+#include <gruel/thread.h>
/*!
* \brief Base class for representing user preferences a la windows INI files.
@@ -39,45 +40,54 @@ public:
static gr_prefs *singleton();
static void set_singleton(gr_prefs *p);
+ gr_prefs();
virtual ~gr_prefs();
/*!
* \brief Does \p section exist?
*/
- virtual bool has_section(const std::string section);
+ virtual bool has_section(const std::string &section);
/*!
* \brief Does \p option exist?
*/
- virtual bool has_option(const std::string section, const std::string option);
+ virtual bool has_option(const std::string &section, const std::string &option);
/*!
* \brief If option exists return associated value; else default_val.
*/
- virtual const std::string get_string(const std::string section,
- const std::string option,
- const std::string default_val);
+ virtual const std::string get_string(const std::string &section,
+ const std::string &option,
+ const std::string &default_val);
/*!
* \brief If option exists and value can be converted to bool, return it; else default_val.
*/
- virtual bool get_bool(const std::string section,
- const std::string option,
+ virtual bool get_bool(const std::string &section,
+ const std::string &option,
bool default_val);
/*!
* \brief If option exists and value can be converted to long, return it; else default_val.
*/
- virtual long get_long(const std::string section,
- const std::string option,
+ virtual long get_long(const std::string &section,
+ const std::string &option,
long default_val);
/*!
* \brief If option exists and value can be converted to double, return it; else default_val.
*/
- virtual double get_double(const std::string section,
- const std::string option,
+ virtual double get_double(const std::string &section,
+ const std::string &option,
double default_val);
+
+ protected:
+ virtual std::vector<std::string> _sys_prefs_filenames();
+ virtual void _read_files();
+
+ private:
+ gruel::mutex d_mutex;
+ std::string d_configs;
};
diff --git a/gnuradio-core/src/lib/general/gr_prefs.i b/gnuradio-core/src/lib/general/gr_prefs.i
index f44dcc944..b21d47f3b 100644
--- a/gnuradio-core/src/lib/general/gr_prefs.i
+++ b/gnuradio-core/src/lib/general/gr_prefs.i
@@ -20,9 +20,6 @@
* Boston, MA 02110-1301, USA.
*/
-// Generate SWIG directors for gr_prefs.
-%feature("director") gr_prefs;
-
class gr_prefs
{
public:
@@ -34,39 +31,39 @@ public:
/*!
* \brief Does \p section exist?
*/
- virtual bool has_section(const std::string section);
+ virtual bool has_section(const std::string &section);
/*!
* \brief Does \p option exist?
*/
- virtual bool has_option(const std::string section, const std::string option);
+ virtual bool has_option(const std::string &section, const std::string &option);
/*!
* \brief If option exists return associated value; else default_val.
*/
- virtual const std::string get_string(const std::string section,
- const std::string option,
- const std::string default_val);
+ virtual const std::string get_string(const std::string &section,
+ const std::string &option,
+ const std::string &default_val);
/*!
* \brief If option exists and value can be converted to bool, return it; else default_val.
*/
- virtual bool get_bool(const std::string section,
- const std::string option,
+ virtual bool get_bool(const std::string &section,
+ const std::string &option,
bool default_val);
/*!
* \brief If option exists and value can be converted to long, return it; else default_val.
*/
- virtual long get_long(const std::string section,
- const std::string option,
+ virtual long get_long(const std::string &section,
+ const std::string &option,
long default_val);
/*!
* \brief If option exists and value can be converted to double, return it; else default_val.
*/
- virtual double get_double(const std::string section,
- const std::string option,
+ virtual double get_double(const std::string &section,
+ const std::string &option,
double default_val);
};
diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.cc b/gnuradio-core/src/lib/general/gr_random_pdu.cc
new file mode 100644
index 000000000..6d8c13614
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_random_pdu.cc
@@ -0,0 +1,84 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_random_pdu.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <string.h>
+#include <iostream>
+#include <vector>
+
+// public constructor that returns a shared_ptr
+
+gr_random_pdu_sptr
+gr_make_random_pdu (int items_min, int items_max)
+{
+ return gnuradio::get_initial_sptr(new gr_random_pdu(items_min, items_max));
+}
+
+gr_random_pdu::gr_random_pdu (int items_min, int items_max)
+ : gr_block("random_pdu",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(0, 0, 0)),
+ urange(items_min, items_max),
+ brange(0, 255),
+ rvar(rng, urange),
+ bvar(rng, brange)
+{
+ message_port_register_out(pmt::mp("pdus"));
+ message_port_register_in(pmt::mp("generate"));
+ set_msg_handler(pmt::mp("generate"), boost::bind(&gr_random_pdu::generate_pdu, this, _1));
+}
+
+bool gr_random_pdu::start(){
+ output_random();
+ return true;
+}
+
+void gr_random_pdu::output_random(){
+
+ // pick a random vector length
+ int len = rvar();
+
+ // fill it with random bytes
+ std::vector<unsigned char> vec;
+ for(int i=0; i<len; i++){
+ vec.push_back((unsigned char) bvar());
+ }
+
+ // send the vector
+ pmt::pmt_t vecpmt( pmt::pmt_make_blob( &vec[0], len ) );
+ pmt::pmt_t pdu( pmt::pmt_cons( pmt::PMT_NIL, vecpmt ) );
+ message_port_pub( pmt::mp("pdus"), pdu );
+
+ std::cout << "sending new random vector of length " << len << "\n";
+}
+
diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.h b/gnuradio-core/src/lib/general/gr_random_pdu.h
new file mode 100644
index 000000000..e6457d21b
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_random_pdu.h
@@ -0,0 +1,64 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_RANDOM_PDU_H
+#define INCLUDED_GR_RANDOM_PDU_H
+
+#include <gr_core_api.h>
+#include <gr_block.h>
+#include <gr_message.h>
+#include <gr_msg_queue.h>
+
+#include <boost/random.hpp>
+#include <boost/generator_iterator.hpp>
+
+class gr_random_pdu;
+typedef boost::shared_ptr<gr_random_pdu> gr_random_pdu_sptr;
+
+GR_CORE_API gr_random_pdu_sptr gr_make_random_pdu (int mintime, int maxtime);
+
+/*!
+ * \brief Send message at defined interval
+ * \ingroup msg_blk
+ */
+class GR_CORE_API gr_random_pdu : public gr_block
+{
+ private:
+ friend GR_CORE_API gr_random_pdu_sptr
+ gr_make_random_pdu(int mintime, int maxtime);
+
+ void output_random();
+
+ boost::mt19937 rng;
+ boost::uniform_int<> urange;
+ boost::uniform_int<> brange;
+ boost::variate_generator< boost::mt19937, boost::uniform_int<> > rvar; // pdu length
+ boost::variate_generator< boost::mt19937, boost::uniform_int<> > bvar; // pdu contents
+
+ public:
+ gr_random_pdu (int, int);
+ bool start();
+ void generate_pdu(pmt::pmt_t msg){ output_random(); }
+ void generate_pdu(){ output_random(); }
+};
+
+#endif /* INCLUDED_GR_RANDOM_PDU_H */
diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.i b/gnuradio-core/src/lib/general/gr_random_pdu.i
new file mode 100644
index 000000000..045a33060
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_random_pdu.i
@@ -0,0 +1,30 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,random_pdu);
+
+%{
+#include <gr_random_pdu.h>
+%}
+
+%include "gr_random_pdu.h"
+