discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] Writing own gnuradio Block, optional output port


From: Marcus Müller
Subject: Re: [Discuss-gnuradio] Writing own gnuradio Block, optional output port
Date: Wed, 16 Dec 2015 23:51:30 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

How many ports GRC enforces depends on the .xml file in your module's grc/ folder, so you will have to add a
<optional>1/<optional>
to the respective <soruce> definition in your .xml.

Regarding operating on out1 iff there's a second output port:
you can either overwrite the check_topology()[1] method and memorize the number of output streams, or you can just use the fact that work()[2] is called with a


gr_vector_void_star output_items 
which is but a typedef for a std::vector<void*>, which means it's a vector of pointers to your output buffers. And hence, the number of available output buffers is just
output_items.size().

You must NEVER write to out1=output_items[1] if there is only one stream. That would be a bug, and in most cases actually lead to a segmentation fault and cancellation of your program.

Best regards,
Marcus

[1] https://gnuradio.org/doc/doxygen/classgr_1_1basic__block.html#aca13d6f083397aada5b44d0f349ce151
[2] https://gnuradio.org/doc/doxygen/classgr_1_1sync__block.html#a38942c5d8bee5232404ab71ada9a3956

On 16.12.2015 23:40, Charles Bridger wrote:
I've created a signal source and want to create a second port which outputs
the same signal, except one sample behind. The problem I'm having is that I
don't know how to make it "optional". If I change the code in the private
constructor from:


[Constructor Code}
...
gr::io_signature::make(1,1,sizeof(float)),
....

 to

gr::io_signature::make(1,2,sizeof(float)),

It still makes me  plug something into the port when I use the block in
GRC, even when I don't want to use the second output port.

I don't know if my code in the work method is relevant but I address the tw
output ports like this:

float *out0 = (float *) output_items[0];
float *out1 = (float *) output_items[1];

for(int i = 0; i < noutput_items; i++)
{
    out0[i] = stuff;
    out1[i] = stuff - 1; // <- I want that to be optional when I put the
block in GRC.
}

I've also tried setting the io_signature::make to 1,-1,sizeof(float) but
that's less than ideal and doesn't work if in GRC i set number of outputs
to 1.

Again thank you all for your time.

Cheers,
Charles



_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


reply via email to

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