diff options
author | Steve Glass <smg@hush.com> | 2013-10-29 18:35:34 +1000 |
---|---|---|
committer | Steve Glass <smg@hush.com> | 2013-11-22 15:03:18 +1000 |
commit | c236f0cf8e01aec2e282c9cecdd2cdba2bd7e013 (patch) | |
tree | adf04725162c87477206f5b2803c099432fbccd5 /gr-uhd | |
parent | b942affe9f36be114ac01bf3dd50e4ad663a2845 (diff) |
gr-uhd: add option to uhd_rx_cfile to write metadata file.
Diffstat (limited to 'gr-uhd')
-rw-r--r--[-rwxr-xr-x] | gr-uhd/apps/uhd_rx_cfile | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/gr-uhd/apps/uhd_rx_cfile b/gr-uhd/apps/uhd_rx_cfile index d727d8752a..7d8d5dd88c 100755..100644 --- a/gr-uhd/apps/uhd_rx_cfile +++ b/gr-uhd/apps/uhd_rx_cfile @@ -31,6 +31,7 @@ from gnuradio import blocks from gnuradio import uhd from gnuradio.eng_option import eng_option from optparse import OptionParser +import pmt import sys n2s = eng_notation.num_to_str @@ -44,11 +45,9 @@ class rx_cfile_block(gr.top_block): if options.output_shorts: self._u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('sc16', options.wire_format, args=options.stream_args)) - self._sink = blocks.file_sink(gr.sizeof_short*2, filename) else: self._u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32', options.wire_format, args=options.stream_args)) - self._sink = blocks.file_sink(gr.sizeof_gr_complex, filename) # Set the subdevice spec if(options.spec): @@ -60,6 +59,7 @@ class rx_cfile_block(gr.top_block): # Set receiver sample rate self._u.set_samp_rate(options.samp_rate) + samp_rate = self._u.get_samp_rate() # Set receive daughterboard gain if options.gain is None: @@ -67,6 +67,7 @@ class rx_cfile_block(gr.top_block): options.gain = float(g.start()+g.stop())/2 print "Using mid-point gain of", options.gain, "(", g.start(), "-", g.stop(), ")" self._u.set_gain(options.gain) + gain = self._u.get_gain() # Set frequency (tune request takes lo_offset) if(options.lo_offset is not None): @@ -77,6 +78,29 @@ class rx_cfile_block(gr.top_block): if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 + freq = self._u.get_center_freq() + + # Create file sink + if options.metafile: + # store additional metadata + extras = pmt.make_dict() + extras = pmt.dict_add(extras, pmt.intern("rx_gain"), pmt.from_double(gain)) + extras_str = pmt.serialize_str(extras) + if options.output_shorts: + self._sink = blocks.file_meta_sink(gr.sizeof_short * 2, filename, + samp_rate, 1, + blocks.GR_FILE_SHORT, True, + 1000000, extras_str, False) + else: + self._sink = blocks.file_meta_sink(gr.sizeof_gr_complex, filename, + samp_rate, 1, + blocks.GR_FILE_FLOAT, True, + 1000000, extras_str, False) + else: + if options.output_shorts: + self._sink = blocks.file_sink(gr.sizeof_short*2, filename) + else: + self._sink = blocks.file_sink(gr.sizeof_gr_complex, filename) # Create head block if needed and wire it up if options.nsamples is None: @@ -89,8 +113,6 @@ class rx_cfile_block(gr.top_block): self.connect(self._u, self._head, self._sink) - input_rate = self._u.get_samp_rate() - if options.verbose: try: info = self._u.get_usrp_info() @@ -116,10 +138,11 @@ class rx_cfile_block(gr.top_block): print "Daughterboard: %s (%s, %s, %s)" % (rx_id, rx_serial, rx_antenna, rx_subdev_spec) except: print "Args: ", options.args + print "Rx gain:", options.gain print "Rx baseband frequency:", n2s(tr.actual_rf_freq) print "Rx DDC frequency:", n2s(tr.actual_dsp_freq) - print "Rx Sample Rate:", n2s(input_rate) + print "Rx Sample Rate:", n2s(samp_rate) if options.nsamples is None: print "Receiving samples until Ctrl-C" else: @@ -156,6 +179,8 @@ def get_options(): help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") + parser.add_option( "-m","--metafile", action="store_true", default=False, + help="output metadata to file [default=%default]") parser.add_option( "-s","--output-shorts", action="store_true", default=False, help="output interleaved shorts instead of complex floats") parser.add_option("-N", "--nsamples", type="eng_float", default=None, |