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