Hello Johannes and hello Marcus,
thank you both for the suggestions and explanations, it really helps a
lot and is much appreciated!
With your explanations, I was able to produce my minimal working
example, which I have linked below.
> The best place to check for specifics about Python blocks is here:
> https://github.com/gnuradio/gnuradio/blob/main/gnuradio-runtime/python/gnuradio/gr/gateway.py
>
> This is the interface that is implemented. The `forecast` method is
> implemented in L153ff. It is different from the C++ version.
Thanks for this hint, I've taken a look at the implementation. Also
thanks for the suggestion with `bpython3` it is a really nice tool. For
now my block works without the `forecast` method so I won't bother
implementing it for now. I think it makes more sense to implement
`forecast` if I should decide to work with a C++ block.
> The mechanism is that the scheduler asks forecast what it needs to produce the largest
> amount of output that the output buffer can deal with, then it halves the amount until it
> hits the minimum number. If none of these requests yield a fulfillable input requirement,
> the block is permanently input-blocked.
Also thanks for clearing this up and explaining it Marcus!
> First off, the `consume_each` call needs to go behind any read on the
> input buffer. You really tell the system at this point: I'm finally done
> with these items, do whatever. Since GR is a multi-threaded system, this
> may cause trouble because the samples you want to read are already
> overwritten.
>
>
> So let's comment on your `general_work`.
>
> > def general_work(self, input_items, output_items):
> > # Firstly check, if input_items has a sufficient amount of items
> > if len(input_items[0]) >= self.buffer_len:
> > # Then consume exactly self.buffer_len items
> > self.consume_each(self.buffer_len)
> `consume_each` should go after the last use of `input_items`.
The comment, together with your explanation makes perfect sense, I have
changed it accordingly.
> > # Now only output a fraction of the input items, say the first
> > self.out_items, on output port[0]
> > output_items[0] = input_items[0][:self.out_items]
> This is probably the line causing issues. Try
> `output_items[0][0:self.out_items] = input_items[0][0:self.out_items]`
> The difference is the left hand indexing. Now, you write items to
> positions in an array. Previously, you overwrote the array and replaced
> it with a new one. Thus, the output buffer was still full of zeros.
Changing this line was the last missing piece, the minimal example now
works! I have posted my working minimal example here:
https://pastebin.com/qxgnPcpL
And with that I would like to close this problem, thanks again for the
feedback!
Kind regards,
Patric
No comments:
Post a Comment