c979750a825fff8929caa0dd615452ad33332514
[debian/gnuradio] / gr-usrp2 / src / usrp2.i
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2009 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 %import "gnuradio.i"    // the common stuff
26 %import <stdint.i>     
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 %template(uint32_t_vector) std::vector<uint32_t>;
39
40 // ----------------------------------------------------------------
41
42 class usrp2_base : public gr_sync_block 
43 {
44 protected:
45   usrp2_base() throw (std::runtime_error);
46
47 public:
48   ~usrp2_base();
49
50   std::string mac_addr() const;
51   %rename(_real_fpga_master_clock_freq) fpga_master_clock_freq;
52   bool fpga_master_clock_freq(long *freq);
53   bool sync_to_pps();
54   std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
55   bool poke32(uint32_t addr, const std::vector<uint32_t> &data);
56 };
57
58 // ----------------------------------------------------------------
59
60 class usrp2_source_base : public usrp2_base 
61 {
62 protected:
63   usrp2_source_base() throw (std::runtime_error);
64
65 public:
66   ~usrp2_source_base();
67
68   bool set_gain(double gain);
69   %rename(_real_set_center_freq) set_center_freq;
70   bool set_center_freq(double frequency, usrp2::tune_result *r);
71   bool set_decim(int decimation_factor);
72   bool set_scale_iq(int scale_i, int scale_q);
73   int decim();
74   %rename(_real_adc_rate) adc_rate;
75   bool adc_rate(long *rate);
76   double gain_min();
77   double gain_max();
78   double gain_db_per_step();
79   double freq_min();
80   double freq_max();
81   %rename(_real_daughterboard_id) daughterboard_id;
82   bool daughterboard_id(int *dbid);
83   unsigned int overruns();
84   unsigned int missing();
85 };
86
87 // ----------------------------------------------------------------
88
89 GR_SWIG_BLOCK_MAGIC(usrp2,source_32fc)
90
91 usrp2_source_32fc_sptr
92 usrp2_make_source_32fc(const std::string ifc="eth0", 
93                        const std::string mac="") 
94   throw (std::runtime_error);
95
96 class usrp2_source_32fc : public usrp2_source_base 
97 {
98 protected:
99   usrp2_source_32fc(const std::string &ifc, const std::string &mac);
100
101 public:
102   ~usrp2_source_32fc();
103 };
104
105 // ----------------------------------------------------------------
106
107 GR_SWIG_BLOCK_MAGIC(usrp2,source_16sc)
108
109 usrp2_source_16sc_sptr
110 usrp2_make_source_16sc(const std::string ifc="eth0", 
111                        const std::string mac="") 
112   throw (std::runtime_error);
113
114 class usrp2_source_16sc : public usrp2_source_base 
115 {
116 protected:
117   usrp2_source_16sc(const std::string &ifc, const std::string &mac);
118
119 public:
120   ~usrp2_source_16sc();
121 };
122
123 // ----------------------------------------------------------------
124
125 class usrp2_sink_base : public usrp2_base 
126 {
127 protected:
128   usrp2_sink_base() throw (std::runtime_error);
129
130 public:
131   ~usrp2_sink_base();
132
133   bool set_gain(double gain);
134   %rename(_real_set_center_freq) set_center_freq;
135   bool set_center_freq(double frequency, usrp2::tune_result *r);
136   bool set_interp(int interp_factor);
137   bool set_scale_iq(int scale_i, int scale_q);
138   int interp();
139   %rename(_real_default_tx_scale_iq) default_scale_iq;
140   void default_scale_iq(int interp, int *scale_i, int *scale_q);
141   %rename(_real_dac_rate) dac_rate;
142   bool dac_rate(long *rate);
143   double gain_min();
144   double gain_max();
145   double gain_db_per_step();
146   double freq_min();
147   double freq_max();
148   %rename(_real_daughterboard_id) daughterboard_id;
149   bool daughterboard_id(int *dbid);
150 };
151
152 // ----------------------------------------------------------------
153
154 GR_SWIG_BLOCK_MAGIC(usrp2,sink_32fc)
155
156 usrp2_sink_32fc_sptr
157 usrp2_make_sink_32fc(const std::string ifc="eth0", 
158                      const std::string mac="") 
159   throw (std::runtime_error);
160
161 class usrp2_sink_32fc : public usrp2_sink_base 
162 {
163 protected:
164   usrp2_sink_32fc(const std::string &ifc, const std::string &mac);
165
166 public:
167   ~usrp2_sink_32fc();
168 };
169
170 // ----------------------------------------------------------------
171
172 GR_SWIG_BLOCK_MAGIC(usrp2,sink_16sc)
173
174 usrp2_sink_16sc_sptr
175 usrp2_make_sink_16sc(const std::string ifc="eth0", 
176                      const std::string mac="") 
177   throw (std::runtime_error);
178
179 class usrp2_sink_16sc : public usrp2_sink_base 
180 {
181 protected:
182   usrp2_sink_16sc(const std::string &ifc, const std::string &mac);
183
184 public:
185   ~usrp2_sink_16sc();
186 };
187
188 // ----------------------------------------------------------------
189
190 // some utility functions to allow Python to deal with pointers
191 %{
192   long *make_long_ptr() { return (long *)malloc(sizeof(long)); }
193   long deref_long_ptr(long *l) { return *l; }
194   void free_long_ptr(long *l) { free(l); }
195   int *make_int_ptr() { return (int *)malloc(sizeof(int)); }
196   int deref_int_ptr(int *l) { return *l; }
197   void free_int_ptr(int *l) { free(l); }
198 %}
199
200 long *make_long_ptr();
201 long deref_long_ptr(long *l);
202 void free_long_ptr(long *l);
203 int *make_int_ptr();
204 int deref_int_ptr(int *l);
205 void free_int_ptr(int *l);
206
207 // create a more pythonic interface
208 %pythoncode %{
209
210 def __set_center_freq(self, freq):
211   tr = tune_result()
212   r = self._real_set_center_freq(freq, tr)
213   if r:
214     return tr
215   else:
216     return None
217
218 def __fpga_master_clock_freq(self):
219   f = make_long_ptr();
220   r = self._real_fpga_master_clock_freq(f)
221   if r:
222     result = deref_long_ptr(f)
223   else:
224     result = None
225   free_long_ptr(f)
226   return result
227
228 def __adc_rate(self):
229   rate = make_long_ptr();
230   r = self._real_adc_rate(rate)
231   if r:
232     result = deref_long_ptr(rate)
233   else:
234     result = None
235   free_long_ptr(rate)
236   return result
237
238 def __dac_rate(self):
239   rate = make_long_ptr();
240   r = self._real_dac_rate(rate)
241   if r:
242     result = deref_long_ptr(rate)
243   else:
244     result = None
245   free_long_ptr(rate)
246   return result
247
248 def __gain_range(self):
249   return [self.gain_min(),
250           self.gain_max(),
251           self.gain_db_per_step()]
252
253 # NOTE: USRP1 uses a length three tuple here (3rd value is 'freq step'),
254 #       but it's not really useful.  We let an index error happen here
255 #       to identify code using it.
256 def __freq_range(self):
257   return [self.freq_min(),
258           self.freq_max()]
259
260 def __daughterboard_id(self):
261   dbid = make_int_ptr()
262   r = self._real_daughterboard_id(dbid)
263   if r:
264     result = deref_int_ptr(dbid)
265   else:
266     result = None
267   free_int_ptr(dbid)
268   return result
269
270 def __default_tx_scale_iq(self, interp):
271   scale_i = make_int_ptr()
272   scale_q = make_int_ptr()
273   self._real_default_tx_scale_iq(interp, scale_i, scale_q)
274   return (deref_int_ptr(scale_i), deref_int_ptr(scale_q))
275
276 usrp2_source_32fc_sptr.set_center_freq = __set_center_freq
277 usrp2_source_16sc_sptr.set_center_freq = __set_center_freq
278 usrp2_sink_32fc_sptr.set_center_freq = __set_center_freq
279 usrp2_sink_16sc_sptr.set_center_freq = __set_center_freq
280
281 usrp2_source_32fc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
282 usrp2_source_16sc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
283 usrp2_sink_32fc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
284 usrp2_sink_16sc_sptr.fpga_master_clock_freq = __fpga_master_clock_freq
285
286 usrp2_source_32fc_sptr.adc_rate = __adc_rate
287 usrp2_source_16sc_sptr.adc_rate = __adc_rate
288 usrp2_sink_32fc_sptr.dac_rate = __dac_rate
289 usrp2_sink_16sc_sptr.dac_rate = __dac_rate
290
291 usrp2_source_32fc_sptr.gain_range = __gain_range
292 usrp2_source_16sc_sptr.gain_range = __gain_range
293 usrp2_sink_32fc_sptr.gain_range = __gain_range
294 usrp2_sink_16sc_sptr.gain_range = __gain_range
295
296 usrp2_source_32fc_sptr.freq_range = __freq_range
297 usrp2_source_16sc_sptr.freq_range = __freq_range
298 usrp2_sink_32fc_sptr.freq_range = __freq_range
299 usrp2_sink_16sc_sptr.freq_range = __freq_range
300
301 usrp2_source_32fc_sptr.daughterboard_id = __daughterboard_id
302 usrp2_source_16sc_sptr.daughterboard_id = __daughterboard_id
303 usrp2_sink_32fc_sptr.daughterboard_id = __daughterboard_id
304 usrp2_sink_16sc_sptr.daughterboard_id = __daughterboard_id
305
306 usrp2_sink_32fc_sptr.default_scale_iq = __default_tx_scale_iq
307 usrp2_sink_16sc_sptr.default_scale_iq = __default_tx_scale_iq
308
309 %}