Some doubts in using gr_modtool

Given below is the constructor in vector_to_stream block. The block size
is
passed as a parameter to the constructor.

vector_to_stream_impl::vector_to_stream_impl(size_t itemsize, size_t

nitems_per_block)
: sync_interpolator (“vector_to_stream”,
io_signature::make (1, 1, itemsize *
nitems_per_block),
io_signature::make (1, 1, itemsize),
nitems_per_block)
{
}

Suppose I don’t know the block size before hand, and I want to pass a
parameter “x” to toe constructor such that block size can be obtained
from
x using certain computation (that will be defined inside the
constructor).
Can I do this? If so how?

When I add a new block “encoder”, to the module “ldpc”, modtool add
files
“include/ldpc/encoder.h”, “lib/encoder_impl.cc”, and
“lib/encoder_impl.h”.
And the work function is to be declared and defined in encoder_impl.h
and
encoder_impl.cc respectively. Consider that I have the function “encode”
defined and declared in ldpc.h and ldpc.cc respectively. ldpc.* does not
define any signal processing block, so I don’t add them using modtool.
But
they are required as they have the definition for the “encode” function
and
inside the work function in encoder_impl.cc I just want to call the
encode
function defined inside this ldpc class.

Am I supposed to put ldpc.h in inlclude/ldpc/ and ldpc.cc in lib/? Or
should I put both of them inside lib/ ? Which section of CMakeLists.txt
am
I supposed to modify?

Hi Manu!

Suppose I don’t know the block size before hand, and I want to pass a parameter
“x” to toe constructor such that block size can be obtained from x using certain
computation (that will be defined inside the constructor). Can I do this? If so
how?
Yes, that’s possible inside the constructor only. See the
gr::basic_block::set_{in,out}put_signature(gr::io_signature::sptr)
doxygen.
When I add a new block “encoder”, to the module “ldpc”, modtool add files
“include/ldpc/encoder.h”, “lib/encoder_impl.cc”, and “lib/encoder_impl.h”. And the
work function is to be declared and defined in encoder_impl.h and encoder_impl.cc
respectively. Consider that I have the function “encode” defined and declared in
ldpc.h and ldpc.cc respectively. ldpc.* does not define any signal processing
block, so I don’t add them using modtool. But they are required as they have the
definition for the “encode” function and inside the work function in
encoder_impl.cc I just want to call the encode function defined inside this ldpc
class.

Am I supposed to put ldpc.h in inlclude/ldpc/ and ldpc.cc in lib/? Or should I
put both of them inside lib/ ? Which section of CMakeLists.txt am I supposed to
modify?
Yes, that would be the correct structure.
Just add ldpc.cc to lib/CMakeLists.txt:

list_append (APPEND projectname_sources
encoder_impl.cc

ldpc.cc )

Happy Hacking!

PS:You should also the include_directuries(${library_INCLUDE_DIR}) for
each external library you use to that file if you haven’t done so; same
applies for target_link_libraries)

Hey Marcus,

Thanks a lot.

On Sun, Sep 8, 2013 at 1:28 PM, Marcus M. [email protected] wrote:

Hi Manu!

Suppose I don’t know the block size before hand, and I want to pass a

parameter “x” to toe constructor such that block size can be obtained from
x using certain computation (that will be defined inside the constructor).
Can I do this? If so how?

Yes, that’s possible inside the constructor only. See the
gr::basic_block::set_{in,out}**put_signature(gr::io_**signature::sptr)
doxygen.

That worked!

Am I supposed to put ldpc.h in inlclude/ldpc/ and ldpc.cc in lib/? Or
should I put both of them inside lib/ ? Which section of CMakeLists.txt am
I supposed to modify?

Yes, that would be the correct structure.
Just add ldpc.cc to lib/CMakeLists.txt:

It is not clear which option you meant. Both ldpc.h and ldpc.cc inside
lib *
OR* should I put .h inside include/ldpc/ ?

*Hi,

*I have a block which copies a block of input to output. The constructor
is
defined as shown below.
*
#######################################################################
copy_bb_impl::copy_bb_impl(int block_length)
{
d_block_length = block_length;
set_input_signature(gr::io_signature::make(1, 1, sizeof(char) *
d_block_length));
set_output_signature(gr::io_signature::make(1, 1, sizeof(char) *
d_block_length));
}
#######################################################################

make runs. Given below is the output for ctest -V


manu@iota build $ ctest -V
UpdateCTestConfiguration from
:/home/manu/gr-ldpc/build/DartConfiguration.tcl
UpdateCTestConfiguration from
:/home/manu/gr-ldpc/build/DartConfiguration.tcl
Test project /home/manu/gr-ldpc/build
Constructing a list of tests
Done constructing a list of tests
Checking test dependency graph…
Checking test dependency graph end
test 1
Start 1: test_ldpc

1: Test command: /bin/sh
“/home/manu/gr-ldpc/build/lib/test_ldpc_test.sh”
1: Test timeout computed to be: 9.99988e+06
1:
1:
1/2 Test #1: test_ldpc … Passed 0.00 sec
test 2
Start 2: qa_copy_bb

2: Test command: /bin/sh
“/home/manu/gr-ldpc/build/python/qa_copy_bb_test.sh”
2: Test timeout computed to be: 9.99988e+06
2: gr::vmcircbuf_sysv_shm: shmget(1): Invalid argument
2: gr::buffer::allocate_buffer: failed to allocate buffer of size
5894500 KB
2: terminate called after throwing an instance of ‘std::bad_alloc’
2: what(): std::bad_alloc
2: Aborted
2/2 Test #2: qa_copy_bb …***Failed 0.22 sec

50% tests passed, 1 tests failed out of 2

Total Test time (real) = 0.23 sec

The following tests FAILED:
2 - qa_copy_bb (Failed)
Errors while running CTest

While if I define the constructor as given below, ctest run without
failures.

#########################################################################
copy_bb_impl::copy_bb_impl(int block_length)
: gr::sync_block(“copy_bb”,
gr::io_signature::make(1, 1, sizeof(char) * block_length),
gr::io_signature::make(1, 1, sizeof(char) *
block_length)),
d_block_length(block_length)
{
}
#########################################################################

Any suggestion why the first constructor is running into errors?

Issue solved by defining the constructor as given below.

############################################################
copy_bb_impl::copy_bb_impl(int block_length)
: gr::sync_block(“copy_bb”,
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0)),
d_block_length(block_length)
{
set_input_signature(gr::io_signature::make(1, 1, sizeof(char) *
d_block_length));
set_output_signature(gr::io_signature::make(1, 1, sizeof(char) *
d_block_length));
}
#############################################################

Hi Manu,

lib OR should I put .h inside include/ldpc/ ?

ldpc.h goes to /include/ldpc.
You have to realize what your build system does: it takes your .cc files
and turns them to compilation units (which manifest itselves as .o
each), and link them together to your library (something like
libgr-projectname.so).
Your .h’s are only there for your compiler so it can find your
declarations, so they should be available for the compiler to find when
you do something like
#include “ldpc/ldpc.h”
and should therefore be in a directory that the compiler will look into
when searching for includes. On the other hand, they don’t implement any
functionality by themselves, and will not compile into anything useful,
so they don’t belong into your Makefile.

Hope that helped explaining why what belongs where,
greetings,
Marcus