discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] GrExtras - write blocks in python, message passin


From: Martin Braun
Subject: Re: [Discuss-gnuradio] GrExtras - write blocks in python, message passing, misc features...
Date: Wed, 6 Jun 2012 12:52:47 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Jun 02, 2012 at 10:52:50AM -0700, Josh Blum wrote:
> Most of the description is in the wiki page:
> https://github.com/guruofquality/grextras/wiki
> 
> And here is a handy coding guide for more detail:
> https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide

Hi Josh,

I'm not quite behind all of this yet. Here's two questions, if you could
spare a minute:

First thing I tried was the Python blocks, and I wrote a random number
generator (yep, I know that already exists, but I just wanted something
simple to start with).
Q: Why can't I assign arrays to output_items? See the code:

<snip>
from gnuradio import gr
import gnuradio.extras
import numpy
MAXRND = 1000

class rng_i(gr.block):
    " random number generator "
    def __init__(self):
        gr.block.__init__(self, name="rng_i", in_sig=None, 
out_sig=[numpy.int32])

    def work(self, input_items, output_items):
        # Doesn't work:
        #output_items[0] = numpy.array(numpy.random.randint(0, MAXRND, 
len(output_items[0])), dtype=numpy.int32)[:]
        # Works:
        for i in xrange(len(output_items[0])):
            output_items[0][i] = numpy.random.randint(0, MAXRND)
        return len(output_items[0])
</snip>

I'm assuming it's something like copy vs. reference, but I thought I was
doing everything right.


Q: The first argument of post_msg, is this simply == the number of
stream ports? Say I have one stream output and one msg output, do I
always post to port 1?
Reason I ask is you mention 'group indexes' and I'm not sure what that
means.

Apart from that, I quite like your code and would like to lobby towards
getting some of it into the mainline repository. Now I just have to come
up with something useful to do with it :)

MB

-- 
Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin Braun
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT -- University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association



reply via email to

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