discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Read/Write stream tags in Python


From: Josh Blum
Subject: Re: [Discuss-gnuradio] Read/Write stream tags in Python
Date: Fri, 13 Jul 2012 13:26:58 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

Aha, I knew I had unit tests.

Study these carefully:
https://github.com/guruofquality/grextras/blob/master/python/qa_block_gateway.py#L104

And just for sanity, make sure that "make test" passed for you :-)

-josh

On 07/13/2012 01:20 PM, Anisha Gorur wrote:
> Also, I've been assuming that nitems_written/read is from gr_block_detail,
> and add_item_tag is from gr_block and that they have both been swigged,
> since you used them in your example. Is it possible that they haven't been?
> Thanks
> -Anisha
> 
> On Fri, Jul 13, 2012 at 3:57 PM, Anisha Gorur <address@hidden> wrote:
> 
>> I don't think I'm writing the work function...
>>
>>
>> def work(self, input_items, output_items):
>>         item_index = 1 #which output item gets the tag?
>>         offset =  self.nitems_written(0) + item_index
>>         key = pmt.pmt_string_to_symbol("example_key")
>>         value = pmt.pmt_string_to_symbol("example_value")
>>
>>         self.add_item_tag(0, offset, key, value)
>> #call work function
>> self.work(self.gr_vector_source_x_0, self.gr_file_sink_0)
>>
>> Error: AttributeError: 'gr_top_block_sptr' object has no attribute
>> 'nitems_written'
>>
>>
>> On Fri, Jul 13, 2012 at 3:25 PM, Josh Blum <address@hidden> wrote:
>>
>>>
>>>
>>> On 07/13/2012 12:08 PM, Anisha Gorur wrote:
>>>> Thanks for the examples, I will definitely be looking into them!
>>>> As for links, This one: http://gnuradio.org/cgit/jblum.git/log/?h=nextis
>>>> broken, it comes from one of the blocks coding guide here:
>>>>
>>> http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide/diff/2which
>>>> i found really helpful.
>>>>
>>>
>>> There was a lot of work in various branches off of gnuradio which I had
>>> merged into next. That branch is gone, and that work has been combined
>>> into the GrExtras project. The link and relevant coding guide was
>>> moved/updated: https://github.com/guruofquality/grextras/wiki
>>>
>>>> I also had one more quick question, I'm getting this error:
>>>> 'gr_top_block_sptr' object has no attribute 'add_item_tag', though I
>>>> thought add_item_tag was inherited from gr_block.
>>>> Thanks again!
>>>>
>>>
>>> Not sure, you might send a code snippet. It looks like you are calling a
>>> method of the top block, and not from the block's work function?
>>>
>>> -josh
>>>
>>>> On Fri, Jul 13, 2012 at 2:40 PM, Josh Blum <address@hidden> wrote:
>>>>
>>>>>
>>>>>
>>>>> On 07/13/2012 10:08 AM, Anisha Gorur wrote:
>>>>>> Thanks!
>>>>>> Do you by any chance have links to specific code examples that could
>>> help
>>>>>> out? I've been trying to look at old examples you have posted to
>>> others
>>>>> on
>>>>>> this forum, however, some of the links from github seem to be broken.
>>>>>>
>>>>>
>>>>> Well, I dont have an example from python, but its just the same thing
>>>>> without semicolons. So this should be very helpful:
>>>>> http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/examples/c++/
>>>>>
>>>>> Let me know if the links are bad on one of my wiki pages.
>>>>> At least I can fix those :-)
>>>>>
>>>>> -josh
>>>>>
>>>>>> On Fri, Jul 13, 2012 at 12:52 PM, Josh Blum <address@hidden> wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 07/13/2012 08:51 AM, Anisha Gorur wrote:
>>>>>>>> Hello all,
>>>>>>>> I've been trying to work with stream tags in python, mainly using
>>> the
>>>>>>>> grextras blocks coding guide
>>>>>>>> here:https://github.com/guruofquality/grextras/wiki/Blo...
>>>>>>>> <
>>>>>>>
>>>>>
>>> https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide#wiki-the-work-function
>>>>>>>> .
>>>>>>>>
>>>>>>>> I've set up a very simple flow graph, just a vector source, throttle
>>>>> and
>>>>>>>> file sink, and I would like to place a tag on the first element of
>>> the
>>>>>>>> vector that contains time metadata. I'm using this code:
>>>>>>>>
>>>>>>>> def work(self, input_items, output_items):
>>>>>>>> item_index = ? #which output item gets the tag?
>>>>>>>
>>>>>>> set item_index to x so the tag gets associated with
>>> outputs_items[0][x]
>>>>>>>
>>>>>>>> offset = self.nitems_written(0) + item_index
>>>>>>>> key = pmt.pmt_string_to_symbol("example_key")
>>>>>>>> value = pmt.pmt_string_to_symbol("example_value")
>>>>>>>>
>>>>>>>> #write at tag to output port 0 with given absolute item offset
>>>>>>>> self.add_item_tag(0, offset, key, value)
>>>>>>>>
>>>>>>>> I think the problem has something to do with not implementing the
>>>>>>>> correct modules. My question is, what are the appropriate modules to
>>>>>>>> import to read and write stream tags in python?
>>>>>>>>
>>>>>>>
>>>>>>> You might want to look more that that coding guide, at lot of the
>>>>>>> snippets are just work functions, but many contain full class
>>>>>>> definitions with import statements. For example:
>>>>>>>
>>>>>>> from gnuradio import gr
>>>>>>> import gnuradio.extras
>>>>>>>
>>>>>>> class my_sync_block(gr.block):
>>>>>>>
>>>>>>>     def __init__(self, args):
>>>>>>>         gr.block.__init__(self, name="my block",
>>> in_sig=[numpy.int32],
>>>>>>> out_sig=[numpy.int32])
>>>>>>>
>>>>>>>     def work(self, input_items, output_items):
>>>>>>>         #work stuff...
>>>>>>>         return len(output_items[0])
>>>>>>>
>>>>>>> -josh
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Discuss-gnuradio mailing list
>>>>>>> address@hidden
>>>>>>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>> --
>> Anisha Gorur
>> Class of 2012
>> Electrical Engineering
>>
>>
> 
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]