Type Selectable GRC Blocks

Hi all,

I made a grc block that allows the user to select the input/output type
using a drop down box. For a while, it seemed like what I had
implemented
worked fine. Recently, however, only selecting the complex data type
works
reliably, the other types sometimes cause the flowgraph to stop
immediately
with no error output. In some flowgraphs the block runs all types, in
others it doesn’t.

I looked at the code and noticed that the first thing I do in
general_work
is the following:

const gr_complex *in = (const gr_complex *) input_items[0];
gr_complex *out = (gr_complex *) output_items[0];

This assumes the input/output types are gr_complex, which makes me think
is
causing the problems I’m seeing. I tried to look in other built-in
blocks
to see how they work but it hasn’t cleared up my confusion. For example,
in
‘Stream to Tagged Stream’, which lets users select the type, the lines
above are declared as follows:

const unsigned char *in = (const unsigned char *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];

Why would this work if the user selects complex type from GRC?

The big question is, how do I properly define the buffer pointer types
for
user selectable type blocks in the C++ code?

v/r,
Rich

On 07.07.2015 15:57, Richard B. wrote:

This assumes the input/output types are gr_complex, which makes me think
is causing the problems I’m seeing. I tried to look in other built-in
blocks to see how they work but it hasn’t cleared up my confusion. For
example, in ‘Stream to Tagged Stream’, which lets users select the type,
the lines above are declared as follows:

const unsigned char *in = (const unsigned char *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];

Why would this work if the user selects complex type from GRC?

Because the block itself is agnostic of the data, and ‘unsigned char’ is
a safe type to declare pointers. You’ll notice that we drag an ‘item
size’ attribute around which is then used for the actual data copying.

The big question is, how do I properly define the buffer pointer types
for user selectable type blocks in the C++ code?

There’s 2 cases: Either the block doesn’t care about the actual type
(e.g. as in stream to tagged stream), then you use the char-pointer +
item size. Or your block does care about the type, then you need to
reimplement the block for every type (e.g. the add blocks). We do have a
template mechanism for this, mind you.

M

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs