diff options
Diffstat (limited to 'gr-qtgui/apps/gr_time_plot_s')
-rwxr-xr-x | gr-qtgui/apps/gr_time_plot_s | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/gr-qtgui/apps/gr_time_plot_s b/gr-qtgui/apps/gr_time_plot_s new file mode 100755 index 0000000000..43b098dbdb --- /dev/null +++ b/gr-qtgui/apps/gr_time_plot_s @@ -0,0 +1,172 @@ +#!/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. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples(filename, start, in_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_short, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int16, count=in_size) + data = data.tolist() + fhandle.close() + + if(len(data) < in_size): + print "Warning: read in {0} samples but asked for {1} samples.".format( + len(data), in_size) + + return data + +class gr_time_plot_f(gr.top_block): + def __init__(self, filelist, samp_rate, start, nsamples, max_nsamples, scale): + gr.top_block.__init__(self) + + self._filelist = filelist + self._samp_rate = samp_rate + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.time_sink_f(self._nsamps, self._samp_rate, + "GNU Radio Time Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples(f, self._start, self._nsamps) + self.srcs.append(gr.vector_source_s(data)) + self.cnvrt.append(gr.short_to_float(1, self._scale)) + + # Set default labels based on file names + fname = f.split("/")[-1] + self.gui_snk.set_line_label(n, "{0}".format(fname)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + + for s,f in zip(self.srcs, self._filelist): + data = read_samples(f, self._start, newnsamps) + s.set_data(data) + if(len(data) < newnsamps): + newnsamps = len(data) + + self._nsamps = newnsamps + self.gui_snk.set_nsamps(self._nsamps) + + self.start() + +def main(): + description = "Plots a list of files on a scope plot. Files are a binary list of shorts." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(16-1)-1, + help="Set a scaling factor for the short->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_short) + max_nsamples = min(filesizes) + + tb = gr_time_plot_f(filelist, options.sample_rate, + options.start, nsamples, max_nsamples, + options.scale); + + main_box = dialog_box(tb, 'GNU Radio Time Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + |