/*
* Copyright 2015 <+YOU OR YOUR COMPANY+>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "deinterleaver_bb_impl.h"
namespace gr {
namespace frame_detection {
deinterleaver_bb::sptr
deinterleaver_bb::make(int n, int m, int message_length)
{
return gnuradio::get_initial_sptr
(new deinterleaver_bb_impl(n, m, message_length));
}
/*
* The private constructor
*/
deinterleaver_bb_impl::deinterleaver_bb_impl(int n, int m, int message_length)
: gr::block("deinterleaver_bb",
gr::io_signature::make(1, 1, sizeof(char)),
gr::io_signature::make(1, 1, sizeof(char)))
{
i_n = n;
i_m = m;
counter = 0;
n_count = 0;
m_count = 0;
buffer = new char[n*m];
buffer2 = new char[n*m];
buf_count = 0;
frame_detected = false;
end_of_frame = false;
eof_pos = 0;
m_length = message_length;
}
/*
* Our virtual destructor.
*/
deinterleaver_bb_impl::~deinterleaver_bb_impl()
{
delete[] buffer;
delete[] buffer2;
}
void
deinterleaver_bb_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
ninput_items_required[0] = noutput_items;
}
int
deinterleaver_bb_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const char *in = (const char *) input_items[0];
char *out = (char *) output_items[0];
int n = ninput_items[0];
int i = 0;
int msg_count = 0;
while (n > 0)
{
if(!frame_detected)
{
if(in[i] != char(0))
{
frame_detected = true;
end_of_frame = false;
}
out[i] = 0;
consume_each(1);
n--;
i++;
}
else
{
if(msg_count == m_length)
{
end_of_frame = true;
eof_pos = i;
}
if ((i == eof_pos + i_n*i_m) && (end_of_frame))
{
out[i++] = 0;
n--;
consume_each(1);
frame_detected = false;
}
else
{
if(counter < i_n*i_m)
{
counter++;
out[i] = 0;
}
else
{
out[i] = buffer2[buf_count++];
n--;
consume_each(1);
}
if (buf_count >= i_n*i_m)
buf_count = 0;
buffer[n_count + i_m*m_count] = in[i];
msg_count++;
if (n_count + i_m*m_count == i_n*i_m - 1)
{
for(int j = 0; j < i_n*i_m; j++)
buffer2[j] = buffer[j];
}
if(m_count < i_n - 1)
m_count++;
else
{
m_count = 0;
n_count++;
}
if(n_count == i_m)
n_count = 0;
i++;
}
}
}
// Tell runtime system how many output items we produced.
return i;
}
} /* namespace frame_detection */
} /* namespace gr */
/* -*- c++ -*- */
/*
* Copyright 2015 <+YOU OR YOUR COMPANY+>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_FRAME_DETECTION_DEINTERLEAVER_BB_IMPL_H
#define INCLUDED_FRAME_DETECTION_DEINTERLEAVER_BB_IMPL_H
#include <frame_detection/deinterleaver_bb.h>
namespace gr {
namespace frame_detection {
class deinterleaver_bb_impl : public deinterleaver_bb
{
private:
int i_n;
int i_m;
int counter;
int n_count;
int m_count;
char* buffer;
char* buffer2;
int buf_count;
bool frame_detected;
bool end_of_frame;
int eof_pos;
int m_length;
public:
deinterleaver_bb_impl(int n, int m, int message_length);
~deinterleaver_bb_impl();
// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace frame_detection
} // namespace gr
#endif /* INCLUDED_FRAME_DETECTION_DEINTERLEAVER_BB_IMPL_H */
/* -*- c++ -*- */
/*
* Copyright 2015 <+YOU OR YOUR COMPANY+>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "preamble_detector_bb_impl.h"
#include <cmath>
#include <iostream>
using namespace std;
namespace gr {
namespace frame_detection {
preamble_detector_bb::sptr
preamble_detector_bb::make(const std::vector<int> &preamble, int preamble_length, int message_length, int i_size)
{
return gnuradio::get_initial_sptr
(new preamble_detector_bb_impl(preamble, preamble_length, message_length, i_size));
}
/*
* The private constructor
*/
preamble_detector_bb_impl::preamble_detector_bb_impl(const std::vector<int> &preamble,
int preamble_length,
int message_length,
int i_size)
: gr::block("preamble_detector_bb",
gr::io_signature::make(1, 1, sizeof(char)),
gr::io_signature::make(1, 1, sizeof(char)))
{
sequence = new char[preamble_length];
sequence_length = preamble_length;
for(int i = 0; i < preamble_length; i++)
sequence[i] = char(preamble[i]);
sequence_detected = false;
counter = 0;
message_counter = 0;
m_length = message_length;
item_size = i_size;
}
/*
* Our virtual destructor.
*/
preamble_detector_bb_impl::~preamble_detector_bb_impl()
{
delete[] sequence;
}
int
preamble_detector_bb_impl::general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const char *in = (const char *) input_items[0];
char *out = (char *) output_items[0];
int n = ninput_items[0];
int i = 0;
bool thresh_sent = false;
int thresh_count = 0;
int zero_count = 0;
int history = 0;
while(n > 0)
{
if(!thresh_sent)
{
if(!sequence_detected)
{
if(in[i - history] == sequence[counter])
{
counter++;
}
else
counter = 0;
if(counter == sequence_length)
{
out[i] = char(255);
sequence_detected = true;
counter = 0;
thresh_count++;
}
else
{
out[i] = 0;
zero_count++;
if(zero_count == item_size)
zero_count = 0;
}
n--;
}
else
{
if(thresh_count < (item_size - zero_count))
{
thresh_count++;
out[i] = char(255);
}
else
{
thresh_sent = true;
sequence_detected = false;
thresh_count = 0;
out[i] = in[i - (history + item_size - zero_count) + 1];
message_counter++;
n--;
}
}
}
else
{
out[i] = in[i - (history + item_size - zero_count) + 1];
if(message_counter < (m_length - 1))
{
message_counter++;
}
else
{
thresh_sent = false;
history += item_size - zero_count - 1;
zero_count = 0;
message_counter = 0;
}
n--;
}
i++;
}
consume_each(ninput_items[0]);
return i;
}
} /* namespace frame_detection */
} /* namespace gr */
/* -*- c++ -*- */
/*
* Copyright 2015 <+YOU OR YOUR COMPANY+>.
*
* This 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, or (at your option)
* any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_FRAME_DETECTION_PREAMBLE_DETECTOR_BB_IMPL_H
#define INCLUDED_FRAME_DETECTION_PREAMBLE_DETECTOR_BB_IMPL_H
#include <frame_detection/preamble_detector_bb.h>
namespace gr {
namespace frame_detection {
class preamble_detector_bb_impl : public preamble_detector_bb
{
private:
char* sequence;
int sequence_length;
bool sequence_detected;
int counter;
int message_counter;
int m_length;
int item_size;
public:
preamble_detector_bb_impl(const std::vector<int> &preamble,
int preamble_length,
int message_length,
int item_size);
~preamble_detector_bb_impl();
// Where all the action really happens
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace frame_detection
} // namespace gr
#endif /* INCLUDED_FRAME_DETECTION_PREAMBLE_DETECTOR_BB_IMPL_H */
On Sun, Feb 8, 2015 at 11:01 AM, Aditya Dhananjay <aditya@cs.nyu.edu> wrote:
> Hello Daniel,
>
> Are you using OFDM? If so, read on, otherwise disregard the rest of the
> email.
This sounds much less like a problem with regards on how to figure out
the synchronization but more about how to do it inside the confines of
GNU Radio.
The original post wants to discard everything before a preamble they
detect. Once preamble is detected, I assume a state machine down
stream will decode some information in the samples coming down which
says "The length of this transmission is 12345 symbols". At this
time, the downstream block will send a message to the upstream block -
holding off the samples until it knows how many more to send down -
and finish up.
The feedback loop cannot be realized inside the flowgraph since
everything needs to be feed forward.
This is a great example of how someone may want to do RF burst
processing which may not necessarily be "real-time" but due to
dead-air or guard bands might be able to catch up on the processing if
you didn't have to keep processing every last incoming sample -
especially at a higher sample rate. Moreover, it shows how blocks
could be used to message each other to create feedback loops and
convey downstream information to upstream processing elements which
may care - things like SNR estimation, timing information, etc.
I'm very interested to see how this all ends up.
Brian
No comments:
Post a Comment