apps/fft: make recording controls visible, but don't record by default

To start recording, verify the filename and press REC button...
wip-signat
Dimitri Stolnikov 9 years ago
parent 567fcbdffa
commit 1e8b45d09e
  1. 126
      apps/osmocom_fft

@ -75,8 +75,8 @@ class app_top_block(stdgui2.std_top_block, pubsub):
help="Set gain in dB (default is midpoint)")
parser.add_option("-G", "--gains", type="string", default=None,
help="Set named gain in dB, name:gain,name:gain,...")
parser.add_option("-r", "--record", type="string", default=None,
help="Record to file, available wildcards: %S: sample rate, %F: center frequency, %T: timestamp, Example: /tmp/name-f%F-s%S-t%T.cfile")
parser.add_option("-r", "--record", type="string", default="/tmp/name-f%F-s%S-t%T.cfile",
help="Filename to record to, available wildcards: %S: sample rate, %F: center frequency, %T: timestamp, Example: /tmp/name-f%F-s%S-t%T.cfile")
parser.add_option("", "--dc-offset-mode", type="int", default=None,
help="Set the RX frontend DC offset correction mode")
parser.add_option("", "--iq-balance-mode", type="int", default=None,
@ -185,7 +185,7 @@ class app_top_block(stdgui2.std_top_block, pubsub):
self[SAMP_RATE_KEY] = options.samp_rate
self[CENTER_FREQ_KEY] = options.center_freq
self[FREQ_CORR_KEY] = options.freq_corr
self['record'] = self.record = options.record
self['record'] = options.record
self.dc_offset_mode = options.dc_offset_mode
self.iq_balance_mode = options.iq_balance_mode
@ -250,15 +250,13 @@ class app_top_block(stdgui2.std_top_block, pubsub):
self.connect(self.src, self.scope)
self._build_gui(vbox)
if self.record != None:
self.recording = self.record_to_filename()
self.file_sink = blocks.file_sink(gr.sizeof_gr_complex, "/dev/null", False)
self.file_sink.set_unbuffered(False)
self.file_sink.close() # close the sink immediately
# lock/connect/unlock at record button event did not work, so we leave it connected at all times
self.connect(self.src, self.file_sink)
print "Recording samples to ", self.recording
self.file_sink = blocks.file_sink(gr.sizeof_gr_complex, self.recording, False)
self.file_sink.set_unbuffered(False)
self.connect(self.src, self.file_sink)
self._build_gui(vbox)
if self.dc_offset_mode != None:
self.set_dc_offset_mode(self.dc_offset_mode)
@ -270,6 +268,13 @@ class app_top_block(stdgui2.std_top_block, pubsub):
if not(self.set_freq(options.center_freq)):
self._set_status_msg("Failed to set initial frequency")
def record_to_filename(self):
s = self['record']
s = s.replace('%S', '%e' % self.src.get_sample_rate())
s = s.replace('%F', '%e' % self.src.get_center_freq())
s = s.replace('%T', datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
return s
def wxsink_callback(self, x, y):
self.set_freq_from_callback(x)
@ -491,66 +496,55 @@ class app_top_block(stdgui2.std_top_block, pubsub):
# File recording controls
##################################################
if self.record != None:
rec_vbox = forms.static_box_sizer(parent=self.panel,
label="File recording",
orient=wx.VERTICAL,
bold=True)
rec_vbox.AddSpacer(3)
# First row of sample rate controls
rec_hbox = wx.BoxSizer(wx.HORIZONTAL)
rec_vbox.Add(rec_hbox, 0, wx.EXPAND)
rec_vbox.AddSpacer(5)
# Add sample rate controls to top window sizer
vbox.Add(rec_vbox, 0, wx.EXPAND)
vbox.AddSpacer(5)
rec_hbox.AddSpacer(3)
self.record_text = forms.text_box(
parent=self.panel, sizer=rec_hbox,
label='File Name',
proportion=1,
ps=self,
key='record',
converter=forms.str_converter(),
)
rec_hbox.AddSpacer(5)
def record_callback(value):
if value:
self.sample_rate_text.Disable()
self.record_text.Disable()
self.recording = self.record_to_filename()
rec_vbox = forms.static_box_sizer(parent=self.panel,
label="File recording",
orient=wx.VERTICAL,
bold=True)
rec_vbox.AddSpacer(3)
# First row of sample rate controls
rec_hbox = wx.BoxSizer(wx.HORIZONTAL)
rec_vbox.Add(rec_hbox, 0, wx.EXPAND)
rec_vbox.AddSpacer(5)
print "Recording samples to ", self.recording
self.file_sink.open(self.recording);
# Add sample rate controls to top window sizer
vbox.Add(rec_vbox, 0, wx.EXPAND)
vbox.AddSpacer(5)
else:
self.sample_rate_text.Enable()
self.record_text.Enable()
rec_hbox.AddSpacer(3)
self.record_text = forms.text_box(
parent=self.panel, sizer=rec_hbox,
label='File Name',
proportion=1,
ps=self,
key='record',
converter=forms.str_converter(),
)
rec_hbox.AddSpacer(5)
self.file_sink.close()
print "Finished recording to", self.recording
def record_callback(value):
if value:
self.sample_rate_text.Disable()
self.record_text.Disable()
forms.toggle_button(
sizer=rec_hbox,
parent=self.panel,
false_label='REC',
true_label='STOP',
value=True,
callback=record_callback,
)
def record_to_filename(self):
s = self['record']
s = s.replace('%S', '%e' % self.src.get_sample_rate())
s = s.replace('%F', '%e' % self.src.get_center_freq())
s = s.replace('%T', datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
return s
self.rec_file_name = self.record_to_filename()
print "Recording samples to ", self.rec_file_name
self.file_sink.open(self.rec_file_name);
else:
self.sample_rate_text.Enable()
self.record_text.Enable()
self.file_sink.close()
print "Finished recording to", self.rec_file_name
forms.toggle_button(
sizer=rec_hbox,
parent=self.panel,
false_label='REC',
true_label='STOP',
value=False,
callback=record_callback,
)
##################################################
# DC Offset controls

Loading…
Cancel
Save