hamnet70-gnuradio-legacy/gr-hamnet70/lib/insert_pilot_symbols_impl.cc

108 lines
3.1 KiB
C++
Raw Normal View History

/* -*- c++ -*- */
/*
* Copyright 2019 Thomas Kolb.
*
* 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 "insert_pilot_symbols_impl.h"
namespace gr {
namespace hamnet70 {
insert_pilot_symbols::sptr
insert_pilot_symbols::make(const std::vector<gr_complex> &pilot_sequence, const std::vector<size_t> &offsets, const std::string &length_tag)
{
return gnuradio::get_initial_sptr
(new insert_pilot_symbols_impl(pilot_sequence, offsets, length_tag));
}
/*
* The private constructor
*/
insert_pilot_symbols_impl::insert_pilot_symbols_impl(const std::vector<gr_complex> &pilot_sequence, const std::vector<size_t> &offsets, const std::string &length_tag)
: gr::tagged_stream_block("insert_pilot_symbols",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex)), length_tag),
d_pilot_sequence(pilot_sequence),
d_offsets(offsets)
{}
/*
* Our virtual destructor.
*/
insert_pilot_symbols_impl::~insert_pilot_symbols_impl()
{
}
int
insert_pilot_symbols_impl::calculate_output_stream_length(const gr_vector_int &ninput_items)
{
int noutput_items = ninput_items[0] + d_pilot_sequence.size() * d_offsets.size();
return noutput_items ;
}
int
insert_pilot_symbols_impl::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];
gr_complex *out = (gr_complex *) output_items[0];
size_t in_pos = 0;
size_t out_pos = 0;
size_t offset_idx = 0;
size_t cur_offset = d_offsets[0];
while(in_pos < ninput_items[0] && out_pos < noutput_items) {
if(in_pos == cur_offset) {
// insert preamble before cur_offset
for(const gr_complex &v : d_pilot_sequence) {
out[out_pos++] = v;
}
offset_idx++;
if(offset_idx >= d_offsets.size()) {
// end of list reached => set to 0, which will never be valid
// again for this packet
cur_offset = 0;
} else {
cur_offset = d_offsets[offset_idx];
}
}
// copy input packet symbol
out[out_pos] = in[in_pos];
out_pos++;
in_pos++;
}
// Tell runtime system how many output items we produced.
return out_pos;
}
} /* namespace hamnet70 */
} /* namespace gr */