piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
| 3 | * Copyright 2014 <+YOU OR YOUR COMPANY+>. |
| 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3, or (at your option) |
| 8 | * any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; see the file COPYING. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #ifdef HAVE_CONFIG_H |
| 22 | #include "config.h" |
| 23 | #endif |
| 24 | |
| 25 | #include <gnuradio/io_signature.h> |
| 26 | #include "controlled_rotator_cc_impl.h" |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 27 | #include <math.h> |
| 28 | |
| 29 | namespace gr { |
| 30 | namespace gsm { |
| 31 | |
| 32 | controlled_rotator_cc::sptr |
| 33 | controlled_rotator_cc::make(double phase_inc, double samp_rate) |
| 34 | { |
| 35 | return gnuradio::get_initial_sptr |
| 36 | (new controlled_rotator_cc_impl(phase_inc, samp_rate)); |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * The private constructor |
| 41 | */ |
| 42 | controlled_rotator_cc_impl::controlled_rotator_cc_impl(double phase_inc, double samp_rate) |
| 43 | : gr::sync_block("controlled_rotator_cc", |
| 44 | gr::io_signature::make2(1, 2, sizeof(gr_complex), sizeof(float)), |
| 45 | gr::io_signature::make(1, 1, sizeof(gr_complex))) |
| 46 | { |
| 47 | set_phase_inc(phase_inc); |
| 48 | set_samp_rate(samp_rate); |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * Our virtual destructor. |
| 53 | */ |
| 54 | controlled_rotator_cc_impl::~controlled_rotator_cc_impl() |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | controlled_rotator_cc_impl::set_phase_inc(double phase_inc) |
| 60 | { |
| 61 | d_phase_inc = phase_inc; |
| 62 | d_r.set_phase_incr( exp(gr_complex(0, (double)phase_inc)) ); |
| 63 | } |
| 64 | |
| 65 | void |
| 66 | controlled_rotator_cc_impl::set_samp_rate(double samp_rate) |
| 67 | { |
| 68 | d_samp_rate = samp_rate; |
| 69 | } |
| 70 | |
| 71 | int |
| 72 | controlled_rotator_cc_impl::work(int noutput_items, |
| 73 | gr_vector_const_void_star &input_items, |
| 74 | gr_vector_void_star &output_items) |
| 75 | { |
| 76 | const gr_complex *in = (const gr_complex *)input_items[0]; |
| 77 | gr_complex *out = (gr_complex *)output_items[0]; |
| 78 | |
| 79 | if(input_items.size() == 2) { |
| 80 | int ii=0; |
| 81 | const float *pp = (const float *)input_items[1]; |
| 82 | |
| 83 | while(ii < noutput_items){ |
| 84 | //look for different values on phase increment control input |
| 85 | if(d_phase_inc != (*pp)){ |
| 86 | set_phase_inc(*(pp)); //set new value of phase increment |
| 87 | |
| 88 | float freq_offset_setting = (*(pp) / (2*M_PI)) * d_samp_rate; //send stream tag with a new value of the frequency offset |
| 89 | int offset = nitems_written(0); |
| 90 | pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset"); |
| 91 | pmt::pmt_t value = pmt::from_double(freq_offset_setting); |
| 92 | add_item_tag(0,offset, key, value); |
| 93 | |
| 94 | break; |
| 95 | } |
| 96 | pp++; |
| 97 | ii++; |
| 98 | } |
| 99 | } |
piotr | fdef676 | 2014-08-06 15:37:01 +0200 | [diff] [blame] | 100 | d_r.rotateN(out, const_cast<gr_complex *>(in), noutput_items); //const_cast<gr_complex *> is workaround old implementation of rotateN that is still present in ubuntu 14.04 packages |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 101 | return noutput_items; |
| 102 | } |
| 103 | |
| 104 | } /* namespace gsm */ |
| 105 | } /* namespace gr */ |
| 106 | |