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