blob: ee72a6a0579c5e2a35e488dddd1bab4cc1056ec8 [file] [log] [blame]
piotr4089c1a2014-08-06 14:10:56 +02001/* -*- 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"
piotr4089c1a2014-08-06 14:10:56 +020027#include <math.h>
28
29namespace 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)){
Piotr K66bb3cd2014-08-13 19:04:57 +020086
piotr4089c1a2014-08-06 14:10:56 +020087 set_phase_inc(*(pp)); //set new value of phase increment
88
89 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 +020090
91 uint64_t offset = nitems_written(0);
piotr4089c1a2014-08-06 14:10:56 +020092 pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset");
93 pmt::pmt_t value = pmt::from_double(freq_offset_setting);
94 add_item_tag(0,offset, key, value);
Piotr K66bb3cd2014-08-13 19:04:57 +020095
piotr4089c1a2014-08-06 14:10:56 +020096 break;
97 }
98 pp++;
99 ii++;
100 }
101 }
piotrfdef6762014-08-06 15:37:01 +0200102 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 +0200103 return noutput_items;
104 }
105
106 } /* namespace gsm */
107} /* namespace gr */
108