yun.fu
yun.fu

Reputation: 21

gnuradio: how to change the noutput_items dynamically when writing OOT block?

When I make a OOT block in gnuradio

class mod(gr.sync_block):
"""
docstring for block mod
"""
def __init__(self):
    gr.sync_block.__init__(self,
        name="mod",
        in_sig=[np.byte],
        out_sig=[np.complex64])
def work(self, input_items, output_items):
    in0 = input_items[0]
    out = output_items[0]
    result=do(....)
    out[:]=result
    return len(output_items[0])

I get:

ValueError: could not broadcast input array from shape (122879) into shape (4096)

How can I solve it?
GRC is as below:
selector :input index and output index are controlled by WX GUI Chooser block
FSK4 MOD: modulate fsk4 signal and write data to raw.bin
FSK4 DEMOD : read data from raw.bin and demodulate

file source -> /////// -> FSK4 MOD -> FSK4 DEMOD -> NULL SINK
               selector 
file source -> //////  -> GMKS MOD -> GMSK DEMOD ->NULL SINK

when the input index or output index is changed,the whole flow graph will be not responding.

Upvotes: 0

Views: 2975

Answers (1)

Marcus Müller
Marcus Müller

Reputation: 36352

There's two things:

  1. You have a bug somewhere, and the solution is not to change something, but fix that bug. The full Python error message will tell you exactly in which line the error is.

  2. noutput_items is a variable that GNU Radio sets at runtime to let you know how much output you might produce in this call to work. Hence, it's not something you can set, but it's something your work method must respect.

I think it's fair to assume that you're not very aware of how GNU Radio works:

GNU Radio is based on calling your block's work function when there is enough output space available and enough input items to process. The amount of output space that your block can use is passed to your work as a parameter, and will change between calls to work.

I very strongly recommend going through chapters 1-3 of the official Guided Tutorials if you haven't already. We always try to keep these tutorials up-to-date.

EDIT: Your command shows that you have not really understood what I meant, sorry. So: GNU Radio calls your work method over and over again while it's executing.

For example, it might call work with 4000 input items and 4000 output items space (you have a sync block, therefore number of input==number of output). Your work processes the first 1000 of that, and therefore return 1000. So there's 3000 items left.

Now, the upstream block does something, so there's 100 new items. Because the 3000 from before are still there, your block's work will get called with 3100 items.

Your work processes any number of items, and returns that number. GNU Radio makes sure that the "remaining" items stay available and will call your work again if there is enough in- our output.

Upvotes: 4

Related Questions