diff options
Diffstat (limited to 'gr-utils/python/utils')
-rw-r--r-- | gr-utils/python/utils/CMakeLists.txt | 3 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_modtool | 28 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_char | 33 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_const | 30 | ||||
-rw-r--r-- | gr-utils/python/utils/gr_plot_fft | 8 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_fft_c | 11 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_fft_f | 12 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_float | 27 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_int | 27 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_iq | 31 | ||||
-rw-r--r-- | gr-utils/python/utils/gr_plot_psd | 8 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_psd_c | 13 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_psd_f | 13 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_short | 27 | ||||
-rw-r--r-- | gr-utils/python/utils/gr_read_file_metadata | 20 | ||||
-rwxr-xr-x | gr-utils/python/utils/grcc | 92 | ||||
-rw-r--r-- | gr-utils/python/utils/plot_data.py | 1 | ||||
-rwxr-xr-x | gr-utils/python/utils/plot_fft_base.py | 33 | ||||
-rwxr-xr-x | gr-utils/python/utils/plot_psd_base.py | 48 |
19 files changed, 165 insertions, 300 deletions
diff --git a/gr-utils/python/utils/CMakeLists.txt b/gr-utils/python/utils/CMakeLists.txt index 54eba51170..3ce335c4ed 100644 --- a/gr-utils/python/utils/CMakeLists.txt +++ b/gr-utils/python/utils/CMakeLists.txt @@ -30,7 +30,6 @@ GR_PYTHON_INSTALL( pyqt_plot.py pyqt_filter.py DESTINATION ${GR_PYTHON_DIR}/gnuradio - COMPONENT "utils" ) GR_PYTHON_INSTALL( @@ -50,7 +49,5 @@ GR_PYTHON_INSTALL( gr_plot_short gr_plot_qt gr_read_file_metadata - grcc DESTINATION ${GR_RUNTIME_DIR} - COMPONENT "utils" ) diff --git a/gr-utils/python/utils/gr_modtool b/gr-utils/python/utils/gr_modtool index e714cf48e5..d9016840be 100755 --- a/gr-utils/python/utils/gr_modtool +++ b/gr-utils/python/utils/gr_modtool @@ -24,19 +24,27 @@ from gnuradio.modtool import * +def setup_parser(): + modules = get_modtool_modules(globals().values()) + parser = ModTool.get_parser() + subparsers = parser.add_subparsers(title="Commands") + epilog = [] + for module in modules: + subparser = subparsers.add_parser(module.name, + description=module.description) + module.setup_parser(subparser) + subparser.set_defaults(module=module) + epilog.append(" {:<22}{}".format(module.name, module.description)) + parser.epilog = '\n'.join(epilog) + return parser + def main(): """ Here we go. Parse command, choose class and run. """ - cmd_dict = get_class_dict(globals().values()) - command = get_command_from_argv(cmd_dict.keys()) - if command is None: - print 'Usage:' + Templates['usage'] - exit(2) - modtool = cmd_dict[command]() - try: - (options, args) = modtool.parser.parse_args() - modtool.setup(options, args) - modtool.run() + parser = setup_parser() + args = parser.parse_args() + try: + args.module().run(args) except ModToolException as err: print >> sys.stderr, err exit(1) diff --git a/gr-utils/python/utils/gr_plot_char b/gr-utils/python/utils/gr_plot_char index a2b93a63c6..ee644557bb 100755 --- a/gr-utils/python/utils/gr_plot_char +++ b/gr-utils/python/utils/gr_plot_char @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio byte/char binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") - - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args - - datatype=scipy.int8 - dc = plot_data(datatype, filenames, options) + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("files", metavar="FILE", nargs="+", + help="Input file with complex samples") + + args = parser.parse_args() + + datatype = scipy.int8 + dc = plot_data(datatype, args.files, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_const b/gr-utils/python/utils/gr_plot_const index e2580dd58f..653a2539b4 100755 --- a/gr-utils/python/utils/gr_plot_const +++ b/gr-utils/python/utils/gr_plot_const @@ -33,7 +33,7 @@ except ImportError: print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser class draw_constellation: def __init__(self, filename, options): @@ -221,24 +221,20 @@ def find(item_in, list_search): def main(): - usage="%prog: [options] input_filename" description = "Takes a GNU Radio complex binary file and displays the I&Q data versus time and the constellation plot (I vs. Q). You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") - - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - dc = draw_constellation(filename, options) + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with complex samples") + args = parser.parse_args() + + dc = draw_constellation(args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_fft b/gr-utils/python/utils/gr_plot_fft index 4343481645..59fc88b994 100644 --- a/gr-utils/python/utils/gr_plot_fft +++ b/gr-utils/python/utils/gr_plot_fft @@ -27,13 +27,9 @@ from gnuradio.plot_fft_base import plot_fft_base def main(): parser = plot_fft_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_fft_base(options.data_type, filename, options) + dc = plot_fft_base(args.data_type, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_fft_c b/gr-utils/python/utils/gr_plot_fft_c index 43e808d95a..48d3218586 100755 --- a/gr-utils/python/utils/gr_plot_fft_c +++ b/gr-utils/python/utils/gr_plot_fft_c @@ -26,15 +26,12 @@ from gnuradio.plot_fft_base import plot_fft_base def main(): parser = plot_fft_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", )) - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_fft_base("complex64", filename, options) + dc = plot_fft_base("complex64", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_fft_f b/gr-utils/python/utils/gr_plot_fft_f index dee9b17dea..d1791419bb 100755 --- a/gr-utils/python/utils/gr_plot_fft_f +++ b/gr-utils/python/utils/gr_plot_fft_f @@ -26,15 +26,11 @@ from gnuradio.plot_fft_base import plot_fft_base def main(): parser = plot_fft_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="float32", + choices=("float32", )) + args = parser.parse_args() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - dc = plot_fft_base("float32", filename, options) + dc = plot_fft_base("float32", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_float b/gr-utils/python/utils/gr_plot_float index 22806e48ae..faf8106d70 100755 --- a/gr-utils/python/utils/gr_plot_float +++ b/gr-utils/python/utils/gr_plot_float @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio floating point binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", nargs='+', + help="Input file with samples") - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args + args = parser.parse_args() datatype=scipy.float32 - dc = plot_data(datatype, filenames, options) + dc = plot_data(datatype, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_int b/gr-utils/python/utils/gr_plot_int index 355ddf0189..c687f13b17 100755 --- a/gr-utils/python/utils/gr_plot_int +++ b/gr-utils/python/utils/gr_plot_int @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio integer binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", nargs='+', + help="Input file"); - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args + args = parser.parse_args() datatype=scipy.int32 - dc = plot_data(datatype, filenames, options) + dc = plot_data(datatype, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_iq b/gr-utils/python/utils/gr_plot_iq index bf8077b6b4..7409b73909 100755 --- a/gr-utils/python/utils/gr_plot_iq +++ b/gr-utils/python/utils/gr_plot_iq @@ -32,7 +32,7 @@ except ImportError: print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser class draw_iq: def __init__(self, filename, options): @@ -149,24 +149,21 @@ def find(item_in, list_search): return False def main(): - usage="%prog: [options] input_filename" description = "Takes a GNU Radio complex binary file and displays the I&Q data versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") - - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - dc = draw_iq(filename, options) + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with complex samples") + + args = parser.parse_args() + + dc = draw_iq(args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_psd b/gr-utils/python/utils/gr_plot_psd index 059ca6b645..b052cbfdd7 100644 --- a/gr-utils/python/utils/gr_plot_psd +++ b/gr-utils/python/utils/gr_plot_psd @@ -27,13 +27,9 @@ from gnuradio.plot_psd_base import plot_psd_base def main(): parser = plot_psd_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base(options.data_type, filename, options) + dc = plot_psd_base(args.data_type, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_psd_c b/gr-utils/python/utils/gr_plot_psd_c index fff2bff0f2..352a838138 100755 --- a/gr-utils/python/utils/gr_plot_psd_c +++ b/gr-utils/python/utils/gr_plot_psd_c @@ -20,22 +20,19 @@ # Boston, MA 02110-1301, USA. # -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_psd_base import plot_psd_base # This is a wrapper program for plot_psd_base specifically for complex data def main(): parser = plot_psd_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", )) - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base("complex64", filename, options) + dc = plot_psd_base("complex64", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_psd_f b/gr-utils/python/utils/gr_plot_psd_f index ec67994797..ab860e3fb8 100755 --- a/gr-utils/python/utils/gr_plot_psd_f +++ b/gr-utils/python/utils/gr_plot_psd_f @@ -20,22 +20,19 @@ # Boston, MA 02110-1301, USA. # -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_psd_base import plot_psd_base # This is a wrapper program for gr_plot_psd specifically for floating point data def main(): parser = plot_psd_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="complex64", + choices=("float32", )) - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base("float32", filename, options) + dc = plot_psd_base("float32", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_short b/gr-utils/python/utils/gr_plot_short index 702a2a94a6..f900af1bac 100755 --- a/gr-utils/python/utils/gr_plot_short +++ b/gr-utils/python/utils/gr_plot_short @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio short integer binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("files", metavar="FILE", nargs="+", + help="Input file with data (int16_t)") - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args + args = parser.parse_args() datatype=scipy.int16 - dc = plot_data(datatype, filenames, options) + dc = plot_data(datatype, args.files, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_read_file_metadata b/gr-utils/python/utils/gr_read_file_metadata index 429b38310f..a05e7ad2c7 100644 --- a/gr-utils/python/utils/gr_read_file_metadata +++ b/gr-utils/python/utils/gr_read_file_metadata @@ -21,7 +21,7 @@ # import sys -from optparse import OptionParser +from argparse import ArgumentParser import pmt from gnuradio.blocks import parse_file_metadata @@ -69,19 +69,15 @@ def main(filename, detached=False): handle.seek(nread, 0) print "\n\n" + if __name__ == "__main__": - usage="%prog: [options] filename" description = "Read in a GNU Radio file with meta data, extracts the header and prints it." - parser = OptionParser(conflict_handler="resolve", - usage=usage, description=description) - parser.add_option("-D", "--detached", action="store_true", default=False, + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-D", "--detached", action="store_true", help="Used if header is detached.") - (options, args) = parser.parse_args () - - if(len(args) < 1): - sys.stderr.write("No filename given\n") - sys.exit(1) + parser.add_argument("file", metavar="FILE", + help="Input file"); + args = parser.parse_args() - filename = args[0] - main(filename, options.detached) + main(args.file, args.detached) diff --git a/gr-utils/python/utils/grcc b/gr-utils/python/utils/grcc deleted file mode 100755 index b9bd1551b9..0000000000 --- a/gr-utils/python/utils/grcc +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2012 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 os -import sys -from optparse import OptionParser -import warnings -warnings.simplefilter('ignore') - -from gnuradio import gr - -try: - from grc.core.Platform import Platform -except ImportError: - from gnuradio.grc.core.Platform import Platform - - -class GRCC: - def __init__(self, grcfile, out_dir): - self.out_dir = out_dir - self.platform = Platform( - prefs_file=gr.prefs(), - version=gr.version(), - version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()) - ) - data = self.platform.parse_flow_graph(grcfile) - - self.fg = self.platform.get_new_flow_graph() - self.fg.import_data(data) - self.fg.grc_file_path = os.path.abspath(grcfile) - self.fg.validate() - - if not self.fg.is_valid(): - raise StandardError("\n\n".join( - ["Validation failed:"] + self.fg.get_error_messages() - )) - - self.gen = self.platform.Generator(self.fg, out_dir) - self.gen.write() - - def exec_program(self): - progname = self.fg.get_option('id') - os.system("{0}/{1}.py".format(self.out_dir, progname)) - - -def main(): - usage="%prog: [options] filename" - description = "Compiles a GRC file (.grc) into a GNU Radio Python program. The program is stored in ~/.grc_gnuradio by default, but this location can be changed with the -d option." - - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-d", "--directory", type="string", default='{0}/.grc_gnuradio/'.format(os.environ["HOME"]), - help="Specify the directory to output the compile program [default=%default]") - parser.add_option("-e", "--execute", action="store_true", default=False, - help="Run the program after compiling [default=%default]") - (options, args) = parser.parse_args () - - if len(args) != 1: - sys.stderr.write("Please specify a GRC file name to compile.\n") - sys.exit(1) - - try: - g = GRCC(args[0], options.directory + "/") - except Exception as e: - sys.stderr.write(str(e) + "\n") - sys.stderr.write("Error during file compilation.\n") - sys.exit(1) - - if options.execute: - g.exec_program() - - -if __name__ == "__main__": - main() diff --git a/gr-utils/python/utils/plot_data.py b/gr-utils/python/utils/plot_data.py index 2ae3b1d5b3..7d80c714fe 100644 --- a/gr-utils/python/utils/plot_data.py +++ b/gr-utils/python/utils/plot_data.py @@ -34,7 +34,6 @@ except ImportError: print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" raise SystemExit, 1 -from optparse import OptionParser class plot_data: def __init__(self, datatype, filenames, options): diff --git a/gr-utils/python/utils/plot_fft_base.py b/gr-utils/python/utils/plot_fft_base.py index c4bc484d97..c99462147d 100755 --- a/gr-utils/python/utils/plot_fft_base.py +++ b/gr-utils/python/utils/plot_fft_base.py @@ -33,7 +33,7 @@ except ImportError: print "Please install Python Matplotlib (http://matplotlib.sourceforge.net/) and Python TkInter https://wiki.python.org/moin/TkInter to run this script" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser class plot_fft_base: def __init__(self, datatype, filename, options): @@ -209,18 +209,21 @@ class plot_fft_base: @staticmethod def setup_options(): - usage="%prog: [options] input_filename" description = "Takes a GNU Radio complex binary file and displays the I&Q data versus time as well as the frequency domain (FFT) plot. The y-axis values are plotted assuming volts as the amplitude of the I&Q streams and converted into dBm in the frequency domain (the 1/N power adjustment out of the FFT is performed internally). The script plots a certain block of data at a time, specified on the command line as -B or --block. This value defaults to 1000. The start position in the file can be set by specifying -s or --start and defaults to 0 (the start of the file). By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time and frequency axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-d", "--data-type", type="string", default="complex64", - help="Specify the data type (complex64, float32, (u)int32, (u)int16, (u)int8) [default=%default]") - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", "float32", "uint32", "int32", "uint16", + "int16", "uint8", "int8"), + help="Specify the data type [default=%(default)r]") + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with samples") return parser def find(item_in, list_search): @@ -231,13 +234,9 @@ def find(item_in, list_search): def main(): parser = plot_fft_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_fft_base(options.data_type, filename, options) + dc = plot_fft_base(args.data_type, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/plot_psd_base.py b/gr-utils/python/utils/plot_psd_base.py index fe3c9e12b7..2611ed4be2 100755 --- a/gr-utils/python/utils/plot_psd_base.py +++ b/gr-utils/python/utils/plot_psd_base.py @@ -33,9 +33,9 @@ except ImportError: print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from scipy import log10 -from gnuradio.eng_option import eng_option +from gnuradio.eng_arg import eng_float, intx class plot_psd_base: def __init__(self, datatype, filename, options): @@ -244,25 +244,27 @@ class plot_psd_base: @staticmethod def setup_options(): - usage="%prog: [options] input_filename" description = "Takes a GNU Radio binary file (with specified data type using --data-type) and displays the I&Q data versus time as well as the power spectral density (PSD) plot. The y-axis values are plotted assuming volts as the amplitude of the I&Q streams and converted into dBm in the frequency domain (the 1/N power adjustment out of the FFT is performed internally). The script plots a certain block of data at a time, specified on the command line as -B or --block. The start position in the file can be set by specifying -s or --start and defaults to 0 (the start of the file). By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time and frequency axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples. Finally, the size of the FFT to use for the PSD and spectrogram plots can be set independently with --psd-size and --spec-size, respectively. The spectrogram plot does not display by default and is turned on with -S or --enable-spec." - parser = OptionParser(option_class=eng_option, conflict_handler="resolve", - usage=usage, description=description) - parser.add_option("-d", "--data-type", type="string", default="complex64", - help="Specify the data type (complex64, float32, (u)int32, (u)int16, (u)int8) [default=%default]") - parser.add_option("-B", "--block", type="int", default=8192, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="eng_float", default=1.0, - help="Set the sampler rate of the data [default=%default]") - parser.add_option("", "--psd-size", type="int", default=1024, - help="Set the size of the PSD FFT [default=%default]") - parser.add_option("", "--spec-size", type="int", default=256, - help="Set the size of the spectrogram FFT [default=%default]") - parser.add_option("-S", "--enable-spec", action="store_true", default=False, - help="Turn on plotting the spectrogram [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", "float32", "int32", "uint32", "int16", + "uint16", "int8", "uint8" ), + help="Specify the data type [default=%(default)r]") + parser.add_argument("-B", "--block", type=int, default=8192, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=eng_float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("--psd-size", type=int, default=1024, + help="Set the size of the PSD FFT [default=%(default)r]") + parser.add_argument("--spec-size", type=int, default=256, + help="Set the size of the spectrogram FFT [default=%(default)r]") + parser.add_argument("-S", "--enable-spec", action="store_true", + help="Turn on plotting the spectrogram [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with samples") return parser @@ -274,13 +276,9 @@ def find(item_in, list_search): def main(): parser = plot_psd_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base(options.data_type, filename, options) + dc = plot_psd_base(args.data_type, args.file, args) if __name__ == "__main__": try: |