From 56dfdfd2885446138edd210c42e0ef70d07d1dc2 Mon Sep 17 00:00:00 2001 From: manojgudi Date: Sat, 15 Mar 2014 20:31:21 +0530 Subject: added sample my_block code --- code/.grc_gnuradio/my_block.py | 30 +++++++++++++++ code/.grc_gnuradio/my_block.xml | 82 +++++++++++++++++++++++++++++++++++++++++ code/README | 1 + 3 files changed, 113 insertions(+) create mode 100644 code/.grc_gnuradio/my_block.py create mode 100644 code/.grc_gnuradio/my_block.xml create mode 100644 code/README (limited to 'code') diff --git a/code/.grc_gnuradio/my_block.py b/code/.grc_gnuradio/my_block.py new file mode 100644 index 0000000..2c3dffc --- /dev/null +++ b/code/.grc_gnuradio/my_block.py @@ -0,0 +1,30 @@ +import gras +import numpy + +class MyBlock(gras.Block): + + def __init__(self): + gras.Block.__init__(self, + name="my_block", + in_sig=[numpy.float32, numpy.float32], # input and output are 32bit numpy float datatype + out_sig=[numpy.float32]) + + + def set_parameters(self, value): + self.value = value + + # Here's where you define the function of block | This function runs for each input value + def work(self, input_items, output_items): + + # output_items is a double array | first index corresponds to output port which starts from 0 + # since we have only one output, first index is 0 + # the item has to be an array even if it is a single integer + output_items[0][:1] = input_items[0][:1] + self.value + + print "Output Value", output_items[0][:1] + print "Hello World" + + # These lines report to GNU Radio how many items were consumed and produced + self.consume(0, 1) # Consume one item from input port 0 + self.produce(0, 1) # Produce one item from output port 0 + diff --git a/code/.grc_gnuradio/my_block.xml b/code/.grc_gnuradio/my_block.xml new file mode 100644 index 0000000..36326ca --- /dev/null +++ b/code/.grc_gnuradio/my_block.xml @@ -0,0 +1,82 @@ + + + + my_block + my_block_key + My Block + + + import my_block + my_block.MyBlock() +self.$(id).set_parameters($value) + + + IO Type + type + enum + + + + + + + Num Inputs + num_inputs + 2 + int + + + + Vec Length + vlen + 1 + int + + + + + Value + value + 1 + int + + + + $num_inputs > 0 + $vlen > 0 + + + + in + $(str($type).split('_')[0]) + $vlen + $num_inputs + + + + + out + $(str($type).split('_')[1]) + $vlen + + + Your Documentation Goes Here + + This block outputs sum of value and input and prints "Hello World" onto the terminal + output = input + value + + diff --git a/code/README b/code/README new file mode 100644 index 0000000..f6225a8 --- /dev/null +++ b/code/README @@ -0,0 +1 @@ +This folder contains a hidden folder .grc_gnuradio/ which has sample code. -- cgit