From 73ccc57f0f8c25162b8a3410e8a9e59c9e824a45 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 12 Oct 2011 23:02:56 -0400 Subject: digital: changed modulation_utils2 to modulation_utils and update all files using it. --- gr-digital/examples/narrowband/benchmark_rx.py | 2 +- gr-digital/examples/narrowband/benchmark_tx.py | 2 +- gr-digital/examples/narrowband/digital_bert_rx.py | 4 +- gr-digital/examples/narrowband/digital_bert_tx.py | 2 +- gr-digital/examples/narrowband/rx_voice.py | 2 +- gr-digital/examples/narrowband/tunnel.py | 4 +- gr-digital/examples/narrowband/tx_voice.py | 2 +- gr-digital/python/Makefile.am | 2 +- gr-digital/python/__init__.py | 2 +- gr-digital/python/bpsk.py | 14 +-- gr-digital/python/cpm.py | 8 +- gr-digital/python/generic_mod_demod.py | 2 +- gr-digital/python/gmsk.py | 10 +-- gr-digital/python/modulation_utils.py | 102 ++++++++++++++++++++++ gr-digital/python/modulation_utils2.py | 102 ---------------------- gr-digital/python/psk.py | 8 +- gr-digital/python/qam.py | 8 +- gr-digital/python/qpsk.py | 14 +-- 18 files changed, 145 insertions(+), 145 deletions(-) create mode 100644 gr-digital/python/modulation_utils.py delete mode 100644 gr-digital/python/modulation_utils2.py diff --git a/gr-digital/examples/narrowband/benchmark_rx.py b/gr-digital/examples/narrowband/benchmark_rx.py index 143948194..65aac3638 100755 --- a/gr-digital/examples/narrowband/benchmark_rx.py +++ b/gr-digital/examples/narrowband/benchmark_rx.py @@ -87,7 +87,7 @@ def main(): print "ok = %5s pktno = %4d n_rcvd = %4d n_right = %4d" % ( ok, pktno, n_rcvd, n_right) - demods = digital.modulation_utils2.type_1_demods() + demods = digital.modulation_utils.type_1_demods() # Create Options Parser: parser = OptionParser (option_class=eng_option, conflict_handler="resolve") diff --git a/gr-digital/examples/narrowband/benchmark_tx.py b/gr-digital/examples/narrowband/benchmark_tx.py index 6f1d75281..1fd881981 100755 --- a/gr-digital/examples/narrowband/benchmark_tx.py +++ b/gr-digital/examples/narrowband/benchmark_tx.py @@ -71,7 +71,7 @@ def main(): def send_pkt(payload='', eof=False): return tb.txpath.send_pkt(payload, eof) - mods = digital.modulation_utils2.type_1_mods() + mods = digital.modulation_utils.type_1_mods() parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") diff --git a/gr-digital/examples/narrowband/digital_bert_rx.py b/gr-digital/examples/narrowband/digital_bert_rx.py index 9ee1f5ee8..9878f55e1 100755 --- a/gr-digital/examples/narrowband/digital_bert_rx.py +++ b/gr-digital/examples/narrowband/digital_bert_rx.py @@ -178,7 +178,7 @@ def get_options(demods): uhd_receiver.add_options(parser) - demods = digital.modulation_utils2.type_1_demods() + demods = digital.modulation_utils.type_1_demods() for mod in demods.values(): mod.add_options(parser) @@ -191,7 +191,7 @@ def get_options(demods): if __name__ == "__main__": - demods = digital.modulation_utils2.type_1_demods() + demods = digital.modulation_utils.type_1_demods() (options, args) = get_options(demods) diff --git a/gr-digital/examples/narrowband/digital_bert_tx.py b/gr-digital/examples/narrowband/digital_bert_tx.py index 6b544c7f7..96cb338fe 100755 --- a/gr-digital/examples/narrowband/digital_bert_tx.py +++ b/gr-digital/examples/narrowband/digital_bert_tx.py @@ -122,7 +122,7 @@ def get_options(mods): return (options, args) if __name__ == "__main__": - mods = digital.modulation_utils2.type_1_mods() + mods = digital.modulation_utils.type_1_mods() (options, args) = get_options(mods) diff --git a/gr-digital/examples/narrowband/rx_voice.py b/gr-digital/examples/narrowband/rx_voice.py index b58704e16..42d7b893b 100755 --- a/gr-digital/examples/narrowband/rx_voice.py +++ b/gr-digital/examples/narrowband/rx_voice.py @@ -114,7 +114,7 @@ def main(): print "ok = %r n_rcvd = %4d n_right = %4d" % ( ok, n_rcvd, n_right) - demods = digital.modulation_utils2.type_1_demods() + demods = digital.modulation_utils.type_1_demods() # Create Options Parser: parser = OptionParser (option_class=eng_option, conflict_handler="resolve") diff --git a/gr-digital/examples/narrowband/tunnel.py b/gr-digital/examples/narrowband/tunnel.py index d25594df5..970920e6e 100755 --- a/gr-digital/examples/narrowband/tunnel.py +++ b/gr-digital/examples/narrowband/tunnel.py @@ -189,8 +189,8 @@ class cs_mac(object): def main(): - mods = digital.modulation_utils2.type_1_mods() - demods = digital.modulation_utils2.type_1_demods() + mods = digital.modulation_utils.type_1_mods() + demods = digital.modulation_utils.type_1_demods() parser = OptionParser (option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") diff --git a/gr-digital/examples/narrowband/tx_voice.py b/gr-digital/examples/narrowband/tx_voice.py index eabb5e3c3..3d767a077 100755 --- a/gr-digital/examples/narrowband/tx_voice.py +++ b/gr-digital/examples/narrowband/tx_voice.py @@ -102,7 +102,7 @@ def main(): def rx_callback(ok, payload): print "ok = %r, payload = '%s'" % (ok, payload) - mods = digital.modulation_utils2.type_1_mods() + mods = digital.modulation_utils.type_1_mods() parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") diff --git a/gr-digital/python/Makefile.am b/gr-digital/python/Makefile.am index d8c332ff8..e24af995e 100644 --- a/gr-digital/python/Makefile.am +++ b/gr-digital/python/Makefile.am @@ -53,7 +53,7 @@ digital_PYTHON = \ crc.py \ generic_mod_demod.py \ gmsk.py \ - modulation_utils2.py \ + modulation_utils.py \ ofdm.py \ ofdm_packet_utils.py \ ofdm_receiver.py \ diff --git a/gr-digital/python/__init__.py b/gr-digital/python/__init__.py index 7e7832481..7c76183c9 100644 --- a/gr-digital/python/__init__.py +++ b/gr-digital/python/__init__.py @@ -34,7 +34,7 @@ from gmsk import * from cpm import * from pkt import * from crc import * -from modulation_utils2 import * +from modulation_utils import * from ofdm import * from ofdm_receiver import * from ofdm_sync_fixed import * diff --git a/gr-digital/python/bpsk.py b/gr-digital/python/bpsk.py index 58a8289a5..0d8f05c4c 100644 --- a/gr-digital/python/bpsk.py +++ b/gr-digital/python/bpsk.py @@ -29,7 +29,7 @@ from cmath import exp from gnuradio import gr from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod import digital_swig -import modulation_utils2 +import modulation_utils # Default number of points in constellation. _def_constellation_points = 2 @@ -163,9 +163,9 @@ class dbpsk_demod(generic_demod): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('bpsk', bpsk_mod) -modulation_utils2.add_type_1_demod('bpsk', bpsk_demod) -modulation_utils2.add_type_1_constellation('bpsk', bpsk_constellation) -modulation_utils2.add_type_1_mod('dbpsk', dbpsk_mod) -modulation_utils2.add_type_1_demod('dbpsk', dbpsk_demod) -modulation_utils2.add_type_1_constellation('dbpsk', dbpsk_constellation) +modulation_utils.add_type_1_mod('bpsk', bpsk_mod) +modulation_utils.add_type_1_demod('bpsk', bpsk_demod) +modulation_utils.add_type_1_constellation('bpsk', bpsk_constellation) +modulation_utils.add_type_1_mod('dbpsk', dbpsk_mod) +modulation_utils.add_type_1_demod('dbpsk', dbpsk_demod) +modulation_utils.add_type_1_constellation('dbpsk', dbpsk_constellation) diff --git a/gr-digital/python/cpm.py b/gr-digital/python/cpm.py index 56d0fa849..05032336d 100644 --- a/gr-digital/python/cpm.py +++ b/gr-digital/python/cpm.py @@ -29,7 +29,7 @@ from math import pi import numpy import digital_swig -import modulation_utils2 +import modulation_utils # default values (used in __init__ and add_options) _def_samples_per_symbol = 2 @@ -227,7 +227,7 @@ class cpm_mod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils2.extract_kwargs_from_options(cpm_mod.__init__, + return modulation_utils.extract_kwargs_from_options(cpm_mod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) @@ -243,5 +243,5 @@ class cpm_mod(gr.hier_block2): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('cpm', cpm_mod) -#modulation_utils2.add_type_1_demod('cpm', cpm_demod) +modulation_utils.add_type_1_mod('cpm', cpm_mod) +#modulation_utils.add_type_1_demod('cpm', cpm_demod) diff --git a/gr-digital/python/generic_mod_demod.py b/gr-digital/python/generic_mod_demod.py index dec96e455..ae876e108 100644 --- a/gr-digital/python/generic_mod_demod.py +++ b/gr-digital/python/generic_mod_demod.py @@ -26,7 +26,7 @@ Generic modulation and demodulation. """ from gnuradio import gr -from modulation_utils2 import extract_kwargs_from_options_for_class +from modulation_utils import extract_kwargs_from_options_for_class from utils import mod_codes import digital_swig import math diff --git a/gr-digital/python/gmsk.py b/gr-digital/python/gmsk.py index c7a50f422..70fa197e3 100644 --- a/gr-digital/python/gmsk.py +++ b/gr-digital/python/gmsk.py @@ -26,7 +26,7 @@ from gnuradio import gr import digital_swig -import modulation_utils2 +import modulation_utils from math import pi import numpy @@ -151,7 +151,7 @@ class gmsk_mod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils2.extract_kwargs_from_options(gmsk_mod.__init__, + return modulation_utils.extract_kwargs_from_options(gmsk_mod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) @@ -265,12 +265,12 @@ class gmsk_demod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils2.extract_kwargs_from_options(gmsk_demod.__init__, + return modulation_utils.extract_kwargs_from_options(gmsk_demod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('gmsk', gmsk_mod) -modulation_utils2.add_type_1_demod('gmsk', gmsk_demod) +modulation_utils.add_type_1_mod('gmsk', gmsk_mod) +modulation_utils.add_type_1_demod('gmsk', gmsk_demod) diff --git a/gr-digital/python/modulation_utils.py b/gr-digital/python/modulation_utils.py new file mode 100644 index 000000000..cb3a9812d --- /dev/null +++ b/gr-digital/python/modulation_utils.py @@ -0,0 +1,102 @@ +# +# 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. +# + +""" +Miscellaneous utilities for managing mods and demods, as well as other items +useful in dealing with generalized handling of different modulations and demods. +""" + +import inspect + + +# Type 1 modulators accept a stream of bytes on their input and produce complex baseband output +_type_1_modulators = {} + +def type_1_mods(): + return _type_1_modulators + +def add_type_1_mod(name, mod_class): + _type_1_modulators[name] = mod_class + + +# Type 1 demodulators accept complex baseband input and produce a stream of bits, packed +# 1 bit / byte as their output. Their output is completely unambiguous. There is no need +# to resolve phase or polarity ambiguities. +_type_1_demodulators = {} + +def type_1_demods(): + return _type_1_demodulators + +def add_type_1_demod(name, demod_class): + _type_1_demodulators[name] = demod_class + +# Also record the constellation making functions of the modulations +_type_1_constellations = {} + +def type_1_constellations(): + return _type_1_constellations + +def add_type_1_constellation(name, constellation): + _type_1_constellations[name] = constellation + + +def extract_kwargs_from_options(function, excluded_args, options): + """ + Given a function, a list of excluded arguments and the result of + parsing command line options, create a dictionary of key word + arguments suitable for passing to the function. The dictionary + will be populated with key/value pairs where the keys are those + that are common to the function's argument list (minus the + excluded_args) and the attributes in options. The values are the + corresponding values from options unless that value is None. + In that case, the corresponding dictionary entry is not populated. + + (This allows different modulations that have the same parameter + names, but different default values to coexist. The downside is + that --help in the option parser will list the default as None, + but in that case the default provided in the __init__ argument + list will be used since there is no kwargs entry.) + + @param function: the function whose parameter list will be examined + @param excluded_args: function arguments that are NOT to be added to the dictionary + @type excluded_args: sequence of strings + @param options: result of command argument parsing + @type options: optparse.Values + """ + + # Try this in C++ ;) + args, varargs, varkw, defaults = inspect.getargspec(function) + d = {} + for kw in [a for a in args if a not in excluded_args]: + if hasattr(options, kw): + if getattr(options, kw) is not None: + d[kw] = getattr(options, kw) + return d + +def extract_kwargs_from_options_for_class(cls, options): + """ + Given command line options, create dictionary suitable for passing to __init__ + """ + d = extract_kwargs_from_options( + cls.__init__, ('self',), options) + for base in cls.__bases__: + if hasattr(base, 'extract_kwargs_from_options'): + d.update(base.extract_kwargs_from_options(options)) + return d diff --git a/gr-digital/python/modulation_utils2.py b/gr-digital/python/modulation_utils2.py deleted file mode 100644 index cb3a9812d..000000000 --- a/gr-digital/python/modulation_utils2.py +++ /dev/null @@ -1,102 +0,0 @@ -# -# 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. -# - -""" -Miscellaneous utilities for managing mods and demods, as well as other items -useful in dealing with generalized handling of different modulations and demods. -""" - -import inspect - - -# Type 1 modulators accept a stream of bytes on their input and produce complex baseband output -_type_1_modulators = {} - -def type_1_mods(): - return _type_1_modulators - -def add_type_1_mod(name, mod_class): - _type_1_modulators[name] = mod_class - - -# Type 1 demodulators accept complex baseband input and produce a stream of bits, packed -# 1 bit / byte as their output. Their output is completely unambiguous. There is no need -# to resolve phase or polarity ambiguities. -_type_1_demodulators = {} - -def type_1_demods(): - return _type_1_demodulators - -def add_type_1_demod(name, demod_class): - _type_1_demodulators[name] = demod_class - -# Also record the constellation making functions of the modulations -_type_1_constellations = {} - -def type_1_constellations(): - return _type_1_constellations - -def add_type_1_constellation(name, constellation): - _type_1_constellations[name] = constellation - - -def extract_kwargs_from_options(function, excluded_args, options): - """ - Given a function, a list of excluded arguments and the result of - parsing command line options, create a dictionary of key word - arguments suitable for passing to the function. The dictionary - will be populated with key/value pairs where the keys are those - that are common to the function's argument list (minus the - excluded_args) and the attributes in options. The values are the - corresponding values from options unless that value is None. - In that case, the corresponding dictionary entry is not populated. - - (This allows different modulations that have the same parameter - names, but different default values to coexist. The downside is - that --help in the option parser will list the default as None, - but in that case the default provided in the __init__ argument - list will be used since there is no kwargs entry.) - - @param function: the function whose parameter list will be examined - @param excluded_args: function arguments that are NOT to be added to the dictionary - @type excluded_args: sequence of strings - @param options: result of command argument parsing - @type options: optparse.Values - """ - - # Try this in C++ ;) - args, varargs, varkw, defaults = inspect.getargspec(function) - d = {} - for kw in [a for a in args if a not in excluded_args]: - if hasattr(options, kw): - if getattr(options, kw) is not None: - d[kw] = getattr(options, kw) - return d - -def extract_kwargs_from_options_for_class(cls, options): - """ - Given command line options, create dictionary suitable for passing to __init__ - """ - d = extract_kwargs_from_options( - cls.__init__, ('self',), options) - for base in cls.__bases__: - if hasattr(base, 'extract_kwargs_from_options'): - d.update(base.extract_kwargs_from_options(options)) - return d diff --git a/gr-digital/python/psk.py b/gr-digital/python/psk.py index 82781e63b..58f6787f0 100644 --- a/gr-digital/python/psk.py +++ b/gr-digital/python/psk.py @@ -27,7 +27,7 @@ from math import pi, log from cmath import exp import digital_swig -import modulation_utils2 +import modulation_utils from utils import mod_codes, gray_code from generic_mod_demod import generic_mod, generic_demod @@ -117,6 +117,6 @@ class psk_demod(generic_demod): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('psk', psk_mod) -modulation_utils2.add_type_1_demod('psk', psk_demod) -modulation_utils2.add_type_1_constellation('psk', psk_constellation) +modulation_utils.add_type_1_mod('psk', psk_mod) +modulation_utils.add_type_1_demod('psk', psk_demod) +modulation_utils.add_type_1_constellation('psk', psk_constellation) diff --git a/gr-digital/python/qam.py b/gr-digital/python/qam.py index 2a7e51495..5b1f7683b 100644 --- a/gr-digital/python/qam.py +++ b/gr-digital/python/qam.py @@ -29,7 +29,7 @@ from gnuradio import gr from generic_mod_demod import generic_mod, generic_demod from utils.gray_code import gray_code from utils import mod_codes -import modulation_utils2 +import modulation_utils import digital_swig # Default number of points in constellation. @@ -224,6 +224,6 @@ class qam_demod(generic_demod): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('qam', qam_mod) -modulation_utils2.add_type_1_demod('qam', qam_demod) -modulation_utils2.add_type_1_constellation('qam', qam_constellation) +modulation_utils.add_type_1_mod('qam', qam_mod) +modulation_utils.add_type_1_demod('qam', qam_demod) +modulation_utils.add_type_1_constellation('qam', qam_constellation) diff --git a/gr-digital/python/qpsk.py b/gr-digital/python/qpsk.py index 481b7cb5b..be21fd76f 100644 --- a/gr-digital/python/qpsk.py +++ b/gr-digital/python/qpsk.py @@ -28,7 +28,7 @@ Demodulation is not included since the generic_mod_demod from gnuradio import gr from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod import digital_swig -import modulation_utils2 +import modulation_utils # Default number of points in constellation. _def_constellation_points = 4 @@ -167,10 +167,10 @@ class dqpsk_demod(generic_demod): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('qpsk', qpsk_mod) -modulation_utils2.add_type_1_demod('qpsk', qpsk_demod) -modulation_utils2.add_type_1_constellation('qpsk', qpsk_constellation) -modulation_utils2.add_type_1_mod('dqpsk', dqpsk_mod) -modulation_utils2.add_type_1_demod('dqpsk', dqpsk_demod) -modulation_utils2.add_type_1_constellation('dqpsk', dqpsk_constellation) +modulation_utils.add_type_1_mod('qpsk', qpsk_mod) +modulation_utils.add_type_1_demod('qpsk', qpsk_demod) +modulation_utils.add_type_1_constellation('qpsk', qpsk_constellation) +modulation_utils.add_type_1_mod('dqpsk', dqpsk_mod) +modulation_utils.add_type_1_demod('dqpsk', dqpsk_demod) +modulation_utils.add_type_1_constellation('dqpsk', dqpsk_constellation) -- cgit