discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] My custom GRC block outputs thousands of unwanted


From: Kevin Reid
Subject: Re: [Discuss-gnuradio] My custom GRC block outputs thousands of unwanted NULL characters - what am I doing wrong?
Date: Fri, 1 Feb 2019 18:07:52 -0800

On Fri, Feb 1, 2019 at 10:00 AM Jeffrey M. Rose <address@hidden> wrote:
I wrote a custom GRC block called gensup_ff that receives a stream of “0” and “1” characters and is supposed to output a stream of of only the “1” characters it received.

In my flowgraph, I have a file sink that sinks these “1” characters into a file.

However, when I open the file, not only does it have the “1” characters but it has thousands of unwanted NULL characters, too.

I'm not familiar with writing blocks using general_work in detail, but I can see one definite problem:

        if (in[i] == '1')
        {
           one_count++;
           out[i] = in[i];
        }     

Here you are copying your '1's into the i-th position of out, not the next one. So this accounts for the extra characters — they may be the uninitialized part of your output buffer that you did not write. Instead, you need to keep track of the next index into the output buffer you want to write into. In your particular case, that's the same as one_count, if you copy before incrementing it.

Additionally, you could be writing past the end of the output buffer (potential memory corruption), whose size is specified by the noutput_items parameter (not ninput_items). In principle, you should stop processing input as soon as you have written noutput_items items (and tell GR that you only consumed however many items that was); it may be that with the forecast() you have, the output buffer will always be that big; I don't know.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]