blob: d58f04fecbbf969a4b5df7fdaf10894497f18dbf [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_const_source_f_impl.h"
27
28namespace gr {
29 namespace gsm {
30
31 controlled_const_source_f::sptr
32 controlled_const_source_f::make(float constant)
33 {
34 return gnuradio::get_initial_sptr
35 (new controlled_const_source_f_impl(constant));
36 }
37
38 void controlled_const_source_f_impl::set_constant_msg(pmt::pmt_t msg){
39 if(pmt::is_real(msg)){
40 set_constant(pmt::to_double(msg));
41 }
42 }
43
44 /*
45 * The private constructor
46 */
47 controlled_const_source_f_impl::controlled_const_source_f_impl(float constant)
48 : gr::sync_block("controlled_const_source_f",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(1, 1, sizeof(float)))
51 {
52 set_constant(constant);
53 message_port_register_in(pmt::mp("constant_msg"));
54 set_msg_handler(pmt::mp("constant_msg"), boost::bind(&controlled_const_source_f_impl::set_constant_msg, this, _1));
55 }
56
57 /*
58 * Our virtual destructor.
59 */
60 controlled_const_source_f_impl::~controlled_const_source_f_impl()
61 {
62 }
63
64 int
65 controlled_const_source_f_impl::work(int noutput_items,
66 gr_vector_const_void_star &input_items,
67 gr_vector_void_star &output_items)
68 {
69 float *optr = (float*)output_items[0];
70 float t;
71
72 t = d_constant;
73 std::fill_n(optr, noutput_items, t);
74
75 return noutput_items;
76 }
77
78 void controlled_const_source_f_impl::set_constant(float constant){
79 d_constant = constant;
80 }
81
82
83
84 } /* namespace gsm */
85} /* namespace gr */
86