I am using using ubuntu 12.10 i am trying to run a python block, namely OP2=
5, in GNU Radio Companion v3.6.3-35-g4435082f, which uses python version 2.=
7.3 for some reason although python3.2 is in the lib folder. I run the foll=
owing trace command in terminal:
~$ python -m trace --count -C . op25_grc.py
Here is the output with an error:
Imported legacy fsk4
Using Volk machine: ssse3_32
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in run_module_as_main
"_main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in run_code
exec code in run_globals
File "/usr/lib/python2.7/trace.py", line 819, in
main()
File "/usr/lib/python2.7/trace.py", line 807, in main
t.runctx(code, globs, globs)
File "/usr/lib/python2.7/trace.py", line 513, in runctx
exec cmd in globals, locals
File "op25_grc.py", line 493, in
tb =3D op25_grc()
File "op25_grc.py", line 231, in __init_
self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback)
File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", =
line 54, in getattr
return getattr(self._hb, name)
AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callbac=
k'
The code for "op25_grc.py":
#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Op25 Grc
# Generated: Wed Feb 13 19:37:41 2013
##################################################
from baz import message_callback
from baz import op25
from gnuradio import audio
from gnuradio import blks2
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import window
from gnuradio.eng_option import eng_option
from gnuradio.gr import firdes
from gnuradio.wxgui import fftsink2
from gnuradio.wxgui import forms
from gnuradio.wxgui import scopesink2
from gnuradio.wxgui import waterfallsink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import ConfigParser
import math
import wx
class op25_grc(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title=3D"Op25 Grc")
_icon_path =3D "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
##################################################
self._config_freq_config =3D ConfigParser.ConfigParser()
self._config_freq_config.read(".grc_op25")
try: config_freq =3D self._config_freq_config.getfloat("main", "freq")
except: config_freq =3D 434075000
self.config_freq =3D config_freq
self.freq =3D freq =3D config_freq
self._config_xlate_offset_config =3D ConfigParser.ConfigParser()
self._config_xlate_offset_config.read(".grc_op25")
try: config_xlate_offset =3D self._config_xlate_offset_config.getfloat("m=
ain", "xlate_offset")
except: config_xlate_offset =3D 0
self.config_xlate_offset =3D config_xlate_offset
self.click_freq =3D click_freq =3D freq-config_xlate_offset
self.xlate_offset_fine =3D xlate_offset_fine =3D 0
self.xlate_offset =3D xlate_offset =3D freq-click_freq
self.samp_rate =3D samp_rate =3D 48000
self.samp_per_sym =3D samp_per_sym =3D 5+1
self.decim =3D decim =3D 20
self._config_xlate_bandwidth_config =3D ConfigParser.ConfigParser()
self._config_xlate_bandwidth_config.read(".grc_rtl")
try: config_xlate_bandwidth =3D self._config_xlate_bandwidth_config.getfl=
oat("main", "xlate_bandwidth")
except: config_xlate_bandwidth =3D 24000
self.config_xlate_bandwidth =3D config_xlate_bandwidth
self.auto_tune_offset =3D auto_tune_offset =3D 0
self.xlate_bandwidth =3D xlate_bandwidth =3D config_xlate_bandwidth
self.variable_static_text_0 =3D variable_static_text_0 =3D freq+xlate_off=
set+xlate_offset_fine+auto_tune_offset
self.pre_channel_rate =3D pre_channel_rate =3D samp_rate/decim
self.gain =3D gain =3D 20
self.fine_click_freq =3D fine_click_freq =3D 0
self.channel_rate =3D channel_rate =3D op25.SYMBOL_RATE*samp_per_sym
self.auto_tune_offset_freq =3D auto_tune_offset_freq =3D auto_tune_offset=
*op25.SYMBOL_DEVIATION
self.audio_mul =3D audio_mul =3D 2
##################################################
# Message Queues
##################################################
op25_decoder_0_msgq_out =3D baz_message_callback_0_msgq_in =3D gr.msg_que=
ue(2)
##################################################
# Blocks
##################################################
_xlate_offset_fine_sizer =3D wx.BoxSizer(wx.VERTICAL)
self._xlate_offset_fine_text_box =3D forms.text_box(
parent=3Dself.GetWin(),
sizer=3D_xlate_offset_fine_sizer,
value=3Dself.xlate_offset_fine,
callback=3Dself.set_xlate_offset_fine,
label=3D"Fine Offset",
converter=3Dforms.float_converter(),
proportion=3D0,
)
self._xlate_offset_fine_slider =3D forms.slider(
parent=3Dself.GetWin(),
sizer=3D_xlate_offset_fine_sizer,
value=3Dself.xlate_offset_fine,
callback=3Dself.set_xlate_offset_fine,
minimum=3D-10000,
maximum=3D10000,
num_steps=3D1000,
style=3Dwx.SL_HORIZONTAL,
cast=3Dfloat,
proportion=3D1,
)
self.Add(_xlate_offset_fine_sizer)
self._xlate_offset_text_box =3D forms.text_box(
parent=3Dself.GetWin(),
value=3Dself.xlate_offset,
callback=3Dself.set_xlate_offset,
label=3D"Xlate Offset",
converter=3Dforms.float_converter(),
)
self.Add(self._xlate_offset_text_box)
_xlate_bandwidth_sizer =3D wx.BoxSizer(wx.VERTICAL)
self._xlate_bandwidth_text_box =3D forms.text_box(
parent=3Dself.GetWin(),
sizer=3D_xlate_bandwidth_sizer,
value=3Dself.xlate_bandwidth,
callback=3Dself.set_xlate_bandwidth,
label=3D"Xlate BW",
converter=3Dforms.float_converter(),
proportion=3D0,
)
self._xlate_bandwidth_slider =3D forms.slider(
parent=3Dself.GetWin(),
sizer=3D_xlate_bandwidth_sizer,
value=3Dself.xlate_bandwidth,
callback=3Dself.set_xlate_bandwidth,
minimum=3D5000,
maximum=3D50000,
num_steps=3D1000,
style=3Dwx.SL_HORIZONTAL,
cast=3Dfloat,
proportion=3D1,
)
self.Add(_xlate_bandwidth_sizer)
self.nb =3D self.nb =3D wx.Notebook(self.GetWin(), style=3Dwx.NB_TOP)
self.nb.AddPage(grc_wxgui.Panel(self.nb), "BB-1")
self.nb.AddPage(grc_wxgui.Panel(self.nb), "BB-2")
self.nb.AddPage(grc_wxgui.Panel(self.nb), "Xlate-1")
self.nb.AddPage(grc_wxgui.Panel(self.nb), "Xlate-2")
self.nb.AddPage(grc_wxgui.Panel(self.nb), "4FSK")
self.nb.AddPage(grc_wxgui.Panel(self.nb), "Dibits")
self.Add(self.nb)
self._auto_tune_offset_freq_static_text =3D forms.static_text(
parent=3Dself.GetWin(),
value=3Dself.auto_tune_offset_freq,
callback=3Dself.set_auto_tune_offset_freq,
label=3D"Auto tune",
converter=3Dforms.float_converter(),
)
self.Add(self._auto_tune_offset_freq_static_text)
_audio_mul_sizer =3D wx.BoxSizer(wx.VERTICAL)
self._audio_mul_text_box =3D forms.text_box(
parent=3Dself.GetWin(),
sizer=3D_audio_mul_sizer,
value=3Dself.audio_mul,
callback=3Dself.set_audio_mul,
label=3D"Audio mul",
converter=3Dforms.float_converter(),
proportion=3D0,
)
self._audio_mul_slider =3D forms.slider(
parent=3Dself.GetWin(),
sizer=3D_audio_mul_sizer,
value=3Dself.audio_mul,
callback=3Dself.set_audio_mul,
minimum=3D0,
maximum=3D10,
num_steps=3D100,
style=3Dwx.SL_HORIZONTAL,
cast=3Dfloat,
proportion=3D1,
)
self.Add(_audio_mul_sizer)
self.wxgui_waterfallsink2_0_0 =3D waterfallsink2.waterfall_sink_c(
self.nb.GetPage(3).GetWin(),
baseband_freq=3D0,
dynamic_range=3D100,
ref_level=3D50,
ref_scale=3D2.0,
sample_rate=3Dchannel_rate,
fft_size=3D512,
fft_rate=3D15,
average=3DFalse,
avg_alpha=3DNone,
title=3D"Waterfall Plot",
)
self.nb.GetPage(3).Add(self.wxgui_waterfallsink2_0_0.win)
self.wxgui_scopesink2_1 =3D scopesink2.scope_sink_f(
self.nb.GetPage(4).GetWin(),
title=3D"Scope Plot",
sample_rate=3Dchannel_rate,
v_scale=3D1.5,
v_offset=3D0,
t_scale=3D0.05,
ac_couple=3DFalse,
xy_mode=3DFalse,
num_inputs=3D1,
trig_mode=3Dgr.gr_TRIG_MODE_AUTO,
y_axis_label=3D"Counts",
)
self.nb.GetPage(4).Add(self.wxgui_scopesink2_1.win)
self.wxgui_scopesink2_0 =3D scopesink2.scope_sink_f(
self.nb.GetPage(5).GetWin(),
title=3D"Scope Plot",
sample_rate=3Dop25.SYMBOL_RATE,
v_scale=3D1,
v_offset=3D0,
t_scale=3D0.05,
ac_couple=3DFalse,
xy_mode=3DFalse,
num_inputs=3D1,
trig_mode=3Dgr.gr_TRIG_MODE_AUTO,
y_axis_label=3D"Counts",
)
self.nb.GetPage(5).Add(self.wxgui_scopesink2_0.win)
self.wxgui_fftsink2_0_0 =3D fftsink2.fft_sink_c(
self.nb.GetPage(2).GetWin(),
baseband_freq=3Dfine_click_freq,
y_per_div=3D10,
y_divs=3D10,
ref_level=3D0,
ref_scale=3D2.0,
sample_rate=3Dchannel_rate,
fft_size=3D1024,
fft_rate=3D30,
average=3DTrue,
avg_alpha=3DNone,
title=3D"FFT Plot",
peak_hold=3DFalse,
)
self.nb.GetPage(2).Add(self.wxgui_fftsink2_0_0.win)
def wxgui_fftsink2_0_0_callback(x, y):
self.set_fine_click_freq(x)
=09
self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback)
self._variable_static_text_0_static_text =3D forms.static_text(
parent=3Dself.GetWin(),
value=3Dself.variable_static_text_0,
callback=3Dself.set_variable_static_text_0,
label=3D"Final freq",
converter=3Dforms.float_converter(),
)
self.Add(self._variable_static_text_0_static_text)
self.op25_decoder_0 =3D op25.op25_decoder(channel_rate=3Dchannel_rate, de=
fer_creation=3DTrue, output_dibits=3DTrue, key=3D"")
self.op25_decoder_0.auto_tune_msgq =3D op25_decoder_0_msgq_out
self.op25_decoder_0.create()
self.gr_quadrature_demod_cf_0 =3D gr.quadrature_demod_cf((channel_rate/(2=
..0 * math.pi * op25.SYMBOL_DEVIATION)))
self.gr_multiply_const_vxx_0 =3D gr.multiply_const_vff((audio_mul, ))
self.gr_freq_xlating_fir_filter_xxx_0 =3D gr.freq_xlating_fir_filter_fcf(=
decim, (firdes.low_pass(1, samp_rate, xlate_bandwidth/2, 1000)), xlate_offs=
et+xlate_offset_fine-fine_click_freq-auto_tune_offset_freq, samp_rate)
self.gr_fir_filter_xxx_0 =3D gr.fir_filter_fff(1, ((1.0/samp_per_sym,)*sa=
mp_per_sym))
_gain_sizer =3D wx.BoxSizer(wx.VERTICAL)
self._gain_text_box =3D forms.text_box(
parent=3Dself.GetWin(),
sizer=3D_gain_sizer,
value=3Dself.gain,
callback=3Dself.set_gain,
label=3D"Gain",
converter=3Dforms.float_converter(),
proportion=3D0,
)
self._gain_slider =3D forms.slider(
parent=3Dself.GetWin(),
sizer=3D_gain_sizer,
value=3Dself.gain,
callback=3Dself.set_gain,
minimum=3D0,
maximum=3D50,
num_steps=3D100,
style=3Dwx.SL_HORIZONTAL,
cast=3Dfloat,
proportion=3D1,
)
self.Add(_gain_sizer)
self._freq_text_box =3D forms.text_box(
parent=3Dself.GetWin(),
value=3Dself.freq,
callback=3Dself.set_freq,
label=3D"Frequency",
converter=3Dforms.float_converter(),
)
self.Add(self._freq_text_box)
self.blks2_rational_resampler_xxx_1 =3D blks2.rational_resampler_ccc(
interpolation=3Dchannel_rate,
decimation=3Dpre_channel_rate,
taps=3DNone,
fractional_bw=3DNone,
)
self.blks2_rational_resampler_xxx_0 =3D blks2.rational_resampler_fff(
interpolation=3D44100,
decimation=3D8000,
taps=3DNone,
fractional_bw=3DNone,
)
self.baz_message_callback_0 =3D message_callback.message_callback(msgq=3D=
baz_message_callback_0_msgq_in, callback=3Dauto_tune_offset
, msg_part=3D"arg1", custom_parts=3D"", dummy=3DFalse)
=09
self.audio_source_0 =3D audio.source(samp_rate, "plughw:0,0", True)
self.audio_sink_0 =3D audio.sink(44100, "", True)
##################################################
# Connections
##################################################
self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.blks2_rati=
onal_resampler_xxx_1, 0))
self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.wxgui_fftsin=
k2_0_0, 0))
self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.wxgui_waterf=
allsink2_0_0, 0))
self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_quadratur=
e_demod_cf_0, 0))
self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_fir_filter_xxx_=
0, 0))
self.connect((self.gr_fir_filter_xxx_0, 0), (self.op25_decoder_0, 0))
self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_multiply_=
const_vxx_0, 0))
self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
self.connect((self.op25_decoder_0, 1), (self.wxgui_scopesink2_0, 0))
self.connect((self.gr_fir_filter_xxx_0, 0), (self.wxgui_scopesink2_1, 0))
self.connect((self.op25_decoder_0, 0), (self.blks2_rational_resampler_xxx=
_0, 0))
self.connect((self.audio_source_0, 0), (self.gr_freq_xlating_fir_filter_x=
xx_0, 0))
def get_config_freq(self):
return self.config_freq
def set_config_freq(self, config_freq):
self.config_freq =3D config_freq
self.set_freq(self.config_freq)
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq =3D freq
self._config_freq_config =3D ConfigParser.ConfigParser()
self._config_freq_config.read(".grc_op25")
if not self._config_freq_config.has_section("main"):
self._config_freq_config.add_section("main")
self._config_freq_config.set("main", "freq", str(self.freq))
self._config_freq_config.write(open(".grc_op25", 'w'))
self.set_variable_static_text_0(self.freq+self.xlate_offset+self.xlate_of=
fset_fine+self.auto_tune_offset)
self._freq_text_box.set_value(self.freq)
self.set_xlate_offset(self.freq-self.click_freq)
self.set_click_freq(self.freq-self.config_xlate_offset)
def get_config_xlate_offset(self):
return self.config_xlate_offset
def set_config_xlate_offset(self, config_xlate_offset):
self.config_xlate_offset =3D config_xlate_offset
self.set_click_freq(self.freq-self.config_xlate_offset)
def get_click_freq(self):
return self.click_freq
def set_click_freq(self, click_freq):
self.click_freq =3D click_freq
self.set_xlate_offset(self.freq-self.click_freq)
def get_xlate_offset_fine(self):
return self.xlate_offset_fine
def set_xlate_offset_fine(self, xlate_offset_fine):
self.xlate_offset_fine =3D xlate_offset_fine
self._config_xlate_offset_config =3D ConfigParser.ConfigParser()
self._config_xlate_offset_config.read(".grc_op25")
if not self._config_xlate_offset_config.has_section("main"):
self._config_xlate_offset_config.add_section("main")
self._config_xlate_offset_config.set("main", "xlate_offset", str(self.xla=
te_offset+self.xlate_offset_fine))
self._config_xlate_offset_config.write(open(".grc_op25", 'w'))
self.set_variable_static_text_0(self.freq+self.xlate_offset+self.xlate_of=
fset_fine+self.auto_tune_offset)
self._xlate_offset_fine_slider.set_value(self.xlate_offset_fine)
self._xlate_offset_fine_text_box.set_value(self.xlate_offset_fine)
self.gr_freq_xlating_fir_filter_xxx_0.set_center_freq(self.xlate_offset+s=
elf.xlate_offset_fine-self.fine_click_freq-self.auto_tune_offset_freq)
def get_xlate_offset(self):
return self.xlate_offset
def set_xlate_offset(self, xlate_offset):
self.xlate_offset =3D xlate_offset
self._config_xlate_offset_config =3D ConfigParser.ConfigParser()
self._config_xlate_offset_config.read(".grc_op25")
if not self._config_xlate_offset_config.has_section("main"):
self._config_xlate_offset_config.add_section("main")
self._config_xlate_offset_config.set("main", "xlate_offset", str(self.xla=
te_offset+self.xlate_offset_fine))
self._config_xlate_offset_config.write(open(".grc_op25", 'w'))
self.set_variable_static_text_0(self.freq+self.xlate_offset+self.xlate_of=
fset_fine+self.auto_tune_offset)
self._xlate_offset_text_box.set_value(self.xlate_offset)
self.gr_freq_xlating_fir_filter_xxx_0.set_center_freq(self.xlate_offset+s=
elf.xlate_offset_fine-self.fine_click_freq-self.auto_tune_offset_freq)
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate =3D samp_rate
self.set_pre_channel_rate(self.samp_rate/self.decim)
self.gr_freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.s=
amp_rate, self.xlate_bandwidth/2, 1000)))
def get_samp_per_sym(self):
return self.samp_per_sym
def set_samp_per_sym(self, samp_per_sym):
self.samp_per_sym =3D samp_per_sym
self.set_channel_rate(op25.SYMBOL_RATE*self.samp_per_sym)
self.gr_fir_filter_xxx_0.set_taps(((1.0/self.samp_per_sym,)*self.samp_per=
_sym))
def get_decim(self):
return self.decim
def set_decim(self, decim):
self.decim =3D decim
self.set_pre_channel_rate(self.samp_rate/self.decim)
def get_config_xlate_bandwidth(self):
return self.config_xlate_bandwidth
def set_config_xlate_bandwidth(self, config_xlate_bandwidth):
self.config_xlate_bandwidth =3D config_xlate_bandwidth
self.set_xlate_bandwidth(self.config_xlate_bandwidth)
def get_auto_tune_offset(self):
return self.auto_tune_offset
def set_auto_tune_offset(self, auto_tune_offset):
self.auto_tune_offset =3D auto_tune_offset
self.set_variable_static_text_0(self.freq+self.xlate_offset+self.xlate_of=
fset_fine+self.auto_tune_offset)
self.set_auto_tune_offset_freq(self.auto_tune_offset*op25.SYMBOL_DEVIATIO=
N)
def get_xlate_bandwidth(self):
return self.xlate_bandwidth
def set_xlate_bandwidth(self, xlate_bandwidth):
self.xlate_bandwidth =3D xlate_bandwidth
self._config_xlate_bandwidth_config =3D ConfigParser.ConfigParser()
self._config_xlate_bandwidth_config.read(".grc_rtl")
if not self._config_xlate_bandwidth_config.has_section("main"):
self._config_xlate_bandwidth_config.add_section("main")
self._config_xlate_bandwidth_config.set("main", "xlate_bandwidth", str(se=
lf.xlate_bandwidth))
self._config_xlate_bandwidth_config.write(open(".grc_rtl", 'w'))
self._xlate_bandwidth_slider.set_value(self.xlate_bandwidth)
self._xlate_bandwidth_text_box.set_value(self.xlate_bandwidth)
self.gr_freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.s=
amp_rate, self.xlate_bandwidth/2, 1000)))
def get_variable_static_text_0(self):
return self.variable_static_text_0
def set_variable_static_text_0(self, variable_static_text_0):
self.variable_static_text_0 =3D variable_static_text_0
self._variable_static_text_0_static_text.set_value(self.variable_static_t=
ext_0)
def get_pre_channel_rate(self):
return self.pre_channel_rate
def set_pre_channel_rate(self, pre_channel_rate):
self.pre_channel_rate =3D pre_channel_rate
def get_gain(self):
return self.gain
def set_gain(self, gain):
self.gain =3D gain
self._gain_slider.set_value(self.gain)
self._gain_text_box.set_value(self.gain)
def get_fine_click_freq(self):
return self.fine_click_freq
def set_fine_click_freq(self, fine_click_freq):
self.fine_click_freq =3D fine_click_freq
self.wxgui_fftsink2_0_0.set_baseband_freq(self.fine_click_freq)
self.gr_freq_xlating_fir_filter_xxx_0.set_center_freq(self.xlate_offset+s=
elf.xlate_offset_fine-self.fine_click_freq-self.auto_tune_offset_freq)
def get_channel_rate(self):
return self.channel_rate
def set_channel_rate(self, channel_rate):
self.channel_rate =3D channel_rate
self.wxgui_scopesink2_1.set_sample_rate(self.channel_rate)
self.gr_quadrature_demod_cf_0.set_gain((self.channel_rate/(2.0 * math.pi =
* op25.SYMBOL_DEVIATION)))
self.wxgui_fftsink2_0_0.set_sample_rate(self.channel_rate)
self.wxgui_waterfallsink2_0_0.set_sample_rate(self.channel_rate)
def get_auto_tune_offset_freq(self):
return self.auto_tune_offset_freq
def set_auto_tune_offset_freq(self, auto_tune_offset_freq):
self.auto_tune_offset_freq =3D auto_tune_offset_freq
self._auto_tune_offset_freq_static_text.set_value(self.auto_tune_offset_f=
req)
self.gr_freq_xlating_fir_filter_xxx_0.set_center_freq(self.xlate_offset+s=
elf.xlate_offset_fine-self.fine_click_freq-self.auto_tune_offset_freq)
def get_audio_mul(self):
return self.audio_mul
def set_audio_mul(self, audio_mul):
self.audio_mul =3D audio_mul
self._audio_mul_slider.set_value(self.audio_mul)
self._audio_mul_text_box.set_value(self.audio_mul)
self.gr_multiply_const_vxx_0.set_k((self.audio_mul, ))
if __name__ =3D=3D '__main__':
parser =3D OptionParser(option_class=3Deng_option, usage=3D"%prog: [option=
s]")
(options, args) =3D parser.parse_args()
tb =3D op25_grc()
tb.Run(True)
and the code from "hier_block2_.py":
#
# Copyright 2006,2007 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_core import hier_block2_swig
try:
import pmt
except ImportError:
from gruel import pmt
#
# This hack forces a 'has-a' relationship to look like an 'is-a' one.
#
# It allows Python classes to subclass this one, while passing through
# method calls to the C++ class shared pointer from SWIG.
#
# It also allows us to intercept method calls if needed
#
class hier_block2(object):
"""
Python wrapper around the C++ hierarchical block implementation.
Provides convenience functions and allows proper Python subclassing.
"""
def __init__(self, name, input_signature, output_signature):
"""
Create a hierarchical block with a given name and I/O signatures.
"""
self._hb =3D hier_block2_swig(name, input_signature, output_signature)
def __getattr__(self, name):
"""
Pass-through member requests to the C++ object.
"""
if not hasattr(self, "_hb"):
raise RuntimeError("hier_block2: invalid state--did you forget =
to call gr.hier_block2.__init__ in a derived class?")
return getattr(self._hb, name)
def connect(self, *points):
"""
Connect two or more block endpoints. An endpoint is either a (bloc=
k, port)
tuple or a block instance. In the latter case, the port number is =
assumed
to be zero.
To connect the hierarchical block external inputs or outputs to int=
ernal block
inputs or outputs, use 'self' in the connect call.
If multiple arguments are provided, connect will attempt to wire th=
em in series,
interpreting the endpoints as inputs or outputs as appropriate.
"""
if len (points) < 1:
raise ValueError, ("connect requires at least one endpoint; %d =
provided." % (len (points),))
else:
if len(points) =3D=3D 1:
self._hb.primitive_connect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._connect(points[i-1], points[i])
def _connect(self, src, dst):
(src_block, src_port) =3D self._coerce_endpoint(src)
(dst_block, dst_port) =3D self._coerce_endpoint(dst)
self._hb.primitive_connect(src_block.to_basic_block(), src_port,
dst_block.to_basic_block(), dst_port)
def _coerce_endpoint(self, endp):
if hasattr(endp, 'to_basic_block'):
return (endp, 0)
else:
if hasattr(endp, "__getitem__") and len(endp) =3D=3D 2:
return endp # Assume user put (block, port)
else:
raise ValueError("unable to coerce endpoint")
def disconnect(self, *points):
"""
Disconnect two endpoints in the flowgraph.
To disconnect the hierarchical block external inputs or outputs to =
internal block
inputs or outputs, use 'self' in the connect call.
If more than two arguments are provided, they are disconnected succ=
essively.
"""
if len (points) < 1:
raise ValueError, ("disconnect requires at least one endpoint; =
%d provided." % (len (points),))
else:
if len (points) =3D=3D 1:
self._hb.primitive_disconnect(points[0].to_basic_block())
else:
for i in range (1, len (points)):
self._disconnect(points[i-1], points[i])
def _disconnect(self, src, dst):
(src_block, src_port) =3D self._coerce_endpoint(src)
(dst_block, dst_port) =3D self._coerce_endpoint(dst)
self._hb.primitive_disconnect(src_block.to_basic_block(), src_port,
dst_block.to_basic_block(), dst_port)
def msg_connect(self, src, srcport, dst, dstport):
self.primitive_msg_connect(src.to_basic_block(), srcport, dst.to_ba=
sic_block(), dstport);
def msg_disconnect(self, src, srcport, dst, dstport):
self.primitive_msg_disconnect(src.to_basic_block(), srcport, dst.to=
_basic_block(), dstport);
def message_port_register_hier_in(self, portname):
self.primitive_message_port_register_hier_in(pmt.pmt_intern(portnam=
e));
def message_port_register_hier_out(self, portname):
self.primitive_message_port_register_hier_out(pmt.pmt_intern(portna=
me));
My goal is to fix the error: AttributeError: "'gr_hier_block2_sptr' object =
has no attribute 'set_callback'" so that the block "op25_grc.py" will run i=
n GNU radio companion. =20
i have been unable to find any sort of solution to this problem anywhere. =
some have said its a version problem with GNUradio but as i posted above i =
have the latest version.
Any help will be greatly appreciated. Thank you very much!