Hi Federico and Jeff,

thank you very much for your prompt answer. As I thought, it was a
"newbie" mistake :-) I have modified my block according to what Federico
has written and now it works.

Regards,

Ralf

Am 02.12.2021 um 12:31 schrieb Jeff Long:
[I just saw the response from Federico as I was writing this, so it's
partly a duplicate]

In work(), items are in terms of vectors, so you need to store
off blk_size in the constructor. In work(), you would copy blk_size *
noutput_items. For an example, take a look at the source for any of
the built-in blocks that can take a vector, e.g.,

https://github.com/gnuradio/gnuradio/blob/master/gr-blocks/include/gnuradio/blocks/abs_blk.h
https://github.com/gnuradio/gnuradio/blob/master/gr-blocks/lib/abs_blk_impl.h
https://github.com/gnuradio/gnuradio/blob/master/gr-blocks/lib/abs_blk_impl.cc

On Thu, Dec 2, 2021 at 5:26 AM Ralf Gorholt <ralf.gorh...@gmx.de> wrote:

    Dear all,

    I am quite new to GNU Radio and in order to see how GNU Radio blocks
    work I would like to create my own block that (for the moment) just
    copies complex data from the input to the output. This works as
    long as
    I copy only one number but not when I want to copy packets of numbers
    that come from the preceeding block. My block takes one parameter:
    blk_size. I would like to insert it in my DVB-T receiver flowgraph to
    analyze data (in a later step).

    I had a look at the square_ff example and other blocks to see how
    they
    are built but I still don't see what I am doing wrong. It must be a
    silly mistake. Perhaps you can help me? Here is the code:

    myblock_impl::myblock_impl(int blk_size)
             : gr::block("myblock",
                     gr::io_signature::make(1, 1, blk_size *
    sizeof(gr_complex)),
                     gr::io_signature::make(1, 1, blk_size *
    sizeof(gr_complex)))
         {
         }

    void
         myblock_impl::forecast(int noutput_items, gr_vector_int
    &ninput_items_required)
         {
             ninput_items_required[0] = noutput_items;
         }

    int
         myblock_impl::general_work(int noutput_items,
                                    gr_vector_int &ninput_items,
                                    gr_vector_const_void_star
    &input_items,
                                    gr_vector_void_star &output_items)
         {
             const gr_complex *in = (const gr_complex *) input_items[0];
             gr_complex *out = (gr_complex *) output_items[0];

             for (int i = 0; i < noutput_items; i++) {
                 out[i] = in[i];
             }

             consume_each(noutput_items);

             return noutput_items;
         }

    And the YML file:

    id: dl5eu_myblock
    label: myblock
    category: '[dl5eu]'

    templates:
       imports: import dl5eu
       make: dl5eu.myblock(${blk_size})

    parameters:
    - id: blk_size
       label: Block size
       dtype: int
       default: '1'

    inputs:
    - label: in
       domain: stream
       dtype: complex
       vlen: ${blk_size}
       optional: '0'

    outputs:
    - label: out
       domain: stream
       dtype: complex
       vlen: ${blk_size}
       optional: '0'

    file_format: 1

    Thank you very much for your help!

    Kind regards,

    Ralf

Reply via email to