discuss-gnuradio
[Top][All Lists]
Advanced

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

Closing: GNU Radio 3.9.3.0 Python basic block - issues with, forecast an


From: Patric Müller
Subject: Closing: GNU Radio 3.9.3.0 Python basic block - issues with, forecast and produce
Date: Thu, 27 Jan 2022 11:59:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

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




reply via email to

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