Merged r10288:10370 from michaelld/swigpythonargs into trunk. Passes distcheck.
[debian/gnuradio] / gr-msdd6000 / src / msdd.i
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,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(module="gnuradio_swig_py_runtime") "gnuradio.i" // the common stuff
26
27 %{
28 #include "gnuradio_swig_bug_workaround.h"       // mandatory bug fix
29 #include "msdd_source_s.h"
30 #include "msdd_source_c.h"
31 #include "msdd_source_simple.h"
32 %}
33
34 // ================================================================
35 //                         abstract classes
36 // ================================================================
37
38 // ----------------------------------------------------------------
39
40 class msdd_source_base : public gr_sync_block {
41
42  protected:
43   msdd_source_base (const std::string &name,
44       gr_io_signature_sptr output_signature,
45       int which_board,
46       msdd_source_base::msdd_command_type_t opp_mode,
47       const char *src, 
48       unsigned short port_src
49          ) throw (std::runtime_error);
50
51   /*!
52    * \brief number of bytes in a low-level sample
53    */
54   unsigned int sizeof_basic_sample() const;
55
56   /*!
57    * \brief convert between native msdd format and output item format
58    *
59    * \param output_items[out]   stream(s) of output items
60    * \param output_index[in]    starting index in output_items
61    * \param output_items_available[in]  number of empty items available at item[index]
62    * \param output_items_produced[out]  number of items produced by copy
63    * \param msdd_buffer[in]   source buffer
64    * \param msdd_buffer_length[in]  number of bytes available in \p msdd_buffer
65    * \param bytes_read[out]   number of bytes read from \p msdd_buffer
66    *
67    * The copy must consume all bytes available.  That is, \p bytes_read must equal
68    * \p msdd_buffer_length.
69    */
70   virtual void copy_from_msdd_buffer (gr_vector_void_star &output_items,
71               int output_index,
72               int output_items_available,
73               int &output_items_produced,
74               const void *msdd_buffer,
75               int msdd_buffer_length,
76               int &bytes_read) = 0;
77   
78   int readsock(int sockfd, unsigned char* buf, int nbytes);
79
80   
81   void* make_request_packet(unsigned int& size, unsigned int number_samples);
82   
83  public:
84   //! magic value used on alternate register read interfaces
85   static const int READ_FAILED = -99999;
86
87   ~msdd_source_base ();
88
89   int work (int noutput_items,
90       gr_vector_const_void_star &input_items,
91       gr_vector_void_star &output_items);
92
93   bool start();
94   bool stop();
95
96   /*!
97    * \brief Set Programmable Gain Amplifier (PGA)
98    *
99    * \param which       which D/A [0,3]
100    * \param gain_in_db  gain value (linear in dB)
101    *
102    * gain is rounded to closest setting supported by hardware.
103    * Note that DAC 0 and DAC 1 share a gain setting as do DAC 2 and DAC 3.
104    * Setting DAC 0 affects DAC 1 and vice versa.  Same with DAC 2 and DAC 3.
105    *
106    * \returns true iff sucessful.
107    *
108    * \sa pga_min(), pga_max(), pga_db_per_step()
109    */
110   bool set_pga (int which, double gain_in_db);
111
112   /*!
113    * \brief Return programmable gain amplifier gain in dB.
114    *
115    * \param which       which D/A [0,3]
116    */
117   double pga (int which) const;
118
119   /*!
120    * \brief Return minimum legal PGA gain in dB.
121    */
122   double pga_min () const;
123
124   /*!
125    * \brief Return maximum legal PGA gain in dB.
126    */
127   double pga_max () const;
128
129   /*!
130    * \brief Return hardware step size of PGA (linear in dB).
131    */
132   double pga_db_per_step () const;
133
134   /*!
135    * \brief open a socket specified by the port and ip address info
136    *
137    * Opens a socket, binds to the address, and waits for a connection
138    * over UDP. If any of these fail, the fuction retuns the error and exits.
139    */
140   bool open();
141
142   /*!
143    * \brief Close current socket.
144    *
145    * Shuts down read/write on the socket
146    */
147   bool close();
148   
149   /*!
150    * \brief Set decimator rate.  \p rate must be EVEN and in [8, 256].
151    *
152    * The final complex sample rate across the USB is
153    *   adc_freq () / decim_rate ()
154    */
155   bool set_decim_rate (unsigned int rate);
156
157   /*!
158    * \brief set the center frequency of the digital down converter.
159    *
160    * \p channel must be 0.  \p freq is the center frequency in Hz.
161    * It must be in the range [-FIXME, FIXME].  The frequency specified is
162    * quantized.  Use rx_freq to retrieve the actual value used.
163    */
164   bool set_rx_freq (int channel, double freq);
165
166   void set_verbose (bool verbose);
167
168   // ACCESSORS
169
170   unsigned int decim_rate () const;
171   double rx_freq (int channel) const;
172   int noverruns () const { return d_noverruns; }
173
174   /*!
175    * \brief return the msdd's serial number.
176    *
177    * \returns non-zero length string iff successful.
178    */
179   std::string serial_number();
180   
181   bool set_desired_packet_size (int which, unsigned long packet_size);
182
183   unsigned long desired_packet_size (int which) const;
184
185 };
186
187
188 // ================================================================
189 //      concrete sources
190 // ================================================================
191
192
193 // ----------------------------------------------------------------
194
195 GR_SWIG_BLOCK_MAGIC(msdd,source_s)
196
197 msdd_source_s_sptr
198 msdd_make_source_s (int which_board, 
199             unsigned int decim_rate,
200             unsigned int fft_points,
201             double initial_rx_freq,
202             int opp_mode,
203             const char *src, 
204             unsigned short port_src
205          ) throw (std::runtime_error);
206
207
208 class msdd_source_s : public msdd_source_base {
209  protected:
210   msdd_source_s (int which_board, 
211       unsigned int decim_rate,
212       unsigned int fft_points,
213       double initial_rx_freq,
214       int opp_mode,
215           const char *src, 
216           unsigned short port_src
217       ) throw (std::runtime_error);
218
219  public:
220   ~msdd_source_s ();
221 };
222
223
224 GR_SWIG_BLOCK_MAGIC(msdd,source_c)
225
226 msdd_source_c_sptr
227 msdd_make_source_c (int which_board, 
228             int opp_mode,
229             const char *src, 
230             unsigned short port_src
231          ) throw (std::runtime_error);
232
233
234 class msdd_source_c : public msdd_source_base {
235  protected:
236   msdd_source_c (int which_board, 
237       int opp_mode,
238           const char *src, 
239           unsigned short port_src
240       ) throw (std::runtime_error);
241
242  public:
243   ~msdd_source_c ();
244 };
245
246
247
248
249
250 GR_SWIG_BLOCK_MAGIC(msdd,source_simple)
251
252 msdd_source_simple_sptr
253 msdd_make_source_simple (
254         const char *src,
255         unsigned short port_src
256         );
257
258 class msdd_source_simple : public gr_sync_block {
259   protected:
260     msdd_source_simple(
261         const char *src,
262         unsigned short port_src
263         );
264  
265   public:
266     ~msdd_source_c(); 
267   int work (int noutput_items,
268       gr_vector_const_void_star &input_items,
269       gr_vector_void_star &output_items);
270
271   bool start();
272   bool stop();
273
274   long adc_freq();
275   int decim_rate();
276   gr_vector_int gain_range();
277   gr_vector_float freq_range();
278
279   bool set_decim_rate(unsigned int);
280   bool set_rx_freq(int,double);
281   bool set_pga(int,double);
282   
283
284   };