# Input items vs Output items

**URL:** <https://www.ruby-forum.com/t/input-items-vs-output-items/241602>\
**Category:** GNU Radio\
**Created:** [April 18, 2015, 2:59pm UTC](https://www.ruby-forum.com/t/input-items-vs-output-items/241602 "2015-04-18T14:59:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [April 18, 2015, 2:59pm UTC](https://www.ruby-forum.com/t/input-items-vs-output-items/241602/1 "2015-04-18T14:59:30Z")

</div>

I am slightly confused with the way you implement a general work  
function - here is my AX25 decoder which takes in bits and outputs  
decoded packets in text format as a stream of 8 bit integers. This was  
based on the general work example in the GR tutorial.

int ax25\_impl::general\_work (int noutput\_items,  
gr\_vector\_int &ninput\_items,  
gr\_vector\_const\_void\_star &input\_items,  
gr\_vector\_void\_star &output\_items)  
{  
int i;  
const char \*bit = (const char \*) input\_items[0];  
out = (char \*) output\_items[0];

d\_numchars=0;  
for (i=0;i \<noutput\_items; i++)  
{  
hdlc\_rxbit( bit[i] );  
}

// Tell runtime system how many output items we produced.  
consume\_each (noutput\_items);  
return d\_numchars;  
}

I keep a tally of how many characters I output in the class member  
variable d\_numchars. I do this by initially printing to the “out”  
buffer (see above code) with the vsprintf() function and then using  
the strlen() function to find out how long the out string is.

It works for a while, perhaps 200-300 packets and then crashes with a  
segfault and error 7. I know the crash is related to the number of  
output items because if I reduce the number of characters I output it  
will run for longer. If I don’t output anything its fine, but not very  
useful.

It gets complicated because the block outputs nothing at all until it  
decodes a packet, then it outputs that entire packet, which might be  
up to 1000 characters or so.

I think I have made a fundamental error somewhere. Finding it is  
proving problematic. I am also confused by ninput\_items and  
noutput\_items variables as to me they appear reversed but that is how  
they are in the tutorial.

Mike

---

<div class="post-metadata">

**Author:** ![vh1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vh1](https://www.ruby-forum.com/u/vh1)\
**Post date:** [April 18, 2015, 3:38pm UTC](https://www.ruby-forum.com/t/input-items-vs-output-items/241602/2 "2015-04-18T15:38:10Z")

</div>

I should have added, the packet decoding is based on Volkers rather  
nifty gr-ax25, which I think is based on earlier implementations so I  
don’t think that is where the bug is. I have heavily modified that code  
as I am using BPSK demodulator but the hdlc parts are the same.

Mike

---

<div class="post-metadata">

**Author:** ![vh1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vh1](https://www.ruby-forum.com/u/vh1)\
**Post date:** [April 18, 2015, 3:48pm UTC](https://www.ruby-forum.com/t/input-items-vs-output-items/241602/3 "2015-04-18T15:48:01Z")

</div>

Hi Mike,

you might actually be doing something redundant here:  
GNU Radio actually keeps tabs on how many items you produced; just call  
nitems\_written(0) to get that number.

I don’t really understand where your string comes from or where it ends  
up, but do make sure your string isn’t going to be longer than your  
noutput\_items.

Generally, this is something that can most probably best be analyzed  
using appropriate debugging methods – I’d like to point you to [1].  
As soon as you find out where your segfault happens, it will be easier  
to understand under which conditions it happens. Also, GDB allows you to  
`print` the value of local variables, so that might actually shine quite  
a light on what goes wrong 🙂

On a more general note: what your block seems to do looks very much like  
what tagged stream blocks (probably after gr-ax25) were designed to do.  
Have a look at [2]; maybe I’m misjudging the situation, maybe you’re  
already using the TSB facilities.

Greetings,  
Marcus

[1] [http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsGDB](http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsGDB)  
[2] [http://gnuradio.org/doc/doxygen/page\_tagged\_stream\_blocks.html](http://gnuradio.org/doc/doxygen/page_tagged_stream_blocks.html)

---

<div class="post-metadata">

**Author:** ![vh1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vh1](https://www.ruby-forum.com/u/vh1)\
**Post date:** [April 18, 2015, 6:45pm UTC](https://www.ruby-forum.com/t/input-items-vs-output-items/241602/4 "2015-04-18T18:45:36Z")

</div>

Also, to point out existing work, there is an HDLC framer and deframer  
in  
Gnuradio now. The deframer takes in a byte stream, 1 bit per byte, and  
outputs PDUs with your HDLC frames.

–n

On Sat, Apr 18, 2015 at 6:46 AM, Marcus Müller  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
