[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss-gnuradio] custom work function gets into an endless loop
From: |
Kolya |
Subject: |
[Discuss-gnuradio] custom work function gets into an endless loop |
Date: |
Sun, 27 Sep 2015 15:25:21 -0700 (MST) |
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 &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_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
&ninput_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] custom work function gets into an endless loop,
Kolya <=