msdd6000 source upgraded and enabled
[debian/gnuradio] / gr-msdd6000 / src / msdd_source_base.h
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 #ifndef INCLUDED_MSDD_SOURCE_BASE_H
24 #define INCLUDED_MSDD_SOURCE_BASE_H
25 #include <gr_sync_block.h>
26 #include <stdexcept>
27
28 /*!
29  * \brief abstract interface to MSDD 6000 Softronics module Rx path (Rev 1)
30  */
31
32 class msdd_source_base : public gr_sync_block {
33 public: 
34   enum msdd_command_type_t {
35     COMMAND_STATUS = 0,
36     SAMPLES_REALTIME = 1,
37     SAMPLES_FFT = 2,
38   };
39      
40    enum msdd_fft_window_type_t {
41      WINDOW_RECTANGLE = 0,
42      WINDOW_HANNING = 1,
43      WINDOW_HAMMING = 2,
44      WINDOW_BLACKMAN = 3
45    };
46    
47    enum msdd_fft_mode_t {
48      MODE_IQ=0, 
49      MODE_MAG=1, 
50      MODE_MAGDB=2
51    };
52    
53    enum msdd_decimation_t {
54      D0=0, 
55      D1=1, 
56      D2=2, 
57      D3=3, 
58      D4=4, 
59      D5=5, 
60      D6=6, 
61      D7=7, 
62      D8=8
63    };    
64    
65    enum msdd_fft_points_t {
66      S256=8, 
67      S512=9, 
68      S1024=10, 
69      S2048=11, 
70      S4096=12, 
71      S8192=13, 
72      S16384=14, 
73      S32768=15
74    };
75    
76  private:
77    
78   class Impl;
79   friend class Impl;
80   std::auto_ptr<Impl> pimpl;
81
82   
83  protected:
84    
85   msdd_source_base (const std::string &name,
86       gr_io_signature_sptr output_signature,
87       int which_board,
88       int opp_mode,
89       const char *src, 
90       unsigned short port_src
91                      ) throw (std::runtime_error);
92
93   /*!
94    * \brief return number of msdd input bytes required to produce noutput items.
95    */
96   virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0;
97
98   /*!
99    * \brief number of bytes in a low-level sample
100    */
101   unsigned int sizeof_basic_sample() const;
102
103   virtual void copy_from_msdd_buffer (gr_vector_void_star &output_items,
104                                       int output_index,
105                                       int output_items_available,
106                                       int &output_items_produced,
107                                       const void *msdd_buffer,
108                                       int msdd_buffer_length,
109                                       int &bytes_read) = 0;
110   
111   int readsock(int sockfd, unsigned char* buf, int nbytes);
112   
113   void* make_request_packet(unsigned int& size, unsigned int number_samples);
114   
115   unsigned long set_fft_size (int channel, unsigned long fft_size);
116   
117  public:
118   //! magic value used on alternate register read interfaces
119   static const int READ_FAILED = -99999;
120
121   ~msdd_source_base ();
122
123   int work (int noutput_items,
124             gr_vector_const_void_star &input_items,
125             gr_vector_void_star &output_items);
126
127   bool start();
128   bool stop();
129
130   /*!
131    * \brief open a socket specified by the port and ip address info
132    *
133    * Opens a socket, binds to the address, and waits for a connection
134    * over UDP. If any of these fail, the fuction retuns the error and exits.
135    */
136   bool open();
137
138   /*!
139    * \brief Close current socket.
140    *
141    * Shuts down read/write on the socket
142    */
143   bool close();
144   
145   /*!
146    * \brief Set decimator rate.  \p rate must be EVEN and in [8, 256].
147    *
148    * The final complex sample rate across the USB is
149    *   adc_freq () / decim_rate ()
150    */
151   bool set_decim_rate (unsigned int rate);
152   //bool set_nchannels (int nchan);
153   //bool set_mux (int mux);
154
155   /*!
156    * \brief set the center frequency of the digital down converter.
157    *
158    * \p channel must be 0.  \p freq is the center frequency in Hz.
159    * It must be in the range [-FIXME, FIXME].  The frequency specified is
160    * quantized.  Use rx_freq to retrieve the actual value used.
161    */
162   bool set_rx_freq (int channel, double freq);
163
164   /*!
165    * \brief
166    */
167   bool set_opp_mode (int channel, msdd_command_type_t mode);
168   
169 //
170 //  /*!
171 //   * \brief set fpga special modes
172 //   */
173 //  bool set_fpga_mode (int mode);
174
175   void set_verbose (bool verbose);
176 //
177 //  /*!
178 //   * \brief Set the digital down converter phase register.
179 //   *
180 //   * \param channel   which ddc channel [0, 3]
181 //   * \param phase     32-bit integer phase value.
182 //   */
183 //  bool set_ddc_phase(int channel, int phase);
184 //
185   /*!
186    * \brief Set Programmable Gain Amplifier (PGA)
187    *
188    * \param which       which A/D [0,3]
189    * \param gain_in_db  gain value (linear in dB)
190    *
191    * gain is rounded to closest setting supported by hardware.
192    *
193    * \returns true iff sucessful.
194    *
195    * \sa pga_min(), pga_max(), pga_db_per_step()
196    */
197   bool set_pga (int which, double gain_in_db);
198
199   /*!
200    * \brief Return programmable gain amplifier gain setting in dB.
201    *
202    * \param which       which A/D [0,3]
203    */
204   double pga (int which) const;
205
206   /*!
207    * \brief Return minimum legal PGA setting in dB.
208    */
209   double pga_min () const;
210
211   /*!
212    * \brief Return maximum legal PGA setting in dB.
213    */
214   double pga_max () const;
215
216   /*!
217    * \brief Return hardware step size of PGA (linear in dB).
218    */
219   double pga_db_per_step () const;
220
221   // ACCESSORS
222
223 //  long converter_rate() const;
224
225   unsigned int decim_rate () const;
226 //  int nchannels () const;
227 //  int mux () const;
228   double rx_freq (int channel) const;
229   unsigned int fft_points() const;
230   int noverruns () const;
231
232   /*!
233    * \brief return the msdd's serial number.
234    *
235    * \returns non-zero length string iff successful.
236    */
237   std::string serial_number();
238
239 //  /*!
240 //   * \brief Enable/disable automatic DC offset removal control loop in FPGA
241 //   *
242 //   * \param bits  which control loops to enable
243 //   * \param mask  which \p bits to pay attention to
244 //   *
245 //   * If the corresponding bit is set, enable the automatic DC
246 //   * offset correction control loop.
247 //   *
248 //   * <pre>
249 //   * The 4 low bits are significant:
250 //   *
251 //   *   ADC0 = (1 << 0)
252 //   *   ADC1 = (1 << 1)
253 //   *   ADC2 = (1 << 2)
254 //   *   ADC3 = (1 << 3)
255 //   * </pre>
256 //   *
257 //   * By default the control loop is enabled on all ADC's.
258 //   */
259 //  bool set_dc_offset_cl_enable(int bits, int mask);
260
261   /*!
262    * \brief Specify Rx data format.
263    *
264    * \param format      format specifier
265    *
266    * Rx data format control register
267    *
268    *     3                   2                   1                       
269    *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
270    *  +-----------------------------------------+-+-+---------+-------+
271    *  |          Reserved (Must be zero)        |B|Q|  WIDTH  | SHIFT |
272    *  +-----------------------------------------+-+-+---------+-------+
273    *
274    *  SHIFT specifies arithmetic right shift [0, 15]
275    *  WIDTH specifies bit-width of I & Q samples across the USB [1, 16] (not all valid)
276    *  Q     if set deliver both I & Q, else just I
277    *  B     if set bypass half-band filter.
278    *
279    * Right now the acceptable values are:
280    *
281    *   B  Q  WIDTH  SHIFT
282    *   0  1    16     0
283    *   0  1     8     8
284    *
285    * More valid combos to come.
286    *
287    * Default value is 0x00000300  16-bits, 0 shift, deliver both I & Q.
288    */
289 //  bool set_format(unsigned int format);
290
291   /*!
292    * \brief return current format
293    */
294 //  unsigned int format () const;
295 //
296 //  static unsigned int make_format(int width=16, int shift=0,
297 //                                bool want_q=true, bool bypass_halfband=false);
298 //  static int format_width(unsigned int format);
299 //  static int format_shift(unsigned int format);
300 //  static bool format_want_q(unsigned int format);
301 //  static bool format_bypass_halfband(unsigned int format);
302
303     bool set_desired_packet_size (int which, unsigned long packet_size);
304
305     unsigned long desired_packet_size (int which) const;
306 };
307
308 #endif /* INCLUDED_MSDD_SOURCE_BASE_H */