Re: [Discuss-gnuradio] custom work function gets into an endless loop

2015-09-29 Thread Ron Economos
The dvb_bbheader_bb_impl.cc module in gr-dtv also uses 
set_output_multiple().


Ron

On 09/28/2015 08:36 PM, Kolya wrote:

Hi Martin and Sylvain,

I obviously didn't understand the forecast function properly but with your
help it works now. I tried both:

set_output_multiple & a correct forecast()
and
set_output_multiple & set_relative_rate

both approaches worked as expected :)

What threw me off was that I had based my forecast on the forecast function
in gr-dtv's dvb_bbheader_bb_impl.cc and in that example it seems to work.

I also appreciate the pointer to the logging infrastructure and I will adopt
that too. The crc32_bb is next on the list of files to dissect and learn
from. That is good stuff!

This is a great mailing list. Thanks so much for your help.

- Kolya



___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] custom work function gets into an endless loop

2015-09-28 Thread Kolya
Hi Martin and Sylvain,

I obviously didn't understand the forecast function properly but with your
help it works now. I tried both: 

set_output_multiple & a correct forecast() 
and 
set_output_multiple & set_relative_rate

both approaches worked as expected :)

What threw me off was that I had based my forecast on the forecast function
in gr-dtv's dvb_bbheader_bb_impl.cc and in that example it seems to work.

I also appreciate the pointer to the logging infrastructure and I will adopt
that too. The crc32_bb is next on the list of files to dissect and learn
from. That is good stuff!

This is a great mailing list. Thanks so much for your help.

- Kolya



--
View this message in context: 
http://gnuradio.4.n7.nabble.com/custom-work-function-gets-into-an-endless-loop-tp56304p56323.html
Sent from the GnuRadio mailing list archive at Nabble.com.

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] custom work function gets into an endless loop

2015-09-28 Thread Sylvain Munaut
> /void
> bbframer_bb_impl::forecast (int noutput_items, gr_vector_int
> _items_required)
> {
> ninput_items_required[0] = ((noutput_items - 32) / 8); // 32 bit
> postamble
> }/

You should make sure forecast can never return <0 or even ==0 numbers.
Returning 0 means you can produce output without input and the only
valid case for it is either a 'source' block, or if you _know_ that
you have currently buffered data and you can produce output without
any further inputs.


Cheers,

   Sylvain

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] custom work function gets into an endless loop

2015-09-28 Thread Martin Braun
On 27.09.2015 15:25, Kolya wrote:
> Hi,
> 
> I'm trying to build a custom block that takes in a stream of input samples
> and simply adds a postamble of 32bits every 352 bits. The package structure
> is illustrated below (payload_bits = msg_bits+postamble_bits):
> ---
> |   msg_bits = 352 |  postamble_bits = 32  |
> ---
> 
> For some reason the code below gets into an endless loop when I run it
> through a test and stimulate it with a non-repeating vector source. The
> debug printf statements show that the loop keeps iterating even without
> input.
> I derived from gr_block because the number of output samples is higher than

I'm guessing you mean gr::block? If so, that's the correct choice.

>   }
> #ifdef VERBOSE
>   printf(">>> offset= %d\n",out_offset);
>   printf(">>> consumed= %d\n",consumed);
> #endif

FYI, we have a great logging infrastructure for these kinds of things,
see http://gnuradio.org/doc/doxygen/page_logger.html.

>   this->consume_each(consumed);
>   return out_offset;
> }/
> 
> I also overrode the forecast function to account for the fact that fewer
> input samples are needed than output samples are produced:
> 
> /void
> bbframer_bb_impl::forecast (int noutput_items, gr_vector_int
> _items_required)
> {
> ninput_items_required[0] = ((noutput_items - 32) / 8); // 32 bit
> postamble
> }/

There's several issues here. First, your math is broken; you want
ninput_items_required to always be a positive, non-zero number which
you're not checking. Say it's 0, then that means it's fine to call your
work function with no input. What you want is something like
'(noutput_items / 47) * 44.
Second, you don't necessarily need forecast. If your packet size is
always the same, I recommend using set_output_multiple and
relative_rate. Or you can even use tagged streams, check out crc32_bb
which does pretty much the same as your block, albeit at varying packet
lengths.

Cheers,
M



___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


[Discuss-gnuradio] custom work function gets into an endless loop

2015-09-27 Thread Kolya
Hi,

I'm trying to build a custom block that takes in a stream of input samples
and simply adds a postamble of 32bits every 352 bits. The package structure
is illustrated below (payload_bits = msg_bits+postamble_bits):
---
|   msg_bits = 352 |  postamble_bits = 32  |
---

For some reason the code below gets into an endless loop when I run it
through a test and stimulate it with a non-repeating vector source. The
debug printf statements show that the loop keeps iterating even without
input.
I derived from gr_block because the number of output samples is higher than
the number of input samples and the work function is shown below:


/void bbframer_bb_impl::general_work(int noutput_items,
gr_vector_int _items,
gr_vector_const_void_star _items,
gr_vector_void_star _items)
{
  const unsigned char *in = (const unsigned char *) input_items[0];
  unsigned char *out = (unsigned char *) output_items[0];
  int out_offset = 0;
  int consumed = 0;

  for (int i = 0; i < noutput_items; i += (int)(payload_bits/8)) {

  for (int j = 0; j < (int)(msg_bits / 8); j++) {   // 
Input index loop
(byte-index)

  out[out_offset++]=in[consumed++];
  }
  // now add add postamble
  out[out_offset++]=0x00;
  out[out_offset++]=0x01;
  out[out_offset++]=0x02;
  out[out_offset++]=0x03;
  }
#ifdef VERBOSE
  printf(">>> offset= %d\n",out_offset);
  printf(">>> consumed= %d\n",consumed);
#endif

  this->consume_each(consumed);
  return out_offset;
}/

I also overrode the forecast function to account for the fact that fewer
input samples are needed than output samples are produced:

/void
bbframer_bb_impl::forecast (int noutput_items, gr_vector_int
_items_required)
{
ninput_items_required[0] = ((noutput_items - 32) / 8); // 32 bit
postamble
}/


Any feedback would be greatly appreciated.
- Kolya



--
View this message in context: 
http://gnuradio.4.n7.nabble.com/custom-work-function-gets-into-an-endless-loop-tp56304.html
Sent from the GnuRadio mailing list archive at Nabble.com.

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio