summaryrefslogtreecommitdiff
path: root/gnuradio-runtime
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime')
-rw-r--r--gnuradio-runtime/CMakeLists.txt32
-rw-r--r--gnuradio-runtime/include/gnuradio/basic_block.h31
-rw-r--r--gnuradio-runtime/include/gnuradio/block_registry.h1
-rw-r--r--gnuradio-runtime/include/gnuradio/logger.h.in4
-rw-r--r--gnuradio-runtime/include/gnuradio/prefs.h1
-rw-r--r--gnuradio-runtime/include/pmt/pmt.h3
-rw-r--r--gnuradio-runtime/include/pmt/pmt_sugar.h10
-rw-r--r--gnuradio-runtime/lib/CMakeLists.txt16
-rw-r--r--gnuradio-runtime/lib/basic_block.cc11
-rw-r--r--gnuradio-runtime/lib/block.cc2
-rw-r--r--gnuradio-runtime/lib/block_registry.cc20
-rw-r--r--gnuradio-runtime/lib/flowgraph.cc8
-rw-r--r--gnuradio-runtime/lib/pmt/CMakeLists.txt15
-rwxr-xr-xgnuradio-runtime/lib/pmt/generate_unv.py1
-rw-r--r--gnuradio-runtime/lib/pmt/pmt.cc7
-rw-r--r--gnuradio-runtime/lib/pmt/pmt_int.h1
-rw-r--r--gnuradio-runtime/lib/pmt/pmt_io.cc13
-rw-r--r--gnuradio-runtime/lib/pmt/unv_template.cc.t8
-rw-r--r--gnuradio-runtime/lib/pmt/unv_template.h.t1
-rw-r--r--gnuradio-runtime/lib/prefs.cc16
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt1
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/__init__.py8
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/packet_utils.py137
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/prefs.py127
-rw-r--r--gnuradio-runtime/python/pmt/__init__.py5
-rw-r--r--gnuradio-runtime/python/pmt/pmt_to_python.py16
-rw-r--r--gnuradio-runtime/swig/pmt_swig.i4
-rw-r--r--gnuradio-runtime/swig/prefs.i2
28 files changed, 326 insertions, 175 deletions
diff --git a/gnuradio-runtime/CMakeLists.txt b/gnuradio-runtime/CMakeLists.txt
index d5a04e9f57..75410abbb0 100644
--- a/gnuradio-runtime/CMakeLists.txt
+++ b/gnuradio-runtime/CMakeLists.txt
@@ -60,6 +60,13 @@ GR_SET_GLOBAL(GNURADIO_RUNTIME_PYTHONPATH ${GNURADIO_RUNTIME_PYTHONPATH})
# Register controlport component
########################################################################
+if(ENABLE_STATIC_LIBS)
+ set(NOT_STATIC_LIBS False)
+ message(STATUS "ControlPort is incompatible with static library builds. Disabling.")
+else(ENABLE_STATIC_LIBS)
+ set(NOT_STATIC_LIBS True)
+endif(ENABLE_STATIC_LIBS)
+
FIND_PACKAGE(ICE-3.5) # check for ICE 3.5
if(NOT ICE_FOUND)
message(STATUS "ICE 3.5 not found. Looking for 3.4")
@@ -68,21 +75,22 @@ endif(NOT ICE_FOUND)
FIND_PACKAGE(SWIG)
if(SWIG_FOUND)
- set(SWIG_VERSION_CHECK FALSE)
- if("${SWIG_VERSION}" VERSION_GREATER "2.0.0")
- set(SWIG_VERSION_CHECK TRUE)
- else("${SWIG_VERSION}" VERSION_GREATER "2.0.0")
- message(STATUS "")
- message(STATUS "Ctrlport requires SWIG version >= 2.0")
- endif()
+ set(SWIG_VERSION_CHECK FALSE)
+ if("${SWIG_VERSION}" VERSION_GREATER "2.0.0")
+ set(SWIG_VERSION_CHECK TRUE)
+ else("${SWIG_VERSION}" VERSION_GREATER "2.0.0")
+ message(STATUS "")
+ message(STATUS "Ctrlport requires SWIG version >= 2.0")
+ endif()
endif(SWIG_FOUND)
GR_REGISTER_COMPONENT("gr-ctrlport" ENABLE_GR_CTRLPORT
- Boost_FOUND
- SWIG_FOUND
- SWIG_VERSION_CHECK
- ICE_FOUND
- ENABLE_GNURADIO_RUNTIME
+ Boost_FOUND
+ SWIG_FOUND
+ SWIG_VERSION_CHECK
+ ICE_FOUND
+ ENABLE_GNURADIO_RUNTIME
+ NOT_STATIC_LIBS
)
########################################################################
diff --git a/gnuradio-runtime/include/gnuradio/basic_block.h b/gnuradio-runtime/include/gnuradio/basic_block.h
index 69775865ee..b413274ded 100644
--- a/gnuradio-runtime/include/gnuradio/basic_block.h
+++ b/gnuradio-runtime/include/gnuradio/basic_block.h
@@ -144,14 +144,41 @@ namespace gr {
virtual ~basic_block();
long unique_id() const { return d_unique_id; }
long symbolic_id() const { return d_symbolic_id; }
+
+ /*! The name of the block */
std::string name() const { return d_name; }
+
+ /*!
+ * The sybolic name of the block, which is used in the
+ * block_registry. The name is assigned by the block's constructor
+ * and never changes during the life of the block.
+ */
std::string symbol_name() const { return d_symbol_name; }
+
gr::io_signature::sptr input_signature() const { return d_input_signature; }
gr::io_signature::sptr output_signature() const { return d_output_signature; }
basic_block_sptr to_basic_block(); // Needed for Python type coercion
+
+ /*!
+ * True if the block has an alias (see set_block_alias).
+ */
bool alias_set() { return !d_symbol_alias.empty(); }
+
+ /*!
+ * Returns the block's alias as a string.
+ */
std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); }
+
+ /*!
+ * Returns the block's alias as PMT.
+ */
pmt::pmt_t alias_pmt(){ return pmt::intern(alias()); }
+
+ /*!
+ * Set's a new alias for the block; also adds an entry into the
+ * block_registry to get the block using either the alias or the
+ * original symbol name.
+ */
void set_block_alias(std::string name);
// ** Message passing interface **
@@ -248,6 +275,10 @@ namespace gr {
}
return false;
}
+
+ const msg_queue_map_t& get_msg_map(void) const {
+ return msg_queue;
+ }
#ifdef GR_CTRLPORT
/*!
diff --git a/gnuradio-runtime/include/gnuradio/block_registry.h b/gnuradio-runtime/include/gnuradio/block_registry.h
index 31a4eab51b..86e5528dd1 100644
--- a/gnuradio-runtime/include/gnuradio/block_registry.h
+++ b/gnuradio-runtime/include/gnuradio/block_registry.h
@@ -44,6 +44,7 @@ namespace gr {
std::string register_symbolic_name(basic_block* block);
void register_symbolic_name(basic_block* block, std::string name);
+ void update_symbolic_name(basic_block* block, std::string name);
basic_block_sptr block_lookup(pmt::pmt_t symbol);
diff --git a/gnuradio-runtime/include/gnuradio/logger.h.in b/gnuradio-runtime/include/gnuradio/logger.h.in
index 2ba0b62851..8e8cd2fb1e 100644
--- a/gnuradio-runtime/include/gnuradio/logger.h.in
+++ b/gnuradio-runtime/include/gnuradio/logger.h.in
@@ -330,7 +330,7 @@ namespace gr {
* This is a singleton that cna launch a thread to wathc a config file for changes
* \ingroup logging
*/
- class logger_config
+ class GR_RUNTIME_API logger_config
{
private:
/*! \brief filename of logger config file */
@@ -710,7 +710,7 @@ namespace gr {
* \ingroup logging
*
*/
- class logger
+ class GR_RUNTIME_API logger
{
private:
/*! \brief logger pointer to logger associated wiith this wrapper class */
diff --git a/gnuradio-runtime/include/gnuradio/prefs.h b/gnuradio-runtime/include/gnuradio/prefs.h
index b675c83491..a9a28586ab 100644
--- a/gnuradio-runtime/include/gnuradio/prefs.h
+++ b/gnuradio-runtime/include/gnuradio/prefs.h
@@ -46,7 +46,6 @@ namespace gr {
{
public:
static prefs *singleton();
- static void set_singleton(prefs *p);
prefs();
virtual ~prefs();
diff --git a/gnuradio-runtime/include/pmt/pmt.h b/gnuradio-runtime/include/pmt/pmt.h
index 5929975a29..3e17571b23 100644
--- a/gnuradio-runtime/include/pmt/pmt.h
+++ b/gnuradio-runtime/include/pmt/pmt.h
@@ -249,7 +249,8 @@ PMT_API std::complex<double> to_complex(pmt_t z);
* ------------------------------------------------------------------------
*/
-extern PMT_API const pmt_t PMT_NIL; //< the empty list
+#define PMT_NIL get_PMT_NIL()
+PMT_API pmt_t get_PMT_NIL();
//! Return true if \p x is the empty list, otherwise return false.
PMT_API bool is_null(const pmt_t& x);
diff --git a/gnuradio-runtime/include/pmt/pmt_sugar.h b/gnuradio-runtime/include/pmt/pmt_sugar.h
index 870b81902e..424f85cb01 100644
--- a/gnuradio-runtime/include/pmt/pmt_sugar.h
+++ b/gnuradio-runtime/include/pmt/pmt_sugar.h
@@ -51,10 +51,16 @@ namespace pmt {
return from_long(x);
}
- //! Make pmt long
+ //! Make pmt uint64
+ static inline pmt_t
+ mp(long unsigned x){
+ return from_uint64(x);
+ }
+
+ //! Make pmt uint64
static inline pmt_t
mp(long long unsigned x){
- return from_long(x);
+ return from_uint64(x);
}
//! Make pmt long
diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt
index cd7f0c7549..a3f0d4cb55 100644
--- a/gnuradio-runtime/lib/CMakeLists.txt
+++ b/gnuradio-runtime/lib/CMakeLists.txt
@@ -198,6 +198,21 @@ add_dependencies(gnuradio-runtime
pmt_generated runtime_generated_includes
)
+if(ENABLE_STATIC_LIBS)
+ add_library(gnuradio-runtime_static STATIC ${gnuradio_runtime_sources})
+
+ add_dependencies(gnuradio-runtime_static gnuradio_runtime)
+
+ if(NOT WIN32)
+ set_target_properties(gnuradio-runtime_static
+ PROPERTIES OUTPUT_NAME gnuradio-runtime)
+ endif(NOT WIN32)
+
+ install(TARGETS gnuradio-runtime_static
+ ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "runtime_devel" # .lib file
+ )
+endif(ENABLE_STATIC_LIBS)
+
########################################################################
# Setup tests
########################################################################
@@ -239,4 +254,3 @@ target_link_libraries(gr_runtime_test test-gnuradio-runtime)
GR_ADD_TEST(gr-runtime-test gr_runtime_test)
endif(ENABLE_TESTING)
-
diff --git a/gnuradio-runtime/lib/basic_block.cc b/gnuradio-runtime/lib/basic_block.cc
index 3cd23c8996..686c1d6e65 100644
--- a/gnuradio-runtime/lib/basic_block.cc
+++ b/gnuradio-runtime/lib/basic_block.cc
@@ -72,7 +72,16 @@ namespace gr {
void
basic_block::set_block_alias(std::string name)
{
- global_block_registry.register_symbolic_name(this, name);
+ // Only keep one alias'd name around for each block. If we don't
+ // have an alias, add it; if we do, update the entry in the
+ // registry.
+ if(alias_set())
+ global_block_registry.update_symbolic_name(this, name);
+ else
+ global_block_registry.register_symbolic_name(this, name);
+
+ // set the block's alias
+ d_symbol_alias = name;
}
// ** Message passing interface **
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index 9e4fcf5cca..6309bca9b1 100644
--- a/gnuradio-runtime/lib/block.cc
+++ b/gnuradio-runtime/lib/block.cc
@@ -111,7 +111,7 @@ namespace gr {
block::~block()
{
- global_block_registry.unregister_primitive(alias());
+ global_block_registry.unregister_primitive(symbol_name());
}
unsigned
diff --git a/gnuradio-runtime/lib/block_registry.cc b/gnuradio-runtime/lib/block_registry.cc
index c4dc7647d6..5241ef9922 100644
--- a/gnuradio-runtime/lib/block_registry.cc
+++ b/gnuradio-runtime/lib/block_registry.cc
@@ -90,6 +90,26 @@ namespace gr {
d_ref_map = pmt::dict_add(d_ref_map, pmt::intern(name), pmt::make_any(block));
}
+ void
+ block_registry::update_symbolic_name(basic_block* block, std::string name)
+ {
+ gr::thread::scoped_lock guard(d_mutex);
+
+ if(pmt::dict_has_key(d_ref_map, pmt::intern(name))) {
+ throw std::runtime_error("symbol already exists, can not re-use!");
+ }
+
+ // If we don't already have an alias, don't try and delete it.
+ if(block->alias_set()) {
+ // And make sure that the registry has the alias key.
+ // We test both in case the block's and registry ever get out of sync.
+ if(pmt::dict_has_key(d_ref_map, block->alias_pmt())) {
+ d_ref_map = pmt::dict_delete(d_ref_map, block->alias_pmt());
+ }
+ }
+ d_ref_map = pmt::dict_add(d_ref_map, pmt::intern(name), pmt::make_any(block));
+ }
+
basic_block_sptr
block_registry::block_lookup(pmt::pmt_t symbol)
{
diff --git a/gnuradio-runtime/lib/flowgraph.cc b/gnuradio-runtime/lib/flowgraph.cc
index 3d8dfea65a..abe51f741d 100644
--- a/gnuradio-runtime/lib/flowgraph.cc
+++ b/gnuradio-runtime/lib/flowgraph.cc
@@ -155,8 +155,14 @@ namespace gr {
if(FLOWGRAPH_DEBUG)
std::cout << "check_valid_port( " << e.block() << ", " << e.port() << ")\n";
- if(!e.block()->has_msg_port(e.port()))
+ if(!e.block()->has_msg_port(e.port())) {
+ const gr::basic_block::msg_queue_map_t& msg_map = e.block()->get_msg_map();
+ std::cout << "Could not find port: " << e.port() << " in:" << std::endl;
+ for (gr::basic_block::msg_queue_map_t::const_iterator it = msg_map.begin(); it != msg_map.end(); ++it)
+ std::cout << it->first << std::endl;
+ std::cout << std::endl;
throw std::invalid_argument("invalid msg port in connect() or disconnect()");
+ }
}
void
diff --git a/gnuradio-runtime/lib/pmt/CMakeLists.txt b/gnuradio-runtime/lib/pmt/CMakeLists.txt
index dc4fe1be46..32c0e57a6a 100644
--- a/gnuradio-runtime/lib/pmt/CMakeLists.txt
+++ b/gnuradio-runtime/lib/pmt/CMakeLists.txt
@@ -114,6 +114,21 @@ add_dependencies(gnuradio-pmt
pmt_generated
)
+if(ENABLE_STATIC_LIBS)
+ add_library(gnuradio-pmt_static STATIC ${pmt_sources})
+
+ add_dependencies(gnuradio-pmt_static pmt_generated)
+
+ if(NOT WIN32)
+ set_target_properties(gnuradio-pmt_static
+ PROPERTIES OUTPUT_NAME gnuradio-pmt)
+ endif(NOT WIN32)
+
+ install(TARGETS gnuradio-pmt_static
+ ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "runtime_devel" # .lib file
+ )
+endif(ENABLE_STATIC_LIBS)
+
########################################################################
# Setup tests
########################################################################
diff --git a/gnuradio-runtime/lib/pmt/generate_unv.py b/gnuradio-runtime/lib/pmt/generate_unv.py
index 7562df46f8..6218099fc1 100755
--- a/gnuradio-runtime/lib/pmt/generate_unv.py
+++ b/gnuradio-runtime/lib/pmt/generate_unv.py
@@ -76,6 +76,7 @@ includes = """
#endif
#include <vector>
#include <pmt/pmt.h>
+#include <boost/lexical_cast.hpp>
#include "pmt_int.h"
"""
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index e3b93255bc..082b98a80d 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -160,9 +160,14 @@ _any(pmt_t x)
const pmt_t PMT_T = pmt_t(new pmt_bool()); // singleton
const pmt_t PMT_F = pmt_t(new pmt_bool()); // singleton
-const pmt_t PMT_NIL = pmt_t(new pmt_null()); // singleton
const pmt_t PMT_EOF = cons(PMT_NIL, PMT_NIL); // singleton
+pmt_t get_PMT_NIL()
+{
+ static pmt_t NIL = pmt_t(new pmt_null());
+ return NIL;
+}
+
////////////////////////////////////////////////////////////////////////////
// Booleans
////////////////////////////////////////////////////////////////////////////
diff --git a/gnuradio-runtime/lib/pmt/pmt_int.h b/gnuradio-runtime/lib/pmt/pmt_int.h
index ca90c5a475..49bde52063 100644
--- a/gnuradio-runtime/lib/pmt/pmt_int.h
+++ b/gnuradio-runtime/lib/pmt/pmt_int.h
@@ -239,6 +239,7 @@ public:
virtual void *uniform_writable_elements(size_t &len) = 0;
virtual size_t length() const = 0;
virtual size_t itemsize() const = 0;
+ virtual const std::string string_ref(size_t k) const { return std::string("not implemented"); }
};
#include "pmt_unv_int.h"
diff --git a/gnuradio-runtime/lib/pmt/pmt_io.cc b/gnuradio-runtime/lib/pmt/pmt_io.cc
index 17bdee408f..e63bae4994 100644
--- a/gnuradio-runtime/lib/pmt/pmt_io.cc
+++ b/gnuradio-runtime/lib/pmt/pmt_io.cc
@@ -110,9 +110,16 @@ write(pmt_t obj, std::ostream &port)
port << "#<dict>";
}
else if (is_uniform_vector(obj)){
- // FIXME
- // port << "#<uniform-vector " << obj << ">";
- port << "#<uniform-vector>";
+ port << "#[";
+ size_t len = length(obj);
+ if (len)
+ {
+ pmt_uniform_vector *uv = static_cast<pmt_uniform_vector*>(obj.get());
+ port << uv->string_ref(0);
+ for (size_t i = 1; i < len; i++)
+ port << " " << uv->string_ref(i);
+ }
+ port << "]";
}
else {
error:
diff --git a/gnuradio-runtime/lib/pmt/unv_template.cc.t b/gnuradio-runtime/lib/pmt/unv_template.cc.t
index 0342367f7e..c8020e7de2 100644
--- a/gnuradio-runtime/lib/pmt/unv_template.cc.t
+++ b/gnuradio-runtime/lib/pmt/unv_template.cc.t
@@ -90,7 +90,7 @@ init_@TAG@vector(size_t k, const @TYPE@ *data)
pmt_t
init_@TAG@vector(size_t k, const std::vector< @TYPE@ > &data)
{
-
+
return pmt_t(new pmt_@TAG@vector(k, &data[0]));
}
@@ -138,4 +138,10 @@ const std::vector< @TYPE@ >
return _@TAG@vector(vector)->writable_elements(len);
}
+const std::string
+pmt_@TAG@vector::string_ref(size_t k) const
+{
+ return boost::lexical_cast< std::string, @TYPE@ > (ref(k));
+}
+
} /* namespace pmt */
diff --git a/gnuradio-runtime/lib/pmt/unv_template.h.t b/gnuradio-runtime/lib/pmt/unv_template.h.t
index 93ca684463..ab5c163570 100644
--- a/gnuradio-runtime/lib/pmt/unv_template.h.t
+++ b/gnuradio-runtime/lib/pmt/unv_template.h.t
@@ -21,4 +21,5 @@ public:
@TYPE@ *writable_elements(size_t &len);
const void *uniform_elements(size_t &len);
void *uniform_writable_elements(size_t &len);
+ virtual const std::string string_ref(size_t k) const;
};
diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc
index d03c6777eb..b7fcaada9d 100644
--- a/gnuradio-runtime/lib/prefs.cc
+++ b/gnuradio-runtime/lib/prefs.cc
@@ -36,22 +36,12 @@ namespace fs = boost::filesystem;
namespace gr {
- /*
- * Stub implementations
- */
- static prefs s_default_singleton;
- static prefs *s_singleton = &s_default_singleton;
-
prefs *
prefs::singleton()
{
- return s_singleton;
- }
-
- void
- prefs::set_singleton(prefs *p)
- {
- s_singleton = p;
+ static prefs instance; // Guaranteed to be destroyed.
+ // Instantiated on first use.
+ return &instance;
}
prefs::prefs()
diff --git a/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt b/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt
index 9d6f4dd718..ddad2c448a 100644
--- a/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt
+++ b/gnuradio-runtime/python/gnuradio/gr/CMakeLists.txt
@@ -23,6 +23,7 @@ include(GrPython)
GR_PYTHON_INSTALL(FILES
__init__.py
tag_utils.py
+ packet_utils.py
gateway.py
gr_threading.py
gr_threading_23.py
diff --git a/gnuradio-runtime/python/gnuradio/gr/__init__.py b/gnuradio-runtime/python/gnuradio/gr/__init__.py
index 94a5c9ec2b..4fc55c68b2 100644
--- a/gnuradio-runtime/python/gnuradio/gr/__init__.py
+++ b/gnuradio-runtime/python/gnuradio/gr/__init__.py
@@ -48,3 +48,11 @@ from gateway import basic_block, sync_block, decim_block, interp_block
# Force the preference database to be initialized
prefs = prefs.singleton
+
+log = gr.logger("log")
+log.add_console_appender(prefs().get_string("LOG", "log_level", "off"), 'gr::log %d :%p: %m%n')
+log.set_level(prefs().get_string("LOG", "log_level", "notset"))
+
+log_debug = gr.logger("log_debug")
+log_debug.add_console_appender(prefs().get_string("LOG", "debug_level", "off"), 'gr::debug %d :%p: %m%n')
+log_debug.set_level(prefs().get_string("LOG", "debug_level", "notset"))
diff --git a/gnuradio-runtime/python/gnuradio/gr/packet_utils.py b/gnuradio-runtime/python/gnuradio/gr/packet_utils.py
new file mode 100644
index 0000000000..7ae42e88e3
--- /dev/null
+++ b/gnuradio-runtime/python/gnuradio/gr/packet_utils.py
@@ -0,0 +1,137 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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.
+#
+
+from gnuradio import gr
+import pmt
+
+def make_lengthtags(lengths, offsets, tagname='length', vlen=1):
+ tags = []
+ assert(len(offsets) == len(lengths))
+ for offset, length in zip(offsets, lengths):
+ tag = gr.tag_t()
+ tag.offset = offset/vlen
+ tag.key = pmt.string_to_symbol(tagname)
+ tag.value = pmt.from_long(length/vlen)
+ tags.append(tag)
+ return tags
+
+def string_to_vector(string):
+ v = []
+ for s in string:
+ v.append(ord(s))
+ return v
+
+def strings_to_vectors(strings, tsb_tag_key):
+ vs = [string_to_vector(string) for string in strings]
+ return packets_to_vectors(vs, tsb_tag_key)
+
+def vector_to_string(v):
+ s = []
+ for d in v:
+ s.append(chr(d))
+ return ''.join(s)
+
+def vectors_to_strings(data, tags, tsb_tag_key):
+ packets = vectors_to_packets(data, tags, tsb_tag_key)
+ return [vector_to_string(packet) for packet in packets]
+
+def count_bursts(data, tags, tsb_tag_key, vlen=1):
+ lengthtags = [t for t in tags
+ if pmt.symbol_to_string(t.key) == tsb_tag_key]
+ lengths = {}
+ for tag in lengthtags:
+ if tag.offset in lengths:
+ raise ValueError(
+ "More than one tags with key {0} with the same offset={1}."
+ .format(tsb_tag_key, tag.offset))
+ lengths[tag.offset] = pmt.to_long(tag.value)*vlen
+ in_burst = False
+ in_packet = False
+ packet_length = None
+ packet_pos = None
+ burst_count = 0
+ for pos in range(len(data)):
+ if pos in lengths:
+ if in_packet:
+ print("Got tag at pos {0} current packet_pos is {1}".format(pos, packet_pos))
+ raise StandardError("Received packet tag while in packet.")
+ packet_pos = -1
+ packet_length = lengths[pos]
+ in_packet = True
+ if not in_burst:
+ burst_count += 1
+ in_burst = True
+ elif not in_packet:
+ in_burst = False
+ if in_packet:
+ packet_pos += 1
+ if packet_pos == packet_length-1:
+ in_packet = False
+ packet_pos = None
+ return burst_count
+
+def vectors_to_packets(data, tags, tsb_tag_key, vlen=1):
+ lengthtags = [t for t in tags
+ if pmt.symbol_to_string(t.key) == tsb_tag_key]
+ lengths = {}
+ for tag in lengthtags:
+ if tag.offset in lengths:
+ raise ValueError(
+ "More than one tags with key {0} with the same offset={1}."
+ .format(tsb_tag_key, tag.offset))
+ lengths[tag.offset] = pmt.to_long(tag.value)*vlen
+ if 0 not in lengths:
+ raise ValueError("There is no tag with key {0} and an offset of 0"
+ .format(tsb_tag_key))
+ pos = 0
+ packets = []
+ while pos < len(data):
+ if pos not in lengths:
+ raise ValueError("There is no tag with key {0} and an offset of {1}."
+ "We were expecting one."
+ .format(tsb_tag_key, pos))
+ length = lengths[pos]
+ if length == 0:
+ raise ValueError("Packets cannot have zero length.")
+ if pos+length > len(data):
+ raise ValueError("The final packet is incomplete.")
+ packets.append(data[pos: pos+length])
+ pos += length
+ return packets
+
+def packets_to_vectors(packets, tsb_tag_key, vlen=1):
+ """ Returns a single data vector and a set of tags.
+ If used with blocks.vector_source_X, this set of data
+ and tags will produced a correct tagged stream. """
+ tags = []
+ data = []
+ offset = 0
+ for packet in packets:
+ data.extend(packet)
+ tag = gr.tag_t()
+ tag.offset = offset/vlen
+ tag.key = pmt.string_to_symbol(tsb_tag_key)
+ tag.value = pmt.from_long(len(packet)/vlen)
+ tags.append(tag)
+ offset = offset + len(packet)
+ return data, tags
+
diff --git a/gnuradio-runtime/python/gnuradio/gr/prefs.py b/gnuradio-runtime/python/gnuradio/gr/prefs.py
deleted file mode 100644
index 17f5bfb54c..0000000000
--- a/gnuradio-runtime/python/gnuradio/gr/prefs.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# Copyright 2006,2009 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.
-#
-
-import gnuradio_runtime as gsp
-_prefs_base = gsp.prefs
-
-
-import ConfigParser
-import os
-import os.path
-import sys
-import glob
-
-
-def _user_prefs_filename():
- return os.path.expanduser('~/.gnuradio/config.conf')
-
-def _sys_prefs_dirname():
- return gsp.prefsdir()
-
-def _bool(x):
- """
- Try to coerce obj to a True or False
- """
- if isinstance(x, bool):
- return x
- if isinstance(x, (float, int)):
- return bool(x)
- raise TypeError, x
-
-
-class _prefs(_prefs_base):
- """
- Derive our 'real class' from the stubbed out base class that has support
- for SWIG directors. This allows C++ code to magically and transparently
- invoke the methods in this python class.
- """
- def __init__(self):
- _prefs_base.__init__(self)
- self.cp = ConfigParser.RawConfigParser()
- self.__getattr__ = lambda self, name: getattr(self.cp, name)
-
- def _sys_prefs_filenames(self):
- dir = _sys_prefs_dirname()
- try:
- fnames = glob.glob(os.path.join(dir, '*.conf'))
- except (IOError, OSError):
- return []
- fnames.sort()
- return fnames
-
- def _read_files(self):
- filenames = self._sys_prefs_filenames()
- filenames.append(_user_prefs_filename())
- #print "filenames: ", filenames
- self.cp.read(filenames)
-
- # ----------------------------------------------------------------
- # These methods override the C++ virtual methods of the same name
- # ----------------------------------------------------------------
- def has_section(self, section):
- return self.cp.has_section(section)
-
- def has_option(self, section, option):
- return self.cp.has_option(section, option)
-
- def get_string(self, section, option, default_val):
- try:
- return self.cp.get(section, option)
- except:
- return default_val
-
- def get_bool(self, section, option, default_val):
- try:
- return self.cp.getboolean(section, option)
- except:
- return default_val
-
- def get_long(self, section, option, default_val):
- try:
- return self.cp.getint(section, option)
- except:
- return default_val
-
- def get_double(self, section, option, default_val):
- try:
- return self.cp.getfloat(section, option)
- except:
- return default_val
- # ----------------------------------------------------------------
- # End override of C++ virtual methods
- # ----------------------------------------------------------------
-
-
-_prefs_db = _prefs()
-
-# if GR_DONT_LOAD_PREFS is set, don't load them.
-# (make check uses this to avoid interactions.)
-if os.getenv("GR_DONT_LOAD_PREFS", None) is None:
- _prefs_db._read_files()
-
-
-_prefs_base.set_singleton(_prefs_db) # tell C++ what instance to use
-
-def prefs():
- """
- Return the global preference data base
- """
- return _prefs_db
diff --git a/gnuradio-runtime/python/pmt/__init__.py b/gnuradio-runtime/python/pmt/__init__.py
index 00940e4cc1..1c7db73322 100644
--- a/gnuradio-runtime/python/pmt/__init__.py
+++ b/gnuradio-runtime/python/pmt/__init__.py
@@ -48,6 +48,9 @@ except ImportError:
__path__.append(os.path.join(dirname, "..", "..", "swig"))
from pmt_swig import *
+# due to changes in the PMT_NIL singleton for static builds, we force
+# this into Python here.
+PMT_NIL = get_PMT_NIL()
+
from pmt_to_python import pmt_to_python as to_python
from pmt_to_python import python_to_pmt as to_pmt
-
diff --git a/gnuradio-runtime/python/pmt/pmt_to_python.py b/gnuradio-runtime/python/pmt/pmt_to_python.py
index 3344eba163..e08b7265de 100644
--- a/gnuradio-runtime/python/pmt/pmt_to_python.py
+++ b/gnuradio-runtime/python/pmt/pmt_to_python.py
@@ -21,6 +21,10 @@ try: import pmt_swig as pmt
except: import pmt
import numpy
+# SWIG isn't taking in the #define PMT_NIL;
+# getting the singleton locally.
+PMT_NIL = pmt.get_PMT_NIL()
+
#define missing
def pmt_to_tuple(p):
elems = list()
@@ -41,7 +45,7 @@ def pmt_to_vector(p):
return v
def pmt_from_vector(p):
- v = pmt.make_vector(len(p), pmt.PMT_NIL)
+ v = pmt.make_vector(len(p), PMT_NIL)
for i, elem in enumerate(p):
pmt.vector_set(v, i, python_to_pmt(elem))
return v
@@ -99,7 +103,7 @@ def uvector_to_numpy(uvector):
raise ValueError("unsupported uvector data type for conversion to numpy array %s"%(uvector))
type_mappings = ( #python type, check pmt type, to python, from python
- (None, pmt.is_null, lambda x: None, lambda x: pmt.PMT_NIL),
+ (None, pmt.is_null, lambda x: None, lambda x: PMT_NIL),
(bool, pmt.is_bool, pmt.to_bool, pmt.from_bool),
(str, pmt.is_symbol, pmt.symbol_to_string, pmt.string_to_symbol),
(unicode, lambda x: False, None, lambda x: pmt.string_to_symbol(x.encode('utf-8'))),
@@ -110,12 +114,17 @@ type_mappings = ( #python type, check pmt type, to python, from python
(tuple, pmt.is_tuple, pmt_to_tuple, pmt_from_tuple),
(list, pmt.is_vector, pmt_to_vector, pmt_from_vector),
(dict, pmt.is_dict, pmt_to_dict, pmt_from_dict),
+ (tuple, pmt.is_pair, lambda x: (pmt_to_python(pmt.car(x)), pmt_to_python(pmt.cdr(x))), lambda x: pmt.cons(python_to_pmt(x[0]), python_to_pmt(x[1]))),
(numpy.ndarray, pmt.is_uniform_vector, uvector_to_numpy, numpy_to_uvector),
)
def pmt_to_python(p):
for python_type, pmt_check, to_python, from_python in type_mappings:
- if pmt_check(p): return to_python(p)
+ if pmt_check(p):
+ try:
+ return to_python(p)
+ except:
+ pass
raise ValueError("can't convert %s type to pmt (%s)"%(type(p),p))
def python_to_pmt(p):
@@ -124,4 +133,3 @@ def python_to_pmt(p):
if p == None: return from_python(p)
elif isinstance(p, python_type): return from_python(p)
raise ValueError("can't convert %s type to pmt (%s)"%(type(p),p))
-
diff --git a/gnuradio-runtime/swig/pmt_swig.i b/gnuradio-runtime/swig/pmt_swig.i
index 25178e3ba2..e54b544977 100644
--- a/gnuradio-runtime/swig/pmt_swig.i
+++ b/gnuradio-runtime/swig/pmt_swig.i
@@ -83,9 +83,11 @@ namespace pmt{
extern const pmt_t PMT_T;
extern const pmt_t PMT_F;
- extern const pmt_t PMT_NIL;
extern const pmt_t PMT_EOF;
+ pmt_t get_PMT_NIL();
+ #define PMT_NIL get_PMT_NIL()
+
bool is_bool(pmt_t obj);
bool is_true(pmt_t obj);
bool is_false(pmt_t obj);
diff --git a/gnuradio-runtime/swig/prefs.i b/gnuradio-runtime/swig/prefs.i
index f56c7910ee..ac5fab7adc 100644
--- a/gnuradio-runtime/swig/prefs.i
+++ b/gnuradio-runtime/swig/prefs.i
@@ -24,7 +24,6 @@ class gr::prefs
{
public:
static gr::prefs *singleton();
- static void set_singleton(gr::prefs *p);
virtual ~prefs();
@@ -60,4 +59,3 @@ public:
const std::string &option,
double val);
};
-