diff options
-rw-r--r-- | code/.grc_gnuradio/my_block.py | 30 | ||||
-rw-r--r-- | code/.grc_gnuradio/my_block.xml | 82 | ||||
-rw-r--r-- | code/README | 1 | ||||
-rw-r--r-- | code_devel.md | 12 |
4 files changed, 121 insertions, 4 deletions
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 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Add Block: +## all types, 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>my_block</name> + <key>my_block_key</key> + <category>My Block</category> + +<!-- This section is Cheetah Script +--> + <import>import my_block</import> + <make>my_block.MyBlock() +self.$(id).set_parameters($value) + </make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option><name>F32_F32</name><key>f32_f32</key></option> + <option><name>S32_S32</name><key>s32_s32</key></option> + <option><name>S16_S16</name><key>s16_s16</key></option> + <option><name>S8_S8</name><key>s8_s8</key></option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>2</value> + <type>int</type> + </param> + + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + + <!-- My Block parameter, this value is used to sum with input; and pass that as output of my block + --> + <param> + <name>Value</name> + <key>value</key> + <value>1</value> + <type>int</type> + </param> + + <!-- + Check if number of inputs are greater than 0, and if vector length + is greater than 0. + --> + <check>$num_inputs > 0</check> + <check>$vlen > 0</check> + + <!-- + Input of the block + --> + <sink> + <name>in</name> + <type>$(str($type).split('_')[0])</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> + + <!-- + Output of the block + --> + <source> + <name>out</name> + <type>$(str($type).split('_')[1])</type> + <vlen>$vlen</vlen> + </source> + <doc> + Your Documentation Goes Here + + This block outputs sum of value and input and prints "Hello World" onto the terminal + output = input + value + </doc> +</block> 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. diff --git a/code_devel.md b/code_devel.md index afaadff..edccd3b 100644 --- a/code_devel.md +++ b/code_devel.md @@ -20,13 +20,17 @@ To know more, here's link to it's [official page](http://forge.scilab.org/index. Sandhi uses GNU Radio (GR) V3.6 with GNU Radio Companion(GRC) as its front-end. [GNU Radio](http://gnuradio.org/redmine/projects/gnuradio/wiki) is open source software for implementing software radio visually through flowgraphs and blocks. A flow graph in GNU Radio is visual representation of data flow between two or more nodes, and these nodes are called blocks (which process the flowing data). Sandhi inherits this capability of intuitively implementing logic through flowgraph which makes it a good LabVIEW replacement. ### Coding a simple block -Since sandhi is still in beta stages, some of user-specific block may be missing; but this is not really a problem, since a user with limited python experience can create block himself/herself using Sandhi's framework. To follow a descriptive, step-by-step and conventional guide check GNU Radio's [Out of Tree Module](http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules). This section will present a rapid but unconventional approach: +Since sandhi is still in beta stages, some of user-specific block may be missing; but this is not really a problem, since a user with limited python experience can create block himself/herself using Sandhi's framework. To follow a descriptive, step-by-step and conventional guide check GNU Radio's [Out of Tree Module](http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules). A block can be either coded in python or C++; but given python is easier to start with, we prefer coding in python. This section will present a rapid but unconventional approach: #### Overview -A block in Sandhi essentially requires two things:<br> -1.A xml file (front end block description which is parsed by GRC to display that block.) -2.A python file (which describes how the block functions.) +A block in Sandhi essentially requires two things: +1. A xml file (front end block description which is parsed by GRC to display that block.) +2. A python file (which describes how the block functions.) +Sandhi, by default, reads any xml block present in ~/.grc_gnuradio. Hence all our initial development will be done in the .grc_gnuradio folder. + +#### Sample code +Sample code is availabe with annotations [here](code/.grc_gnuradio/) |