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