diff options
author | Johnathan Corgan | 2011-03-16 08:18:30 -0700 |
---|---|---|
committer | Johnathan Corgan | 2011-03-16 08:18:30 -0700 |
commit | 4cd06fadac972d4cac559c15488bc39823063afe (patch) | |
tree | 6fe57896bc216d8c9e672194f2e4e0e75aedb645 /gruel/src/lib | |
parent | 4ad736e21f45f64fd616bb53f54e45e1c63e7330 (diff) | |
parent | 1d70ed2bd928d52a383e688949cc7f747dd584fa (diff) | |
download | gnuradio-4cd06fadac972d4cac559c15488bc39823063afe.tar.gz gnuradio-4cd06fadac972d4cac559c15488bc39823063afe.tar.bz2 gnuradio-4cd06fadac972d4cac559c15488bc39823063afe.zip |
Merge remote branch 'gnuradio/next'
* gnuradio/next: (806 commits)
gruel: added missing ignores
gruel: fixed swig interface file to dereference pmt_t.
qtgui: fix distcheck error
gruel: fixing structure. Passes make check.
gruel: SWIGing Gruel into Python to access PMTs.
gnuradio-examples: add C++ audio examples using new gr-audio
created gruel/attributes.h to house compiler specific attribute macros
audio: remove obsoleted individual top-level components
gr-audio: added README and default config fix
volk: simplify the get new method for the aligned pool
grc: moved all usrp1 and usrp2 stuff out of grc and into gr-usrp*/grc
grc: swap store the subprocess object rather than the pid when executing
qtgui: removed python directory that was added, never used
uhd: use %ignore to hide warnings and fix errors
Added/updated ignore files.
Fixing gr_filter_design program to import from gnuradio Python package.
audio: high prio for platform specific audio osx
audio: added windows and osx audio source files
audio: added config checks for other audios, added jack and port
audio: make prefs look like old audio, removed old audio.py
...
Diffstat (limited to 'gruel/src/lib')
-rw-r--r-- | gruel/src/lib/Makefile.am | 5 | ||||
-rw-r--r-- | gruel/src/lib/pmt/Makefile.am | 10 | ||||
-rw-r--r-- | gruel/src/lib/pmt/pmt_io.cc | 10 | ||||
-rw-r--r-- | gruel/src/lib/pmt/pmt_serialize.cc | 107 | ||||
-rw-r--r-- | gruel/src/lib/test_gruel.cc | 53 | ||||
-rw-r--r-- | gruel/src/lib/thread.cc | 35 |
6 files changed, 129 insertions, 91 deletions
diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 5c3302f19..f37ab27a1 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008,2009,2010 Free Software Foundation, Inc. +# Copyright 2008,2009,2010,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -45,12 +45,13 @@ MSG_LIB = msg/libmsg.la libgruel_la_SOURCES = \ realtime.cc \ sys_pri.cc \ - thread.cc \ thread_body_wrapper.cc \ thread_group.cc libgruel_la_LIBADD = \ $(BOOST_THREAD_LIB) \ + $(BOOST_SYSTEM_LIB) \ + $(BOOST_FILESYSTEM_LIB) \ $(PMT_LIB) \ $(MSG_LIB) \ -lstdc++ diff --git a/gruel/src/lib/pmt/Makefile.am b/gruel/src/lib/pmt/Makefile.am index d3efc1afa..0c8e12dc3 100644 --- a/gruel/src/lib/pmt/Makefile.am +++ b/gruel/src/lib/pmt/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008,2009,2010 Free Software Foundation, Inc. +# Copyright 2008,2009,2010,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -48,7 +48,7 @@ python_built_sources = $(GENERATED_H) $(GENERATED_CC) PMT_SERIAL_TAGS_H = $(abs_top_builddir)/gruel/src/include/gruel/pmt_serial_tags.h BUILT_SOURCES = $(python_built_sources) $(PMT_SERIAL_TAGS_H) -EXTRA_DIST = $(code_generator) +EXTRA_DIST += $(code_generator) # ---------------------------------------------------------------- @@ -99,7 +99,7 @@ gen_sources_deps = $(core_generator) par_gen_command = PYTHONPATH=$(top_srcdir)/gruel/src/lib/pmt srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_unv.py include $(top_srcdir)/Makefile.par.gen -# Rule to create the build header file using GUILE +# Rule to create the build header file using python # Doesn't need parallel protections because there is a single target -$(PMT_SERIAL_TAGS_H): $(srcdir)/../../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../../scheme/gnuradio/pmt-serial-tags.scm - $(RUN_GUILE) $(srcdir)/../../scheme/gnuradio/gen-serial-tags.scm $(srcdir)/../../scheme/gnuradio/pmt-serial-tags.scm $(PMT_SERIAL_TAGS_H) +$(PMT_SERIAL_TAGS_H): $(top_srcdir)/gruel/src/scheme/gnuradio/gen-serial-tags.py $(top_srcdir)/gruel/src/scheme/gnuradio/pmt-serial-tags.scm + $(PYTHON) $^ $@ diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc index b909c1b64..1214ff588 100644 --- a/gruel/src/lib/pmt/pmt_io.cc +++ b/gruel/src/lib/pmt/pmt_io.cc @@ -26,6 +26,7 @@ #include <gruel/pmt.h> #include "pmt_int.h" #include <sstream> +#include <iostream> namespace pmt { @@ -156,3 +157,12 @@ pmt_deserialize(std::istream &source) } } /* namespace pmt */ + + +void +pmt::pmt_print(pmt_t v) +{ + std::cout << pmt_write_string(v) << std::endl; +} + + diff --git a/gruel/src/lib/pmt/pmt_serialize.cc b/gruel/src/lib/pmt/pmt_serialize.cc index 937423a93..184a31e6b 100644 --- a/gruel/src/lib/pmt/pmt_serialize.cc +++ b/gruel/src/lib/pmt/pmt_serialize.cc @@ -59,6 +59,26 @@ serialize_untagged_u32(unsigned int i, std::streambuf &sb) return sb.sputc((i >> 0) & 0xff) != std::streambuf::traits_type::eof(); } +static bool +serialize_untagged_f64(double i, std::streambuf &sb) +{ + typedef union { + double id; + uint64_t ii; + } iu_t; + iu_t iu; + iu.id = i; + sb.sputc((iu.ii >> 56) & 0xff); + sb.sputc((iu.ii >> 48) & 0xff); + sb.sputc((iu.ii >> 40) & 0xff); + sb.sputc((iu.ii >> 32) & 0xff); + sb.sputc((iu.ii >> 24) & 0xff); + sb.sputc((iu.ii >> 16) & 0xff); + sb.sputc((iu.ii >> 8) & 0xff); + return sb.sputc((iu.ii >> 0) & 0xff) != std::streambuf::traits_type::eof(); +} + + #if 0 // always writes big-endian static bool @@ -163,6 +183,41 @@ deserialize_untagged_u64(uint64_t *ip, std::streambuf &sb) } #endif +static bool +deserialize_untagged_f64(double *ip, std::streambuf &sb) +{ + std::streambuf::traits_type::int_type t; + + typedef union { + double id; + uint64_t ii; + } iu_t; + + iu_t iu; + + t = sb.sbumpc(); + iu.ii = t & 0xff; + + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + t = sb.sbumpc(); + iu.ii = (iu.ii<<8) | (t & 0xff); + + *ip = iu.id; + return t != std::streambuf::traits_type::eof(); +} + + /* * Write portable byte-serial representation of \p obj to \p sb * @@ -172,7 +227,7 @@ bool pmt_serialize(pmt_t obj, std::streambuf &sb) { bool ok = true; - + tail_recursion: if (pmt_is_bool(obj)){ @@ -217,11 +272,21 @@ pmt_serialize(pmt_t obj, std::streambuf &sb) return ok; } - if (pmt_is_real(obj)) - throw pmt_notimplemented("pmt_serialize (real)", obj); + if (pmt_is_real(obj)){ + float i = pmt_to_double(obj); + ok = serialize_untagged_u8(PST_DOUBLE, sb); + ok &= serialize_untagged_f64(i, sb); + return ok; + } + + if (pmt_is_complex(obj)){ + std::complex<double> i = pmt_to_complex(obj); + ok = serialize_untagged_u8(PST_COMPLEX, sb); + ok &= serialize_untagged_f64(i.real(), sb); + ok &= serialize_untagged_f64(i.imag(), sb); + return ok; + } - if (pmt_is_complex(obj)) - throw pmt_notimplemented("pmt_serialize (complex)", obj); } if (pmt_is_vector(obj)) @@ -251,6 +316,7 @@ pmt_deserialize(std::streambuf &sb) uint16_t u16; uint32_t u32; //uint32_t u64; + double f64; static char tmpbuf[1024]; if (!deserialize_untagged_u8(&tag, sb)) @@ -285,7 +351,18 @@ pmt_deserialize(std::streambuf &sb) return parse_pair(sb); case PST_DOUBLE: + if(!deserialize_untagged_f64(&f64, sb)) + goto error; + return pmt_from_double( f64 ); + case PST_COMPLEX: + { + double r,i; + if(!deserialize_untagged_f64(&r, sb) && !deserialize_untagged_f64(&i, sb)) + goto error; + return pmt_make_rectangular( r,i ); + } + case PST_VECTOR: case PST_DICT: case PST_UNIFORM_VECTOR: @@ -302,6 +379,26 @@ pmt_deserialize(std::streambuf &sb) throw pmt_exception("pmt_deserialize: malformed input stream", PMT_F); } + +/* + * provide a simple string accessor to the serialized pmt form + */ +std::string pmt_serialize_str(pmt_t obj){ + std::stringbuf sb; + pmt_serialize(obj, sb); + return sb.str(); +} + + +/* + * provide a simple string accessor to the deserialized pmt form + */ +pmt_t pmt_deserialize_str(std::string s){ + std::stringbuf sb(s); + return pmt_deserialize(sb); +} + + /* * This is a mostly non-recursive implementation that allows us to * deserialize very long lists w/o exhausting the evaluation stack. diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc index 2c9528b0a..7ef3520e6 100644 --- a/gruel/src/lib/test_gruel.cc +++ b/gruel/src/lib/test_gruel.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009,2010 Free Software Foundation, Inc. + * Copyright 2006,2009,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -28,16 +28,19 @@ #include "pmt/qa_pmt.h" -static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize); +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> +namespace fs = boost::filesystem; int main(int argc, char **argv) { - char path[200]; - get_unittest_path ("gruel.xml", path, 200); - + fs::path path = fs::current_path() / ".unittests"; + if (!fs::is_directory(path)) fs::create_directory(path); + path = path / "gruel.xml"; + CppUnit::TextTestRunner runner; - std::ofstream xmlfile(path); + std::ofstream xmlfile(path.string().c_str()); CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); runner.addTest(qa_pmt::suite ()); @@ -47,41 +50,3 @@ main(int argc, char **argv) return was_successful ? 0 : 1; } - - -// NOTE: These are defined in gr_unittest.h for the rest of the project; -// rewriting here since we don't depend on gnuradio-core in gruel - -#ifdef MKDIR_TAKES_ONE_ARG -#define gr_mkdir(pathname, mode) mkdir(pathname) -#else -#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) -#endif - -/* - * Mostly taken from gr_preferences.cc/h - * The simplest thing that could possibly work: - * the key is the filename; the value is the file contents. - */ - -static void -ensure_unittest_path (const char *path) -{ - struct stat statbuf; - if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) - return; - - // blindly try to make it // FIXME make this robust. C++ SUCKS! - gr_mkdir (path, 0750); -} - -static void -get_unittest_path (const char *filename, char *fullpath, size_t pathsize) -{ - char path[200]; - snprintf (path, sizeof(path), "./.unittests"); - snprintf (fullpath, pathsize, "%s/%s", path, filename); - - ensure_unittest_path(path); -} - diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc deleted file mode 100644 index d8f77b506..000000000 --- a/gruel/src/lib/thread.cc +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 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 this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <gruel/thread.h> - -namespace gruel { - - boost::system_time - get_new_timeout(double secs) - { - return boost::get_system_time() + boost::posix_time::milliseconds(long(secs*1e3)); - } - -} |