WriteBlocksInPython¶
This is experimental work. The code can be found here:
http://gnuradio.org/cgit/jblum.git/log/?h=next
An advanced coding guide can be found here: BlocksCodingGuide
This work allows one to write a gnuradio block entirely in python
by overloading work() and doing the processing with numpy arrays.
The following interfaces are available:
- gr.basic_block - overload general work, call consume
- gr.sync_block - overload work, return num output items
- gr.decim_block - set decimation factor, overload work
- gr.interp_block - set interpolation factor, overload work
Some quick examples¶
Look at the QA code here for how to use:
http://gnuradio.org/cgit/jblum.git/tree/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py?h=next
Examples of message passing in QA code:
http://gnuradio.org/cgit/jblum.git/tree/gnuradio-core/src/python/gnuradio/gr/qa_msg_passing.py?h=next
Replacing example pkt.py with message passing framework:
http://gnuradio.org/cgit/jblum.git/tree/gr-digital/python/pkt2.py?h=next
IO Signatures¶
The block input and output signature should be a list of dtype arguments,
where each dtype argument can be passed into the numpy.dtype constructor.
Alternatively, if an IO has zero ports, you can pass None as the argument.
- Block with no output streams: None or []
- Each item is a complex float: [numpy.complex64]
- Each item is a 2x float vector: [(numpy.float32, 2)]
- Multiple input streams: [numpy.float32, numpy.int32]
Overloading work¶
Overload the work method in your class as follows:
def work(self, input_items, output_items):
#TODO insert work code here...
return len(output_items[0])
input_items and output_items is a list of numpy arrays.
Each numpy array in the items list represents a port.
The user should read from input_items and write to output_items.
And the user should return the number of output_items produced.
For those unfamiliar with numpy, read the following:
output_items[0] = my_data #incorrect, this only changes array references output_items[0][:] = my_data #correct, this assigns to the output buffer