Hello,
I am am new to the gnuradio system and I have a USRP1 board running
gnuradio-3.0.2 (I have a box that was setup with this older version).
I modified the usrp_oscope.py and scopesink.py code to run without the gui
(files attached). I then decided to measure the time taken to retrieve a
message from the msgq. I find that the time taken (at a decimrate of 256,
128, or 64) to get a single msg from the msgq (using msgq.delete_head())
to be anywhere between 30 - 60ms. This seems to be particularly high. I do
have USB 2.0 on my machine. I also tried this with different fusb_nlocks
and fusb_block_size params but I still get the same delay.
I have looked at the mailing list archive and I haven't really a post with
the same issue.
Would anybody know why I might be seeing this error?
thanks,
Rohan
#!/usr/bin/env python
from gnuradio import gr, gru
from gnuradio import usrp
from gnuradio import eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import sys
import rnm_scopesink
def pick_subdevice(u):
"""
The user didn't specify a subdevice on the command line.
If there's a daughterboard on A, select A.
If there's a daughterboard on B, select B.
Otherwise, select A.
"""
if u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem
return (0, 0)
if u.db[1][0].dbid() >= 0:
return (1, 0)
return (0, 0)
class app_flow_graph(gr.flow_graph):
def __init__(self):
gr.flow_graph.__init__(self)
parser = OptionParser(option_class=eng_option)
parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
help="select USRP Rx side A or B (default=first one with a daughterboard)")
parser.add_option("-d", "--decim", type="int", default=16,
help="set fgpa decimation rate to DECIM [default=%default]")
parser.add_option("-f", "--freq", type="eng_float", default=None,
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("-8", "--width-8", action="store_true", default=False,
help="Enable 8-bit samples across USB")
parser.add_option("-n", "--frame-decim", type="int", default=1,
help="set oscope frame decimation factor to n [default=1]")
parser.add_option("-v", "--v-scale", type="eng_float", default=1000,
help="set oscope frame decimation factor to n [default=1]")
parser.add_option("-v", "--v-scale", type="eng_float", default=1000,
help="set oscope initial V/div to SCALE [default=%default]")
parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6,
help="set oscope initial s/div to SCALE [default=50us]")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.print_help()
sys.exit(1)
self.show_debug_info = True
# build the graph
self.u = usrp.source_c(decim_rate=options.decim,
nchan=1,
fusb_block_size=2048,
fusb_nblocks=4)
if options.rx_subdev_spec is None:
options.rx_subdev_spec = pick_subdevice(self.u)
self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
if options.width_8:
width = 8
shift = 8
format = self.u.make_format(width, shift)
print "format =", hex(format)
r = self.u.set_format(format)
# determine the daughterboard subdevice we're using
self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
input_rate = self.u.adc_freq() / self.u.decim_rate()
self.scope = modified_scopesink.scope_sink_c(self, sample_rate=input_rate,
frame_decim=options.frame_decim,
v_scale=options.v_scale,
t_scale=options.t_scale)
self.connect(self.u, self.scope)
# set initial values
if options.gain is None:
# if no gain was specified, use the mid-point in dB
g = self.subdev.gain_range()
options.gain = float(g[0]+g[1])/2
if options.freq is None:
# if no freq was specified, use the mid-point
r = self.subdev.freq_range()
options.freq = float(r[0]+r[1])/2
self.set_gain(options.gain)
if not(self.set_freq(options.freq)):
print "Failed to set initial frequency"
def set_freq(self, target_freq):
"""
Set the center frequency we're interested in.
@param target_freq: frequency in Hz
@rypte: bool
Tuning is a two step process. First we ask the front-end to
tune as close to the desired frequency as it can. Then we use
the result of that operation and our target_frequency to
determine the value for the digital down converter.
"""
r = usrp.tune(self.u, 0, self.subdev, target_freq)
if r:
# update displayed value
#print "Setting freq to " + str(target_freq)
# update displayed value
#print "Setting freq to " + str(target_freq)
return True
return False
def set_gain(self, gain):
#print "Setting gain to " + str(gain)
self.subdev.set_gain(gain)
def set_decim(self, decim):
ok = self.u.set_decim_rate(decim)
if not ok:
print "set_decim failed"
input_rate = self.u.adc_freq() / self.u.decim_rate()
self.scope.set_sample_rate(input_rate)
if self.show_debug_info: # update displayed values
print "decim = " + str(self.u.decim_rate())
print "[EMAIL PROTECTED] = " + str(self.u.adc_freq() / self.u.decim_rate())
return ok
def main():
fg = app_flow_graph()
fg.run()
if __name__ == '__main__':
main()
#!/usr/bin/env python
from gnuradio import gr, gru, eng_notation
import Numeric
import threading
import struct
import sys
import os
import time
default_scopesink_size = (640, 240)
default_v_scale = 1000
default_frame_decim = 25
class scope_sink_f(gr.hier_block):
def __init__(self, fg, sample_rate=1,
size=default_scopesink_size, frame_decim=default_frame_decim,
v_scale=default_v_scale, t_scale=None):
msgq = gr.msg_queue(16) # message queue that holds at most 2 messages
self.guts = gr.oscope_sink_f(sample_rate, msgq)
gr.hier_block.__init__(self, fg, self.guts, self.guts)
def set_sample_rate(self, sample_rate):
self.guts.set_sample_rate(sample_rate)
self.win.info.set_sample_rate(sample_rate)
class scope_sink_c(gr.hier_block):
def __init__(self, fg, sample_rate=1,
size=default_scopesink_size, frame_decim=default_frame_decim,
v_scale=default_v_scale, t_scale=None):
self.msgq = gr.msg_queue(16) # message queue that holds at most 2 messages
c2f = gr.complex_to_float()
self.guts = gr.oscope_sink_f(sample_rate, self.msgq)
fg.connect((c2f, 0), (self.guts, 0))
fg.connect((c2f, 1), (self.guts, 1))
gr.hier_block.__init__(self, fg, c2f, self.guts)
self.input_watcher = input_watcher(self, frame_decim)
def set_sample_rate(self, sample_rate):
self.guts.set_sample_rate(sample_rate)
class input_watcher (threading.Thread):
def __init__ (self, fg, frame_decim, name="inputwatcher"):
threading.Thread.__init__ (self, name="inputwatcher")
self.setDaemon (1)
self.fg = fg
self.msgq = fg.msgq
self.frame_decim = frame_decim
self.iscan = 0
self.keep_running = True
self.count = 0
self.start ()
def run (self):
while count < 500:
t0 = time.time()
msg = self.msgq.delete_head()
t1 = time.time()
diff = (t1 - t0) * 1000 #in ms
print `dt`
return
_______________________________________________
Discuss-gnuradio mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio