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

96 lines
2.7 KiB
C++

/* -*- 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 <gnuradio/expj.h>
#include "correct_phase_from_tag_impl.h"
namespace gr {
namespace hamnet70 {
correct_phase_from_tag::sptr
correct_phase_from_tag::make(const std::string &phase_tag_name)
{
return gnuradio::get_initial_sptr
(new correct_phase_from_tag_impl(phase_tag_name));
}
/*
* The private constructor
*/
correct_phase_from_tag_impl::correct_phase_from_tag_impl(const std::string &phase_tag_name)
: gr::sync_block("correct_phase_from_tag",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
m_pmtPhaseTagName(pmt::intern(phase_tag_name)),
m_rotation(1, 0)
{}
/*
* Our virtual destructor.
*/
correct_phase_from_tag_impl::~correct_phase_from_tag_impl()
{
}
int
correct_phase_from_tag_impl::work(int noutput_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];
std::vector<tag_t> tags;
get_tags_in_window(tags, 0, 0, noutput_items, m_pmtPhaseTagName);
std::cerr << "correct_phase_from_tag: Found " << tags.size() << " tags." << std::endl;
size_t tagidx = 0;
// rotate the data by the last set phase angle
for(int i = 0; i < noutput_items; i++) {
if((tagidx < tags.size()) && (tags[tagidx].offset == nitems_read(0) + i)) {
double phase = pmt::to_double(tags[tagidx].value);
m_rotation = gr_expj(-phase);
std::cerr << "correct_phase_from_tag: Updated phase correction to " << -phase << std::endl;
tagidx++;
}
out[i] = in[i] * m_rotation;
}
for(size_t i = 0; i < tags.size(); i++) {
}
// Tell runtime system how many output items we produced.
return noutput_items;
}
} /* namespace hamnet70 */
} /* namespace gr */