2 # Copyright 2006 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 Miscellaneous utilities for managing mods and demods, as well as other items
23 useful in dealing with generalized handling of different modulations and demods.
29 # Type 1 modulators accept a stream of bytes on their input and produce complex baseband output
30 _type_1_modulators = {}
33 return _type_1_modulators
35 def add_type_1_mod(name, mod_class):
36 _type_1_modulators[name] = mod_class
39 # Type 1 demodulators accept complex baseband input and produce a stream of bits, packed
40 # 1 bit / byte as their output. Their output is completely unambiguous. There is no need
41 # to resolve phase or polarity ambiguities.
42 _type_1_demodulators = {}
45 return _type_1_demodulators
47 def add_type_1_demod(name, demod_class):
48 _type_1_demodulators[name] = demod_class
51 def extract_kwargs_from_options(function, excluded_args, options):
53 Given a function, a list of excluded arguments and the result of
54 parsing command line options, create a dictionary of key word
55 arguments suitable for passing to the function. The dictionary
56 will be populated with key/value pairs where the keys are those
57 that are common to the function's argument list (minus the
58 excluded_args) and the attributes in options. The values are the
59 corresponding values from options unless that value is None.
60 In that case, the corresponding dictionary entry is not populated.
62 (This allows different modulations that have the same parameter
63 names, but different default values to coexist. The downside is
64 that --help in the option parser will list the default as None,
65 but in that case the default provided in the __init__ argument
66 list will be used since there is no kwargs entry.)
68 @param function: the function whose parameter list will be examined
69 @param excluded_args: function arguments that are NOT to be added to the dictionary
70 @type excluded_args: sequence of strings
71 @param options: result of command argument parsing
72 @type options: optparse.Values
75 args, varargs, varkw, defaults = inspect.getargspec(function)
77 for kw in [a for a in args if a not in excluded_args]:
78 if hasattr(options, kw):
79 if getattr(options, kw) is not None:
80 d[kw] = getattr(options, kw)