Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gr-ezdop / src / lib / ezdop_source_c.cc
1 /*
2  * Copyright 2004,2006 Free Software Foundation, Inc.
3  * 
4  * This file is part of GNU Radio
5  * 
6  * GNU Radio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  * 
11  * GNU Radio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with GNU Radio; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <ezdop_source_c.h>
27 #include <gr_io_signature.h>
28
29 ezdop_source_c_sptr ezdop_make_source_c()
30 {
31     return ezdop_source_c_sptr(new ezdop_source_c());
32 }
33
34 ezdop_source_c::ezdop_source_c() throw (std::runtime_error) :
35     gr_sync_block("ezdop_source_c",
36                   gr_make_io_signature(0, 0, 0),
37                   gr_make_io_signature(1, 1, sizeof (gr_complex))
38     )
39 {
40     d_ezdop = new ezdop();
41
42     if (!d_ezdop->init())
43         throw std::runtime_error("unable to init ezdop hardware");
44     if (!d_ezdop->reset())
45         throw std::runtime_error("unable to reset ezdop hardware");
46 }
47
48 ezdop_source_c::~ezdop_source_c()
49 {
50     assert(d_ezdop);
51     d_ezdop->finish();
52     delete d_ezdop;
53 }
54
55 bool ezdop_source_c::start()
56 {
57     assert(d_ezdop);
58     bool success = d_ezdop->stream();
59     if (!success)
60         fprintf(stderr, "ezdop_source_c::start(): unable to start streaming\n");
61     return success;
62 }
63
64 bool ezdop_source_c::stop()
65 {
66     assert(d_ezdop);
67     bool success = d_ezdop->stop_streaming();
68     if (!success)
69         fprintf(stderr, "ezdop_source_c::start(): unable to stop streaming\n");
70     return success;
71 }
72
73 int ezdop_source_c::rate()
74 {
75     assert(d_ezdop);
76     return d_ezdop->rate();
77 }
78
79 bool ezdop_source_c::set_rate(int rate)
80 {
81     assert(d_ezdop);
82     if (rate <= 0 || rate > 2000)
83         return false;
84     bool success = d_ezdop->set_rate(rate);    
85     return success;
86 }
87
88 bool ezdop_source_c::rotate()
89 {
90     assert(d_ezdop);
91     bool success = d_ezdop->rotate();
92     if (!success)
93         fprintf(stderr, "ezdop_source_c::rotate(): unable to start rotating\n");
94     return success;
95 }
96
97 bool ezdop_source_c::stop_rotating()
98 {
99     assert(d_ezdop);
100     bool success = d_ezdop->stop_rotating();
101     if (!success)
102         fprintf(stderr, "ezdop_source_c::stop_rotating(): unable to stop rotating\n");
103     return success;
104 }
105
106 int ezdop_source_c::work(int noutput_items,
107         gr_vector_const_void_star &input_items,
108         gr_vector_void_star &output_items)
109 {
110     assert(d_ezdop);
111     float volume = 0.0; // Dummy for now
112
113     gr_complex *out = (gr_complex *)output_items[0];
114     return d_ezdop->read_iq(out, noutput_items, volume);
115 }