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