diff options
-rwxr-xr-x | gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py | 16 | ||||
-rwxr-xr-x | gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py | 14 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_multi_usrp_sink.cc | 8 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_multi_usrp_sink.h | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_multi_usrp_source.cc | 8 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_multi_usrp_source.h | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_single_usrp_sink.cc | 8 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_single_usrp_sink.h | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_single_usrp_source.cc | 8 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_single_usrp_source.h | 4 | ||||
-rw-r--r-- | gr-uhd/swig/__init__.py | 41 | ||||
-rw-r--r-- | gr-uhd/swig/uhd_swig.i | 21 |
12 files changed, 89 insertions, 51 deletions
diff --git a/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py b/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py index 5902fa855..9f413f2a8 100755 --- a/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py +++ b/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -Copyright 2010 Free Software Foundation, Inc. +Copyright 2010-2011 Free Software Foundation, Inc. This file is part of GNU Radio @@ -27,16 +27,12 @@ MAIN_TMPL = """\ <import>from gnuradio import uhd</import> <make>uhd.multi_usrp_$(sourk)( device_addr=\$dev_addr, - io_type=uhd.io_type_t.\$type.type, + io_type=uhd.io_type.\$type.type, num_channels=\$nchan, ) \#if \$sync() -_clk_cfg = uhd.clock_config_t() -_clk_cfg.ref_source = uhd.clock_config_t.REF_SMA -_clk_cfg.pps_source = uhd.clock_config_t.PPS_SMA -_clk_cfg.pps_polarity = uhd.clock_config_t.PPS_POS -self.\$(id).set_clock_config(_clk_cfg, uhd.ALL_MBOARDS); -self.\$(id).set_time_unknown_pps(uhd.time_spec_t()) +self.\$(id).set_clock_config(uhd.clock_config.external(), uhd.ALL_MBOARDS); +self.\$(id).setime_unknown_pps(uhd.time_spec()) \#end if #for $m in range($max_mboards) \#if \$num_mboards() > $m and \$sd_spec$(m)() @@ -201,8 +197,8 @@ If the requested rate is not possible, the UHD block will print an error at runt Center frequency: The center frequency is the overall frequency of the RF chain. \\ For greater control of how the UHD tunes elements in the RF chain, \\ -pass a tune_request_t object rather than a simple target frequency. -Tuning with an LO offset example: uhd.tune_request_t(freq, lo_off) +pass a tune_request object rather than a simple target frequency. +Tuning with an LO offset example: uhd.tune_request(freq, lo_off) Antenna: For subdevices with only one antenna, this may be left blank. \\ diff --git a/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py b/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py index 66728fe28..4de21c989 100755 --- a/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py +++ b/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -Copyright 2010 Free Software Foundation, Inc. +Copyright 2010-2011 Free Software Foundation, Inc. This file is part of GNU Radio @@ -27,15 +27,11 @@ MAIN_TMPL = """\ <import>from gnuradio import uhd</import> <make>uhd.single_usrp_$(sourk)( device_addr=\$dev_addr, - io_type=uhd.io_type_t.\$type.type, + io_type=uhd.io_type.\$type.type, num_channels=\$nchan, ) \#if \$ref_clk() -_clk_cfg = uhd.clock_config_t() -_clk_cfg.ref_source = uhd.clock_config_t.REF_SMA -_clk_cfg.pps_source = uhd.clock_config_t.PPS_SMA -_clk_cfg.pps_polarity = uhd.clock_config_t.PPS_POS -self.\$(id).set_clock_config(_clk_cfg); +self.\$(id).set_clock_config(uhd.clock_config.external()); \#end if \#if \$sd_spec() self.\$(id).set_subdev_spec(\$sd_spec) @@ -180,8 +176,8 @@ If the requested rate is not possible, the UHD block will print an error at runt Center frequency: The center frequency is the overall frequency of the RF chain. \\ For greater control of how the UHD tunes elements in the RF chain, \\ -pass a tune_request_t object rather than a simple target frequency. -Tuning with an LO offset example: uhd.tune_request_t(freq, lo_off) +pass a tune_request object rather than a simple target frequency. +Tuning with an LO offset example: uhd.tune_request(freq, lo_off) Antenna: For subdevices with only one antenna, this may be left blank. \\ diff --git a/gr-uhd/lib/uhd_multi_usrp_sink.cc b/gr-uhd/lib/uhd_multi_usrp_sink.cc index a1d0a2584..7e81f8dea 100644 --- a/gr-uhd/lib/uhd_multi_usrp_sink.cc +++ b/gr-uhd/lib/uhd_multi_usrp_sink.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,7 +37,7 @@ uhd_multi_usrp_sink::uhd_multi_usrp_sink(gr_io_signature_sptr sig) class uhd_multi_usrp_sink_impl : public uhd_multi_usrp_sink{ public: uhd_multi_usrp_sink_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -185,8 +185,8 @@ protected: * Make UHD Multi USRP Sink **********************************************************************/ boost::shared_ptr<uhd_multi_usrp_sink> uhd_make_multi_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_multi_usrp_sink>( diff --git a/gr-uhd/lib/uhd_multi_usrp_sink.h b/gr-uhd/lib/uhd_multi_usrp_sink.h index 4a92cba6c..208e2c55d 100644 --- a/gr-uhd/lib/uhd_multi_usrp_sink.h +++ b/gr-uhd/lib/uhd_multi_usrp_sink.h @@ -29,8 +29,8 @@ class uhd_multi_usrp_sink; GR_UHD_API boost::shared_ptr<uhd_multi_usrp_sink> uhd_make_multi_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ); diff --git a/gr-uhd/lib/uhd_multi_usrp_source.cc b/gr-uhd/lib/uhd_multi_usrp_source.cc index 029a763e3..770314057 100644 --- a/gr-uhd/lib/uhd_multi_usrp_source.cc +++ b/gr-uhd/lib/uhd_multi_usrp_source.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,7 +39,7 @@ uhd_multi_usrp_source::uhd_multi_usrp_source(gr_io_signature_sptr sig) class uhd_multi_usrp_source_impl : public uhd_multi_usrp_source{ public: uhd_multi_usrp_source_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -177,8 +177,8 @@ private: * Make UHD Multi USRP Source **********************************************************************/ boost::shared_ptr<uhd_multi_usrp_source> uhd_make_multi_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_multi_usrp_source>( diff --git a/gr-uhd/lib/uhd_multi_usrp_source.h b/gr-uhd/lib/uhd_multi_usrp_source.h index 841f8fb44..ff77d9d9e 100644 --- a/gr-uhd/lib/uhd_multi_usrp_source.h +++ b/gr-uhd/lib/uhd_multi_usrp_source.h @@ -29,8 +29,8 @@ class uhd_multi_usrp_source; GR_UHD_API boost::shared_ptr<uhd_multi_usrp_source> uhd_make_multi_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ); diff --git a/gr-uhd/lib/uhd_single_usrp_sink.cc b/gr-uhd/lib/uhd_single_usrp_sink.cc index 8ac2ae0fd..7b47827d6 100644 --- a/gr-uhd/lib/uhd_single_usrp_sink.cc +++ b/gr-uhd/lib/uhd_single_usrp_sink.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,7 +37,7 @@ uhd_single_usrp_sink::uhd_single_usrp_sink(gr_io_signature_sptr sig) class uhd_single_usrp_sink_impl : public uhd_single_usrp_sink{ public: uhd_single_usrp_sink_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -172,8 +172,8 @@ protected: * Make UHD Single USRP Sink **********************************************************************/ boost::shared_ptr<uhd_single_usrp_sink> uhd_make_single_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_single_usrp_sink>( diff --git a/gr-uhd/lib/uhd_single_usrp_sink.h b/gr-uhd/lib/uhd_single_usrp_sink.h index 432798a6d..c6e92c1e6 100644 --- a/gr-uhd/lib/uhd_single_usrp_sink.h +++ b/gr-uhd/lib/uhd_single_usrp_sink.h @@ -29,8 +29,8 @@ class uhd_single_usrp_sink; GR_UHD_API boost::shared_ptr<uhd_single_usrp_sink> uhd_make_single_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels = 1 ); diff --git a/gr-uhd/lib/uhd_single_usrp_source.cc b/gr-uhd/lib/uhd_single_usrp_source.cc index 45f852a3e..547b950dc 100644 --- a/gr-uhd/lib/uhd_single_usrp_source.cc +++ b/gr-uhd/lib/uhd_single_usrp_source.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,7 +39,7 @@ uhd_single_usrp_source::uhd_single_usrp_source(gr_io_signature_sptr sig) class uhd_single_usrp_source_impl : public uhd_single_usrp_source{ public: uhd_single_usrp_source_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -183,8 +183,8 @@ private: * Make UHD Single USRP Source **********************************************************************/ boost::shared_ptr<uhd_single_usrp_source> uhd_make_single_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_single_usrp_source>( diff --git a/gr-uhd/lib/uhd_single_usrp_source.h b/gr-uhd/lib/uhd_single_usrp_source.h index 9b7255533..298c00dc2 100644 --- a/gr-uhd/lib/uhd_single_usrp_source.h +++ b/gr-uhd/lib/uhd_single_usrp_source.h @@ -29,8 +29,8 @@ class uhd_single_usrp_source; GR_UHD_API boost::shared_ptr<uhd_single_usrp_source> uhd_make_single_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels = 1 ); diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 157733880..0991f5b6b 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -27,13 +27,15 @@ from uhd_swig import * ######################################################################## -# Add other content from pure-Python modules here +# Make types with to_string functions printable ######################################################################## - -#make the ranges printable in python range_t.__str__ = lambda s: s.to_pp_string().strip() meta_range_t.__str__ = lambda s: s.to_pp_string().strip() +device_addr_t.__str__ = lambda s: s.to_pp_string().strip() +######################################################################## +# Add other content from pure-Python modules here +######################################################################## class freq_range_t(meta_range_t): pass #a typedef for the user class gain_range_t(meta_range_t): pass #a typedef for the user @@ -46,8 +48,41 @@ class tune_request_t(tune_request_t, float): def __new__(self, *args): return float.__new__(self) def __float__(self): return self.target_freq +class device_addr_t(device_addr_t, str): + """ + Make the python tune request object inherit from string + so that it can be passed in GRC as a string parameter. + The type checking in GRC will accept the device address. + Define the set/get item special methods for dict access. + """ + def __new__(self, *args): return str.__new__(self) + def __getitem__(self, key): return self.get(key) + def __setitem__(self, key, val): self.set(key, val) + ######################################################################## # Create aliases for global attributes to avoid the "_t" ######################################################################## for attr in globals().keys(): if attr.endswith('_t'): globals()[attr[:-2]] = globals()[attr] + +######################################################################## +# Cast constructor args (FIXME swig handle overloads?) +######################################################################## +for attr in ( + 'single_usrp_source', 'single_usrp_sink', + 'multi_usrp_source', 'multi_usrp_sink' +): + def constructor_factory(old_constructor): + def constructor_interceptor(*args, **kwargs): + args = list(args) + kwargs = dict(kwargs) + for index, key, cast in ( + (0, 'device_addr', device_addr), + (1, 'io_type', io_type), + ): + if len(args) > index: args[index] = cast(args[index]) + if kwargs.has_key(key): kwargs[key] = cast(kwargs[key]) + return old_constructor(*args, **kwargs) + return constructor_interceptor + import uhd_swig + globals()[attr] = constructor_factory(getattr(uhd_swig, attr)) diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 89f82e9f4..e25dbce90 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -60,21 +60,32 @@ %} //////////////////////////////////////////////////////////////////////// -// templated types +// used types //////////////////////////////////////////////////////////////////////// %template(string_vector_t) std::vector<std::string>; -%template(range_vector_t) std::vector<uhd::range_t>; -//////////////////////////////////////////////////////////////////////// -// used types -//////////////////////////////////////////////////////////////////////// %include <uhd/config.hpp> + %include <uhd/utils/pimpl.hpp> + +%include <uhd/types/dict.hpp> +%template(string_string_dict_t) uhd::dict<std::string, std::string>; //define after dict + +%include <uhd/types/device_addr.hpp> + +%include <uhd/types/io_type.hpp> + +%template(range_vector_t) std::vector<uhd::range_t>; //define before range %include <uhd/types/ranges.hpp> + %include <uhd/types/tune_request.hpp> + %include <uhd/types/tune_result.hpp> + %include <uhd/types/io_type.hpp> + %include <uhd/types/time_spec.hpp> + %include <uhd/types/clock_config.hpp> //////////////////////////////////////////////////////////////////////// |