Merged r9834:9855 from jcorgan/u2-wip into trunk. Catches up gr-usrp2 with the lates...
[debian/gnuradio] / gr-usrp2 / src / usrp2.i
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * 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.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * 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.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 %feature("autodoc", "1");               // generate python docstrings
24
25 %include "exception.i"
26 %import "gnuradio.i"                    // the common stuff
27
28 %{
29 #include <gnuradio_swig_bug_workaround.h>
30 #include "usrp2_source_16sc.h"
31 #include "usrp2_source_32fc.h"
32 #include "usrp2_sink_16sc.h"
33 #include "usrp2_sink_32fc.h"
34 %}
35
36 %include <usrp2/tune_result.h>
37
38 // ----------------------------------------------------------------
39
40 class usrp2_base : public gr_sync_block 
41 {
42 protected:
43   usrp2_base() throw (std::runtime_error);
44
45 public:
46   ~usrp2_base();
47
48   std::string mac_addr() const;
49   %rename(_real_fpga_master_clock_freq) fpga_master_clock_freq;
50   bool fpga_master_clock_freq(long *freq);
51 };
52
53 // ----------------------------------------------------------------
54
55 class usrp2_source_base : public usrp2_base 
56 {
57 protected:
58   usrp2_source_base() throw (std::runtime_error);
59
60 public:
61   ~usrp2_source_base();
62
63   bool set_gain(double gain);
64   %rename(_real_set_center_freq) set_center_freq;
65   bool set_center_freq(double frequency, usrp2::tune_result *r);
66   bool set_decim(int decimation_factor);
67   bool set_scale_iq(int scale_i, int scale_q);
68   int decim();
69   %rename(_real_adc_rate) adc_rate;
70   bool adc_rate(long *rate);
71   double gain_min();
72   double gain_max();
73   double gain_db_per_step();
74   double freq_min();
75   double freq_max();
76   %rename(_real_daughterboard_id) daughterboard_id;
77   bool daughterboard_id(int *dbid);
78   unsigned int overruns();
79   unsigned int missing();
80 };
81
82 // ----------------------------------------------------------------
83
84 GR_SWIG_BLOCK_MAGIC(usrp2,source_32fc)
85
86 usrp2_source_32fc_sptr
87 usrp2_make_source_32fc(const std::string ifc="eth0", 
88                        const std::string mac="") 
89   throw (std::runtime_error);
90
91 class usrp2_source_32fc : public usrp2_source_base 
92 {
93 protected:
94   usrp2_source_32fc(const std::string &ifc, const std::string &mac);
95
96 public:
97   ~usrp2_source_32fc();
98 };
99
100 // ----------------------------------------------------------------
101
102 GR_SWIG_BLOCK_MAGIC(usrp2,source_16sc)
103
104 usrp2_source_16sc_sptr
105 usrp2_make_source_16sc(const std::string ifc="eth0", 
106                        const std::string mac="") 
107   throw (std::runtime_error);
108
109 class usrp2_source_16sc : public usrp2_source_base 
110 {
111 protected:
112   usrp2_source_16sc(const std::string &ifc, const std::string &mac);
113
114 public:
115   ~usrp2_source_16sc();
116 };
117
118 // ----------------------------------------------------------------
119
120 class usrp2_sink_base : public usrp2_base 
121 {
122 protected:
123   usrp2_sink_base() throw (std::runtime_error);
124
125 public:
126   ~usrp2_sink_base();
127
128   bool set_gain(double gain);
129   %rename(_real_set_center_freq) set_center_freq;
130   bool set_center_freq(double frequency, usrp2::tune_result *r);
131   bool set_interp(int interp_factor);
132   bool set_scale_iq(int scale_i, int scale_q);
133   int interp();
134   %rename(_real_dac_rate) dac_rate;
135   bool dac_rate(long *rate);
136   double gain_min();
137   double gain_max();
138   double gain_db_per_step();
139   double freq_min();
140   double freq_max();
141   %rename(_real_daughterboard_id) daughterboard_id;
142   bool daughterboard_id(int *dbid);
143 };
144
145 // ----------------------------------------------------------------
146
147 GR_SWIG_BLOCK_MAGIC(usrp2,sink_32fc)
148
149 usrp2_sink_32fc_sptr
150 usrp2_make_sink_32fc(const std::string ifc="eth0", 
151                      const std::string mac="") 
152   throw (std::runtime_error);
153
154 class usrp2_sink_32fc : public usrp2_sink_base 
155 {
156 protected:
157   usrp2_sink_32fc(const std::string &ifc, const std::string &mac);
158
159 public:
160   ~usrp2_sink_32fc();
161 };
162
163 // ----------------------------------------------------------------
164
165 GR_SWIG_BLOCK_MAGIC(usrp2,sink_16sc)
166
167 usrp2_sink_16sc_sptr
168 usrp2_make_sink_16sc(const std::string ifc="eth0", 
169                      const std::string mac="") 
170   throw (std::runtime_error);
171
172 class usrp2_sink_16sc : public usrp2_sink_base 
173 {
174 protected:
175   usrp2_sink_16sc(const std::string &ifc, const std::string &mac);
176
177 public:
178   ~usrp2_sink_16sc();
179 };
180
181 // ----------------------------------------------------------------
182
183 // some utility functions to allow Python to deal with pointers
184 %{
185   long *make_long_ptr() { return (long *)malloc(sizeof(long)); }
186   long deref_long_ptr(long *l) { return *l; }
187   void free_long_ptr(long *l) { free(l); }
188   int *make_int_ptr() { return (int *)malloc(sizeof(int)); }
189   int deref_int_ptr(int *l) { return *l; }
190   void free_int_ptr(int *l) { free(l); }
191 %}
192
193 long *make_long_ptr();
194 long deref_long_ptr(long *l);
195 void free_long_ptr(long *l);
196 int *make_int_ptr();
197 int deref_int_ptr(int *l);
198 void free_int_ptr(int *l);
199
200 // create a more pythonic interface
201 %pythoncode %{
202
203 def __set_center_freq(self, freq):
204   tr = tune_result()
205   r = self._real_set_center_freq(freq, tr)
206   if r:
207     return tr
208   else:
209     return None
210
211 def __fpga_master_clock_freq(self):
212   f = make_long_ptr();
213   r = self._real_fpga_master_clock_freq(f)
214   if r:
215     result = deref_long_ptr(f)
216   else:
217     result = None
218   free_long_ptr(f)
219   return result
220
221 def __adc_rate(self):
222   rate = make_long_ptr();
223   r = self._real_adc_rate(rate)
224   if r:
225     result = deref_long_ptr(rate)
226   else:
227     result = None
228   free_long_ptr(rate)
229   return result
230
231 def __dac_rate(self):
232   rate = make_long_ptr();
233   r = self._real_dac_rate(rate)
234   if r:
235     result = deref_long_ptr(rate)
236   else:
237     result = None
238   free_long_ptr(rate)
239   return result
240
241 def __gain_range(self):
242   return [self.gain_min(),
243           self.gain_max(),
244           self.gain_db_per_step()]
245
246 # NOTE: USRP1 uses a length three tuple here (3rd value is 'freq step'),
247 #       but it's not really useful.  We let an index error happen here
248 #       to identify code using it.
249 def __freq_range(self):
250   return [self.freq_min(),
251           self.freq_max()]
252
253 def __daughterboard_id(self):
254   dbid = make_int_ptr();
255   r = self._real_daughterboard_id(dbid)
256   if r:
257     result = deref_int_ptr(dbid)
258   else:
259     result = None
260   free_int_ptr(dbid)
261   return result
262
263 usrp2_source_32fc_sptr.set_center_freq = __set_center_freq
264 usrp2_source_16sc_sptr.set_center_freq = __set_center_freq
265 usrp2_sink_32fc_sptr.set_center_freq = __set_center_freq
266 usrp2_sink_16sc_sptr.set_center_freq = __set_center_freq
267
268 usrp2_source_32fc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
269 usrp2_source_16sc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
270 usrp2_sink_32fc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
271 usrp2_sink_16sc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
272
273 usrp2_source_32fc_sptr.adc_rate = __adc_rate
274 usrp2_source_16sc_sptr.adc_rate = __adc_rate
275 usrp2_sink_32fc_sptr.dac_rate = __dac_rate
276 usrp2_sink_16sc_sptr.dac_rate = __dac_rate
277
278 usrp2_source_32fc_sptr.gain_range = __gain_range
279 usrp2_source_16sc_sptr.gain_range = __gain_range
280 usrp2_sink_32fc_sptr.gain_range = __gain_range
281 usrp2_sink_16sc_sptr.gain_range = __gain_range
282
283 usrp2_source_32fc_sptr.freq_range = __freq_range
284 usrp2_source_16sc_sptr.freq_range = __freq_range
285 usrp2_sink_32fc_sptr.freq_range = __freq_range
286 usrp2_sink_16sc_sptr.freq_range = __freq_range
287
288 usrp2_source_32fc_sptr.daughterboard_id = __daughterboard_id
289 usrp2_source_16sc_sptr.daughterboard_id = __daughterboard_id
290 usrp2_sink_32fc_sptr.daughterboard_id = __daughterboard_id
291 usrp2_sink_16sc_sptr.daughterboard_id = __daughterboard_id
292
293 %}