discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] call the work() method


From: xianda
Subject: Re: [Discuss-gnuradio] call the work() method
Date: Sat, 31 May 2014 19:02:46 +0800 (CST)

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 <fstream>
#include <vector>
#include <gnuradio/gr_complex.h>
#include <gnuradio/fft/fft.h>
#include <gnuradio/digital/ofdm_cyclic_prefixer.h>

std::vector<std::complex<float> *> buff1(64);//read data
std::vector<std::complex<float> *> 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<float>));

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<float>));
buff->execute();
gr_complex *out=buff->get_outbuf();
memcpy(&buff2.front(),out,buff2.size()*sizeof(std::complex<float>));

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

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

At 2014-05-31 05:56:29, "Marcus Müller" <address@hidden> 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üller



reply via email to

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