forked from sdr/gr-osmosdr
apps: check for sample rate availability
This commit is contained in:
parent
7a129238b7
commit
86b906a019
|
@ -97,6 +97,12 @@ class app_top_block(stdgui2.std_top_block, pubsub):
|
||||||
|
|
||||||
self.src = osmosdr.source(options.args)
|
self.src = osmosdr.source(options.args)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.src.get_sample_rates().start()
|
||||||
|
except RuntimeError:
|
||||||
|
print "Source has no sample rates (wrong device arguments?)."
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Set the antenna
|
# Set the antenna
|
||||||
if(options.antenna):
|
if(options.antenna):
|
||||||
self.src.set_antenna(options.antenna)
|
self.src.set_antenna(options.antenna)
|
||||||
|
|
|
@ -160,6 +160,12 @@ class top_block(gr.top_block, pubsub):
|
||||||
def _setup_osmosdr(self, options):
|
def _setup_osmosdr(self, options):
|
||||||
self._sink = osmosdr.sink(options.args)
|
self._sink = osmosdr.sink(options.args)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._sink.get_sample_rates().start()
|
||||||
|
except RuntimeError:
|
||||||
|
print "Sink has no sample rates (wrong device arguments?)."
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if options.samp_rate is None:
|
if options.samp_rate is None:
|
||||||
options.samp_rate = self._sink.get_sample_rates().start()
|
options.samp_rate = self._sink.get_sample_rates().start()
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,11 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import osmosdr
|
import osmosdr
|
||||||
from gnuradio import gr, eng_notation, window
|
from gnuradio import gr, eng_notation
|
||||||
|
from gnuradio import blocks
|
||||||
from gnuradio import audio
|
from gnuradio import audio
|
||||||
|
from gnuradio import filter
|
||||||
|
from gnuradio import fft
|
||||||
from gnuradio.eng_option import eng_option
|
from gnuradio.eng_option import eng_option
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import sys
|
import sys
|
||||||
|
@ -47,7 +50,7 @@ class tune(gr.feval_dd):
|
||||||
|
|
||||||
def eval(self, ignore):
|
def eval(self, ignore):
|
||||||
"""
|
"""
|
||||||
This method is called from gr.bin_statistics_f when it wants
|
This method is called from blocks.bin_statistics_f when it wants
|
||||||
to change the center frequency. This method tunes the front
|
to change the center frequency. This method tunes the front
|
||||||
end to the new center frequency, and returns the new frequency
|
end to the new center frequency, and returns the new frequency
|
||||||
as its result.
|
as its result.
|
||||||
|
@ -149,6 +152,12 @@ class my_top_block(gr.top_block):
|
||||||
# build graph
|
# build graph
|
||||||
self.u = osmosdr.source(options.args)
|
self.u = osmosdr.source(options.args)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.u.get_sample_rates().start()
|
||||||
|
except RuntimeError:
|
||||||
|
print "Source has no sample rates (wrong device arguments?)."
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Set the antenna
|
# Set the antenna
|
||||||
if(options.antenna):
|
if(options.antenna):
|
||||||
self.u.set_antenna(options.antenna, 0)
|
self.u.set_antenna(options.antenna, 0)
|
||||||
|
@ -166,19 +175,19 @@ class my_top_block(gr.top_block):
|
||||||
|
|
||||||
self.squelch_threshold = options.squelch_threshold
|
self.squelch_threshold = options.squelch_threshold
|
||||||
|
|
||||||
s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
|
s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
|
||||||
|
|
||||||
mywindow = window.blackmanharris(self.fft_size)
|
mywindow = filter.window.blackmanharris(self.fft_size)
|
||||||
fft = gr.fft_vcc(self.fft_size, True, mywindow, True)
|
ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)
|
||||||
power = 0
|
power = 0
|
||||||
for tap in mywindow:
|
for tap in mywindow:
|
||||||
power += tap*tap
|
power += tap*tap
|
||||||
|
|
||||||
c2mag = gr.complex_to_mag_squared(self.fft_size)
|
c2mag = blocks.complex_to_mag_squared(self.fft_size)
|
||||||
|
|
||||||
# FIXME the log10 primitive is dog slow
|
# FIXME the log10 primitive is dog slow
|
||||||
#log = gr.nlog10_ff(10, self.fft_size,
|
#log = blocks.nlog10_ff(10, self.fft_size,
|
||||||
# -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
|
# -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
|
||||||
|
|
||||||
# Set the freq_step to 75% of the actual data throughput.
|
# Set the freq_step to 75% of the actual data throughput.
|
||||||
# This allows us to discard the bins on both ends of the spectrum.
|
# This allows us to discard the bins on both ends of the spectrum.
|
||||||
|
@ -195,13 +204,13 @@ class my_top_block(gr.top_block):
|
||||||
|
|
||||||
self.msgq = gr.msg_queue(1)
|
self.msgq = gr.msg_queue(1)
|
||||||
self._tune_callback = tune(self) # hang on to this to keep it from being GC'd
|
self._tune_callback = tune(self) # hang on to this to keep it from being GC'd
|
||||||
stats = gr.bin_statistics_f(self.fft_size, self.msgq,
|
stats = blocks.bin_statistics_f(self.fft_size, self.msgq,
|
||||||
self._tune_callback, tune_delay,
|
self._tune_callback, tune_delay,
|
||||||
dwell_delay)
|
dwell_delay)
|
||||||
|
|
||||||
# FIXME leave out the log10 until we speed it up
|
# FIXME leave out the log10 until we speed it up
|
||||||
#self.connect(self.u, s2v, fft, c2mag, log, stats)
|
#self.connect(self.u, s2v, ffter, c2mag, log, stats)
|
||||||
self.connect(self.u, s2v, fft, c2mag, stats)
|
self.connect(self.u, s2v, ffter, c2mag, stats)
|
||||||
|
|
||||||
if options.gain is None:
|
if options.gain is None:
|
||||||
# if no gain was specified, use the mid-point in dB
|
# if no gain was specified, use the mid-point in dB
|
||||||
|
|
Loading…
Reference in New Issue