Saturday, April 28, 2018

[Discuss-gnuradio] Correct usage of gr::io_signature::makev

/*
* Copyright (C) 2013, 2016 Bastian Bloessl <bloessl@ccs-labs.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ieee802-11/sync_short.h>
#include <gnuradio/io_signature.h>
#include "utils.h"

#include <iostream>

using namespace gr::ieee802_11;

static const int MIN_GAP = 480;
static const int MAX_SAMPLES = 540 * 80;

class sync_short_impl : public sync_short {

public:
static int ios[] = {sizeof(gr_complex), sizeof(gr_complex), sizeof(gr_complex), sizeof(float)};
static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));
sync_short_impl(double threshold, unsigned int min_plateau, bool log, bool debug) :
block("sync_short",
gr::io_signature::makev(4, 4, iosig),
gr::io_signature::make2(2, 2, sizeof(gr_complex), sizeof(gr_complex))),
d_log(log),
d_debug(debug),
d_state(SEARCH),
d_plateau(0),
d_freq_offset(0),
d_copied(0),
MIN_PLATEAU(min_plateau),
d_threshold(threshold) {

set_tag_propagation_policy(block::TPP_DONT);
}

int general_work (int noutput_items, gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) {

const gr_complex *in = (const gr_complex*)input_items[0];
const gr_complex *in_1 = (const gr_complex*)input_items[1];
const gr_complex *in_abs = (const gr_complex*)input_items[2];
const float *in_cor = (const float*)input_items[3];
gr_complex *out = (gr_complex*)output_items[0];
gr_complex *out_1 = (gr_complex*)output_items[1];

int noutput = noutput_items;
int ninput = std::min(std::min(ninput_items[2] ,std::min(ninput_items[0], ninput_items[1])), ninput_items[3]);

// dout << "SHORT noutput : " << noutput << " ninput: " << ninput_items[0] << std::endl;

switch(d_state) {

case SEARCH: {
int i;

for(i = 0; i < ninput; i++) {
if(in_cor[i] > d_threshold) {
if(d_plateau < MIN_PLATEAU) {
d_plateau++;

} else {
d_state = COPY;
d_copied = 0;
d_freq_offset = arg(in_abs[i]) / 16;
d_plateau = 0;
insert_tag(nitems_written(0), d_freq_offset, nitems_read(0) + i);
dout << "SHORT Frame!" << std::endl;
break;
}
} else {
d_plateau = 0;
}
}

consume_each(i);
return 0;
}

case COPY: {

int o = 0;
while( o < ninput && o < noutput && d_copied < MAX_SAMPLES) {
if(in_cor[o] > d_threshold) {
if(d_plateau < MIN_PLATEAU) {
d_plateau++;

// there's another frame
} else if(d_copied > MIN_GAP) {
d_copied = 0;
d_plateau = 0;
d_freq_offset = arg(in_abs[o]) / 16;
insert_tag(nitems_written(0) + o, d_freq_offset, nitems_read(0) + o);
dout << "SHORT Frame!" << std::endl;
break;
}

} else {
d_plateau = 0;
}

out[o] = in[o] * exp(gr_complex(0, -d_freq_offset * d_copied));
out_1[o] = in[o] * exp(gr_complex(0, -d_freq_offset * d_copied));
o++;
d_copied++;
}

if(d_copied == MAX_SAMPLES) {
d_state = SEARCH;
}

dout << "SHORT copied " << o << std::endl;

consume_each(o);
return o;
}
}

throw std::runtime_error("sync short: unknown state");
return 0;
}

void insert_tag(uint64_t item, double freq_offset, uint64_t input_item) {
mylog(boost::format("frame start at in: %2% out: %1%") % item % input_item);

const pmt::pmt_t key = pmt::string_to_symbol("wifi_start");
const pmt::pmt_t value = pmt::from_double(freq_offset);
const pmt::pmt_t srcid = pmt::string_to_symbol(name());
add_item_tag(0, item, key, value, srcid);
}

private:
enum {SEARCH, COPY} d_state;
int d_copied;
int d_plateau;
float d_freq_offset;
const double d_threshold;
const bool d_log;
const bool d_debug;
const unsigned int MIN_PLATEAU;
};

sync_short::sptr
sync_short::make(double threshold, unsigned int min_plateau, bool log, bool debug) {
return gnuradio::get_initial_sptr(new sync_short_impl(threshold, min_plateau, log, debug));
}

Hi,

In order to look for correct usage of gr::io_signature::makev, I checked this example https://github.com/gnuradio/gnuradio/blob/master/gr-digital/lib/fll_band_edge_cc_impl.cc

and found

static int ios[] = {sizeof(gr_complex), sizeof(gr_complex), sizeof(gr_complex), sizeof(float)};

static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));

and then use as io_signature::makev(1, 4, iosig))

Basically I have to use it in sync_short.cc from gr-ieee 80211 in order to create more inputs.

But if I use the above two lines inside the class i.e. sync_short_impl, I get lots of error. I have attached the file for reference. Could you please suggest me correct usage. I can give more information if needed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc:31:84: error: in-class initialization of static data member 'int sync_short_impl::ios []' of incomplete type
 tic int ios[] = {sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float)};
                                                                                 ^
/home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc:32:31: error: 'ios' is not a type
 static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));
                               ^
/home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc:32:36: error: 'ios' is not a type
 static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));
                                    ^
/home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc:32:39: error: expected ',' or '...' before '+' token
 static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));
                                       ^
/home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc: In constructor 'sync_short_impl::sync_short_impl(double, unsigned int, bool, bool)':
/home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc:35:39: error: no matching function for call to 'gr::io_signature::makev(int, int, std::vector<int> (&)(int, int))'
    gr::io_signature::makev(4, 4, iosig),
                                       ^
In file included from /home/john/myprefix/include/gnuradio/basic_block.h:30:0,
                 from /home/john/myprefix/include/gnuradio/block.h:27,
                 from /home/john/myprefix/src/gr-ieee-80211/include/ieee802-11/sync_short.h:21,
                 from /home/john/myprefix/src/gr-ieee-80211/lib/sync_short.cc:17:
/home/john/myprefix/include/gnuradio/io_signature.h:100:17: note: candidate: static gr::io_signature::sptr gr::io_signature::makev(int, int, const std::vector<int>&)
     static sptr makev(int min_streams, int max_streams,
                 ^
/home/john/myprefix/include/gnuradio/io_signature.h:100:17: note:   no known conversion for argument 3 from 'std::vector<int>(int, int)' to 'const std::vector<int>&'
lib/CMakeFiles/gnuradio-ieee802_11.dir/build.make:584: recipe for target 'lib/CMakeFiles/gnuradio-ieee802_11.dir/sync_short.cc.o' failed
make[2]: *** [lib/CMakeFiles/gnuradio-ieee802_11.dir/sync_short.cc.o] Error 1
CMakeFiles/Makefile2:200: recipe for target 'lib/CMakeFiles/gnuradio-ieee802_11.dir/all' failed
make[1]: *** [lib/CMakeFiles/gnuradio-ieee802_11.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

No comments:

Post a Comment