I’m having problem with my first created OutOfTree block in gnuradio
with the command “gr_modtool.py add -t general -l python”. As a first
trial, I wanted to have an output signal that toggle every cycle. In the
gnu radio companion, I have a signal source of 1K with a sample rate of
20K. It is connected to a throttle with the same sample rate. Then it
goes into my block my_trigger2, which then goes to channel 1 of a QT GUI
Time Sink. The channel 0 being connected at the output of the throttle.
On the QT GUI, I can see the 1 kHz signal as expected. The expected
behavior of my signal would have been a signal that toggle every cycle
(value 0.25 and 0.5) so 10 kHz signal. Instead, I get a signal that
toggles every second or so, which I don’t understand why.
I also tried to generate a block as a sync_block with the same behavior.
If I connect the input_items on output_items, then I get the expected 1
kHz signal. The problem seem to be around the pulse2 variable but I
tried different coding tricks without any success.
Any idea what is the problem?
Here’s my python code:
#!/usr/bin/env python
-- coding: utf-8 --
import numpy
from gnuradio import gr
class my_trigger2(gr.basic_block):
pulse2 = 0
def __init__(self):
gr.basic_block.__init__(self,
name="my_trigger2",
in_sig=[numpy.float32],
out_sig=[numpy.float32])
def forecast(self, noutput_items, ninput_items_required):
#setup size of input_items[i] for work call
for i in range(len(ninput_items_required)):
ninput_items_required[i] = noutput_items
def general_work(self, input_items, output_items):
in0 = input_items[0]
out0 = output_items[0]
if my_trigger2.pulse2 == 0.25:
my_trigger2.pulse2 = 0.5
else:
my_trigger2.pulse2 = 0.25
output_items[0][:] = my_trigger2.pulse2
self.consume(0, len(input_items[0]))
return len(output_items[0])
The xml code is:
<?xml version="1.0"?> my_trigger2 my_blocks_my_trigger2 my_blocks import my_blocks my_blocks.my_trigger2() in float out float