I am trying to build a sync block with Kurtosis capability using gr_modtool.
I used to make them with sink blocks, but decided to remake them with sync blocks.
The code itself can be compiled without error.
But when I run the flow graph in GRC, it produces following error message.
It appears when you try to return the number of items consumed.
Question: How to solve this error?
Thank you in advance for any guidance you may be able to provide.
WARNING:gnuradio.grc.core.platform.block_loader:Block with id "Kurtosis_Kurtosis_c" loaded from
/usr/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_c.block.yml
overwritten by
/usr/local/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_c.block.yml
WARNING:gnuradio.grc.core.platform.block_loader:Block with id "Kurtosis_Kurtosis_p" loaded from
/usr/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_p.block.yml
overwritten by
/usr/local/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_p.block.yml
WARNING:gnuradio.grc.core.platform.block_loader:Block with id "Kurtosis_Kurtosis_c" loaded from
/usr/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_c.block.yml
overwritten by
/usr/local/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_c.block.yml
WARNING:gnuradio.grc.core.platform.block_loader:Block with id "Kurtosis_Kurtosis_p" loaded from
/usr/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_p.block.yml
overwritten by
/usr/local/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_p.block.yml
WARNING:gnuradio.grc.core.platform.block_loader:Block with id "Kurtosis_Kurtosis_c" loaded from
/usr/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_c.block.yml
overwritten by
/usr/local/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_c.block.yml
WARNING:gnuradio.grc.core.platform.block_loader:Block with id "Kurtosis_Kurtosis_p" loaded from
/usr/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_p.block.yml
overwritten by
/usr/local/share/gnuradio/grc/blocks/Kurtosis_Kurtosis_p.block.yml
Generating: '/home/nomo/j.py'
Executing: /usr/bin/python3 -u /home/nomo/j.py
0
7
python3: ../gnuradio-runtime/lib/../include/gnuradio/buffer.h:193: unsigned int gr::buffer::index_add(unsigned int, unsigned int): Assertion `s < d_bufsize' failed.
Below is the implmentation source file:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "Kurtosis_only_c_impl.h"
namespace gr {
namespace Kurtosis_only {
using input_type = gr_complex;
using output_type = gr_complex;
Kurtosis_only_c::sptr
Kurtosis_only_c::make(int large_loop, int small_loop)
{
return gnuradio::get_initial_sptr
(new Kurtosis_only_c_impl(large_loop, small_loop));
}
/*
* The private constructor
*/
Kurtosis_only_c_impl::Kurtosis_only_c_impl(int large_loop, int small_loop)
: gr::sync_block("Kurtosis_only_c",
gr::io_signature::make(1, 1, sizeof(input_type) * small_loop),
gr::io_signature::make(2, 2, sizeof(output_type) * small_loop)),
d_LL(large_loop), d_SL(small_loop)
{
}
/*
* Our virtual destructor.
*/
Kurtosis_only_c_impl::~Kurtosis_only_c_impl()
{
}
void Kurtosis_only_c_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required)
{
for (unsigned int i = 0; i < ninput_items_required.size(); ++i)
ninput_items_required[i] = d_SL;
}
int
Kurtosis_only_c_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
/*printf("sizeof(gr_compelx) = %ld", sizeof(gr_complex));
printf("sizeof(gr_complex) * small_loop = %ld", sizeof(gr_complex) * d_SL);
printf("in0 = %d, out0 = %d", input_items, output_items);
printf("d_N = %d", d_SL);*/
auto in0 = static_cast<const input_type*>(input_items[0]);
auto out0 = static_cast<output_type*>(output_items[0]);
auto out1 = static_cast<output_type*>(output_items[1]);
gr_complex S1r[d_SL], S1i[d_SL], S2r[d_SL], S2i[d_SL], S3r[d_SL], S3i[d_SL],
S4r[d_SL], S4i[d_SL];
gr_complex dcnt[d_SL];
gr_complex Myu1r[d_SL], Myu1i[d_SL], Myu2r[d_SL], Myu2i[d_SL], Myu3r[d_SL],
Myu3i[d_SL], Myu4r[d_SL], Myu4i[d_SL];
gr_complex M1r[d_SL], M1i[d_SL], M2r[d_SL], M2i[d_SL], M3r[d_SL], M3i[d_SL], M4r[d_SL],
M4i[d_SL];
gr_complex Kr[d_SL], Ki[d_SL];
/*for (int k = 0; k < noutput_items; k += d_SL)
{
unsigned int datasize = noutput_items - k;
unsigned int resid = d_SL - d_index;*/
for(unsigned int j = 0; j < d_LL; ++j)
{
for(unsigned int i = 0; i < d_SL; ++i)
{
pwr = in0[i].real();
pwi = in0[i].imag();
S1r[i] += pwr;
S1i[i] += pwi;
S2r[i] += pwr * pwr;
S2i[i] += pwi * pwi;
S3r[i] += pwr * pwr * pwr;
S3i[i] += pwi * pwi * pwi;
S4r[i] += pwr * pwr * pwr * pwr;
S4i[i] += pwi * pwi * pwi * pwi;
dcnt[i] += 1;
}
}
for(unsigned int i = 0; i < d_SL; ++i)
{
Myu1r[i] = S1r[i] / dcnt[i];
Myu1i[i] = S1i[i] / dcnt[i];
Myu2r[i] = S2r[i] / dcnt[i];
Myu2i[i] = S2i[i] / dcnt[i];
Myu3r[i] = S3r[i] / dcnt[i];
Myu3i[i] = S3i[i] / dcnt[i];
Myu4r[i] = S4r[i] / dcnt[i];
Myu4i[i] = S4i[i] / dcnt[i];
}
gr_complex a = 4, b = 6, c = 3, d = 2;
for(unsigned int i = 0; i < d_SL; ++i)
{
M1r[i] = a * Myu3r[i] * Myu1r[i];
M1i[i] = a * Myu3i[i] * Myu1i[i];
M2r[i] = b * Myu2r[i] * pow(Myu1r[i], d);
M2i[i] = b * Myu2i[i] * pow(Myu1i[i], d);
M3r[i] = c * pow(Myu1r[i], a);
M3i[i] = c * pow(Myu1i[i], a);
M4r[i] = Myu2r[i] - pow(Myu1r[i], d);
M4i[i] = Myu2i[i] - pow(Myu1i[i], d);
}
for(unsigned int i = 0; i < d_SL; ++i)
{
Kr[i] = (Myu4r[i] - M1r[i] + M2r[i] - M3r[i]) / pow(M4r[i], d);
Ki[i] = (Myu4i[i] - M1i[i] + M2i[i] - M3i[i]) / pow(M4i[i], d);
}
for(unsigned int i = 0; i < d_SL; ++i)
{
out0[i] = Kr[i];
out1[i] = Ki[i];
}
return 0;
}
} /* namespace Kurtosis_only */
} /* namespace gr */
Below is the header file.
#ifndef INCLUDED_KURTOSIS_ONLY_KURTOSIS_ONLY_C_IMPL_H
#define INCLUDED_KURTOSIS_ONLY_KURTOSIS_ONLY_C_IMPL_H
#include <Kurtosis_only/Kurtosis_only_c.h>
namespace gr {
namespace Kurtosis_only {
class Kurtosis_only_c_impl : public Kurtosis_only_c
{
private:
gr_complex pwr;
gr_complex pwi;
int d_LL;
int d_SL;
int d_index = 0;
public:
Kurtosis_only_c_impl(int large_loop, int small_loop);
~Kurtosis_only_c_impl();
void forecast(int nouput_items, gr_vector_int &ninput_items_required) override;
// Where all the action really happens
int work(
int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items
);
};
} // namespace Kurtosis_only
} // namespace gr
#endif /* INCLUDED_KURTOSIS_ONLY_KURTOSIS_ONLY_C_IMPL_H */
You're assuming you can simply produce and consume d_SL
items. That is not generally the case. As explained in the comments to my previous answer (and at the end of said answer), you need to check whether you have enough in- and output space.