blob: 6211d4961aaa92ca32bb690d46fda06968cb42f5 [file] [log] [blame]
piotr4089c1a2014-08-06 14:10:56 +02001/* -*- c++ -*- */
ptrkrysik529895b2014-12-02 18:07:38 +01002/*
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
piotr4089c1a2014-08-06 14:10:56 +02008 * 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.
ptrkrysik529895b2014-12-02 18:07:38 +010011 *
12 * Gr-gsm is distributed in the hope that it will be useful,
piotr4089c1a2014-08-06 14:10:56 +020013 * 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.
ptrkrysik529895b2014-12-02 18:07:38 +010016 *
piotr4089c1a2014-08-06 14:10:56 +020017 * You should have received a copy of the GNU General Public License
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
piotr4089c1a2014-08-06 14:10:56 +020019 * 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"
piotr4089c1a2014-08-06 14:10:56 +020029#include <math.h>
30
31namespace 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 K66bb3cd2014-08-13 19:04:57 +020088
piotr4089c1a2014-08-06 14:10:56 +020089 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 K66bb3cd2014-08-13 19:04:57 +020092
93 uint64_t offset = nitems_written(0);
piotr4089c1a2014-08-06 14:10:56 +020094 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 K66bb3cd2014-08-13 19:04:57 +020097
piotr4089c1a2014-08-06 14:10:56 +020098 break;
99 }
100 pp++;
101 ii++;
102 }
103 }
piotrfdef6762014-08-06 15:37:01 +0200104 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
piotr4089c1a2014-08-06 14:10:56 +0200105 return noutput_items;
106 }
107
108 } /* namespace gsm */
109} /* namespace gr */
110