Call the work() method

Hi all:
I know every block should have it’s work or general_work
function.And i know it’s used by scheduler.
Now I want to write my c++ code just call work function.Is
right to do it?
If ok,can someone explain how to call work function?
Thanks.
Best regards

Hi Xianda,

     I know every block should have it's work or general_work function.And i 

know it’s used by scheduler.
Right!

     Now I want to write my c++ code just call work function.Is right to do 

it?
I hope I understand you correctly:
You want to write a C++ program that calls your work function?

As usual, it would be quite helpful if you explained why you would
want to do this!

Short Answer:
Usually you don’t do that, so it’s not right to do.
Long Answer:
You can not generally do this because a block can only exist within GNU
Radio, and relies on GNU Radio scheduler mechanisms.
If you however, wrote a work() that only uses the the input_items,
output_items buffers and only relies on noutput_items as runtime
information,
than that’s technically possible. I would not recommend that, though.
Better write a new function, e.g. “signal_processing(in,out, howmany)”
in a non-block class
and call that from your work() as well as from your new C++ program.

     If ok,can someone explain how to call work function?

It’s a C++ method, and the function signature is
int work
http://gnuradio.org/doc/doxygen/classgr_1_1sync__block.html#a38942c5d8bee5232404ab71ada9a3956
(int noutput_items, gr_vector_const_void_star
http://gnuradio.org/doc/doxygen/gnuradio-runtime_2include_2gnuradio_2types_8h.html#a9852a3d906d823cb70eb9c29e7f2a43d
&input_items, gr_vector_void_star
http://gnuradio.org/doc/doxygen/gnuradio-runtime_2include_2gnuradio_2types_8h.html#acd3f499576e769966ea44554b359d949
&output_items)
(from the official documentation,
http://gnuradio.org/doc/doxygen/classgr_1_1sync__block.html)
You could call it like you would call every other method. Since I assume
you already know how input_ and output_items should look like from
writing a work() function,
I don’t understand where the “how to call question” comes from.

Best Regards,
Marcus M?ller

On 31 May 2014 11:57, “Marcus Müller” [email protected] wrote:

Hi Xianda,

     I know every block should have it's work or general_work

function.And i know it’s used by scheduler

For the record, a block that only uses message passing doesn’t need a
work
function - not that that’s what you’re looking for here.

M

Hi:
Thank you so much.
For example,I write a simple c++ program which can use the
“gnuradio/fft/fft.h”.But i also want to use
<gnuradio/digital/ofdm_cyclic_prefixer.h>.
But the ofdm_cyclic_prefixer is a block.It has work function.
I attached my document.
#include
#include
#include <gnuradio/gr_complex.h>
#include <gnuradio/fft/fft.h>
#include <gnuradio/digital/ofdm_cyclic_prefixer.h>

std::vector<std::complex *> buff1(64);//read data
std::vector<std::complex *> buff2(64);//write data

std::ifstream infile(“a.dat”,std::ifstream::binary);
std::ofstream outfile(“b.dat”,std::ofstream::binary);

int main(){
while(not infile.eof())
{
infile.read((char*)&buff1.front(),buff1.size()*sizeof(std::complex));

gr::fft::fft_complex *buff=new gr::fft::fft_complex(64,0);
gr_complex *bu=buff->get_inbuf();
memcpy(bu,&buff1.front(),buff1.size()*sizeof(std::complex));
buff->execute();
gr_complex *out=buff->get_outbuf();
memcpy(&buff2.front(),out,buff2.size()*sizeof(std::complex));

outfile.write((char*)&buff2.front(),buff2.size()*sizeof(std::complex));
}

infile.close();
outfile.close();
}
Can you help me?
Thanks
Best regards,
xianda

At 2014-05-31 05:56:29, “Marcus M.” [email protected] wrote:
Hi Xianda,

     I know every block should have it's work or general_work 

function.And i know it’s used by scheduler.
Right!

     Now I want to write my c++ code just call work function.Is 

right to do it?
I hope I understand you correctly:
You want to write a C++ program that calls your work function?

As usual, it would be quite helpful if you explained why you would
want to do this!

Short Answer:
Usually you don’t do that, so it’s not right to do.
Long Answer:
You can not generally do this because a block can only exist within GNU
Radio, and relies on GNU Radio scheduler mechanisms.
If you however, wrote a work() that only uses the the input_items,
output_items buffers and only relies on noutput_items as runtime
information,
than that’s technically possible. I would not recommend that, though.
Better write a new function, e.g. “signal_processing(in,out, howmany)”
in a non-block class
and call that from your work() as well as from your new C++ program.

     If ok,can someone explain how to call work function?

It’s a C++ method, and the function signature is
int work (int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
(from the official documentation,
http://gnuradio.org/doc/doxygen/classgr_1_1sync__block.html)
You could call it like you would call every other method. Since I assume
you already know how input_ and output_items should look like from
writing a work() function,
I don’t understand where the “how to call question” comes from.

Best Regards,
Marcus M.

Hi:
Thank you so much.
I just want to write c++ code to realize (“fft” block+“OFDM Cyclic
Prefixer”).
And I attached my code which just realize ifft but the “OFDM Cyclic
Prefixer” has it’s work function.
#include
#include
#include <gnuradio/gr_complex.h>
#include <gnuradio/fft/fft.h>
#include <gnuradio/digital/ofdm_cyclic_prefixer.h>

std::vector<std::complex *> buff1(64);//read data
std::vector<std::complex *> buff2(64);//write data

std::ifstream infile(“a.dat”,std::ifstream::binary);
std::ofstream outfile(“b.dat”,std::ofstream::binary);

int main(){
while(not infile.eof())
{
infile.read((char*)&buff1.front(),buff1.size()*sizeof(std::complex));

gr::fft::fft_complex *buff=new gr::fft::fft_complex(64,0);
gr_complex *bu=buff->get_inbuf();
memcpy(bu,&buff1.front(),buff1.size()*sizeof(std::complex));
buff->execute();
gr_complex *out=buff->get_outbuf();
memcpy(&buff2.front(),out,buff2.size()*sizeof(std::complex));

outfile.write((char*)&buff2.front(),buff2.size()*sizeof(std::complex));
}

infile.close();
outfile.close();
}

Thank you.
Best regards,
xianda

At 2014-05-31 06:33:35, “Martin B.” [email protected] wrote:

On 31 May 2014 11:57, “Marcus Müller” [email protected] wrote:

Hi Xianda,

     I know every block should have it's work or general_work function.And 

i know it’s used by scheduler

For the record, a block that only uses message passing doesn’t need a
work function - not that that’s what you’re looking for here.

M

Hi:
Thank you so much.
What I want to do is that
read symbols from file and perform fft and insert cp and then transmit
to the usrp.Just as the “fft” and “OFDM Cyclic Prefixer” do!

The easy way is use the<gnuradio/fft/fft.h> and
<gnuradio/digital/ofdm_cyclic_prefixer.h>.But as you said
fft_complex_vcc is a block.But now how can i call it in my code?(It’s a
block.It has work function.)Can i add it’s work function in my
code?Thank you.
Best regards,
xianda

Hi Xianda,

some of your emails are really hard to read due to your email client
writing non-standard-compliant HTML mail. Could you disable
HTML/multimedia mail?

What I want to do is that read symbols from file and perform fft and insert cp
and then transmit to the usrp.
ok, thanks for clarifying that!

Just as the “fft” and “OFDM Cyclic Prefixer” do!

Well, the fft block doesn’t read from a file, and ofdm cyclic prefixer
does not transmit, but I get your point.

The easy way is use the <gnuradio/fft/fft.h> and
<gnuradio/digital/ofdm_cyclic_prefixer.h>;

No!
In GNU Radio, you build flow graphs out of existing blocks, whenever
possible. So you want to use

[file source] --> [ (I)FFT ] --> [ cyclic prefixer ] --> [ USRP sink ]

by instantiating these blocks, and connecting them to a GNU Radio flow
graph. Then you let GNU Radio run that flow graph.
There’s no need to write your own block, so far. Actually, you can do
this without writing a single line of code just by constructing
above flow graph in gnuradio-companion. That will generate the flowgraph
setup and starting program in python.

If you need to add more functionality, you usually just add another
block to this chain, but from what you’ve said there will be no need to
do this.

But as you said fft_complex_vcc is a block. But now how can i call it in my
code?

You don’t, see my previous post on calling work().

Greetings,
Marcus

Hi Xianda,

I just want to write c++ code to realize (“fft” block+“OFDM Cyclic
Prefixer”).

Sorry, I still did not understand. I only understand your C++, so here’s
my comments:

The code you posted has really nothing to do with gr::block;
gr::fft:fft_complex is not a gr::block, and has no work()!
http://gnuradio.org/doc/doxygen/classgr_1_1fft_1_1fft__complex.html

Also, I don’t see the need to #include
<gnuradio/digital/ofdm_cyclic_prefixer.h>. Is this a mistake or was it
intentional?

fft_complex really just a convenience wrapper around FFTW.
I haven’t tried to test your code, and you could read() directly into
the get_inbuf() buffer, and write directly from your get_outbuf()
buffer, but it looks ok.

Again: gr::fft:fft_complex is not a block! it is used from within
fft_complex_vcc (which is a block).
All it does is use the FFTW library to perform FFTs, you can do that
yourself without using GNU Radio at all. Only use it when you are
developing a GNU Radio program!

Greetings,
Marcus

Hi!

The gr-uhd USRP sink can represent multiple USRPs at once.
If you have a recent GNU Radio version, in gnuradio-companion your “UHD:
USRP Sink” block will have a “Documentation” tab.
There is an example that specifies two USRP addresses. This will
automatically enable you to transmit the contents of both files
simultaneously [1].
You should start with the gnuradio-companion, which will generate
easy-to-read Python code.
Usually, you don’t need to write your own blocks to interface with
USRPs.

Greetings,
Marcus

[1] “Simultaneously” does not mean “coherently”!

Hi
Thank you so much for your patient instructions.
Yes ,I know the “UHD:USRP Sink” can specifies two USRP
addresses.But the symbol i try to transmit to the usrp is different.
They may be should in two flow graph.
[file source 1] --> [ (I)FFT ] --> [ cyclic prefixer ] --> [ USRP sink
1]
[file source 2] --> [ (I)FFT ] --> [ cyclic prefixer ] --> [ USRP sink
2]
Can i realize it in grc?Or should i write the c++ code?
Thank you.Thank you.
Best regards,
xianda

Hi:
Thank you so much for your kindly reply.
Sorry for my poor English.
The reason why i directly write the c++ code is that I want to use
the uhd to control my two usrps send simultaneously.
The aim i want to reach is that read symbol from file and perform
ifft and insert cp and then transmit.Just like you write:
[file source 1] --> [ (I)FFT ] --> [ cyclic prefixer ] --> [ USRP
sink 1]
[file source 2] --> [ (I)FFT ] --> [ cyclic prefixer ] --> [ USRP sink
2]
I can control them simutanously.Use some class like
uhd::usrp::multi_usrp.
Which is the best way to realize it?Use the c++ or write python flow
graph?Thanks.
Thank you so much.
Best regards,
xianda

GRC. You get 1 USRP sink, but it will have 2 independent inputs.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs