blob: 39fafb02aec5f4f16d5bb8eb8fbae5e864988870 [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"
27#include <gnuradio/blocks/rotator_cc.h>
28#include <math.h>
29
30namespace gr {
31 namespace gsm {
32
33 controlled_rotator_cc::sptr
34 controlled_rotator_cc::make(double phase_inc, double samp_rate)
35 {
36 return gnuradio::get_initial_sptr
37 (new controlled_rotator_cc_impl(phase_inc, samp_rate));
38 }
39
40 /*
41 * The private constructor
42 */
43 controlled_rotator_cc_impl::controlled_rotator_cc_impl(double phase_inc, double samp_rate)
44 : gr::sync_block("controlled_rotator_cc",
45 gr::io_signature::make2(1, 2, sizeof(gr_complex), sizeof(float)),
46 gr::io_signature::make(1, 1, sizeof(gr_complex)))
47 {
48 set_phase_inc(phase_inc);
49 set_samp_rate(samp_rate);
50 }
51
52 /*
53 * Our virtual destructor.
54 */
55 controlled_rotator_cc_impl::~controlled_rotator_cc_impl()
56 {
57 }
58
59 void
60 controlled_rotator_cc_impl::set_phase_inc(double phase_inc)
61 {
62 d_phase_inc = phase_inc;
63 d_r.set_phase_incr( exp(gr_complex(0, (double)phase_inc)) );
64 }
65
66 void
67 controlled_rotator_cc_impl::set_samp_rate(double samp_rate)
68 {
69 d_samp_rate = samp_rate;
70 }
71
72 int
73 controlled_rotator_cc_impl::work(int noutput_items,
74 gr_vector_const_void_star &input_items,
75 gr_vector_void_star &output_items)
76 {
77 const gr_complex *in = (const gr_complex *)input_items[0];
78 gr_complex *out = (gr_complex *)output_items[0];
79
80 if(input_items.size() == 2) {
81 int ii=0;
82 const float *pp = (const float *)input_items[1];
83
84 while(ii < noutput_items){
85 //look for different values on phase increment control input
86 if(d_phase_inc != (*pp)){
87 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
90 int offset = nitems_written(0);
91 pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset");
92 pmt::pmt_t value = pmt::from_double(freq_offset_setting);
93 add_item_tag(0,offset, key, value);
94
95 break;
96 }
97 pp++;
98 ii++;
99 }
100 }
101 d_r.rotateN(out, in, noutput_items);
102 return noutput_items;
103 }
104
105 } /* namespace gsm */
106} /* namespace gr */
107