clang format, similar to GNU Radio
This commit is contained in:
+111
-100
@@ -14,9 +14,9 @@
|
||||
* 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 <gnuradio/io_signature.h>
|
||||
#include <ieee802_11/sync_short.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -25,130 +25,141 @@ 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 {
|
||||
class sync_short_impl : public sync_short
|
||||
{
|
||||
|
||||
public:
|
||||
sync_short_impl(double threshold, unsigned int min_plateau, bool log, bool debug) :
|
||||
block("sync_short",
|
||||
gr::io_signature::make3(3, 3, sizeof(gr_complex), sizeof(gr_complex), sizeof(float)),
|
||||
gr::io_signature::make(1, 1, 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) {
|
||||
sync_short_impl(double threshold, unsigned int min_plateau, bool log, bool debug)
|
||||
: block("sync_short",
|
||||
gr::io_signature::make3(
|
||||
3, 3, sizeof(gr_complex), sizeof(gr_complex), sizeof(float)),
|
||||
gr::io_signature::make(1, 1, 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);
|
||||
}
|
||||
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) {
|
||||
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_abs = (const gr_complex*)input_items[1];
|
||||
const float *in_cor = (const float*)input_items[2];
|
||||
gr_complex *out = (gr_complex*)output_items[0];
|
||||
const gr_complex* in = (const gr_complex*)input_items[0];
|
||||
const gr_complex* in_abs = (const gr_complex*)input_items[1];
|
||||
const float* in_cor = (const float*)input_items[2];
|
||||
gr_complex* out = (gr_complex*)output_items[0];
|
||||
|
||||
int noutput = noutput_items;
|
||||
int ninput = std::min(std::min(ninput_items[0], ninput_items[1]), ninput_items[2]);
|
||||
int noutput = noutput_items;
|
||||
int ninput =
|
||||
std::min(std::min(ninput_items[0], ninput_items[1]), ninput_items[2]);
|
||||
|
||||
// dout << "SHORT noutput : " << noutput << " ninput: " << ninput_items[0] << std::endl;
|
||||
// dout << "SHORT noutput : " << noutput << " ninput: " << ninput_items[0] <<
|
||||
// std::endl;
|
||||
|
||||
switch(d_state) {
|
||||
switch (d_state) {
|
||||
|
||||
case SEARCH: {
|
||||
int i;
|
||||
case SEARCH: {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < ninput; i++) {
|
||||
if(in_cor[i] > d_threshold) {
|
||||
if(d_plateau < MIN_PLATEAU) {
|
||||
d_plateau++;
|
||||
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;
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
consume_each(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case COPY: {
|
||||
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++;
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
} else {
|
||||
d_plateau = 0;
|
||||
}
|
||||
|
||||
out[o] = in[o] * exp(gr_complex(0, -d_freq_offset * d_copied));
|
||||
o++;
|
||||
d_copied++;
|
||||
}
|
||||
out[o] = in[o] * exp(gr_complex(0, -d_freq_offset * d_copied));
|
||||
o++;
|
||||
d_copied++;
|
||||
}
|
||||
|
||||
if(d_copied == MAX_SAMPLES) {
|
||||
d_state = SEARCH;
|
||||
}
|
||||
if (d_copied == MAX_SAMPLES) {
|
||||
d_state = SEARCH;
|
||||
}
|
||||
|
||||
dout << "SHORT copied " << o << std::endl;
|
||||
dout << "SHORT copied " << o << std::endl;
|
||||
|
||||
consume_each(o);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
consume_each(o);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("sync short: unknown state");
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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;
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user