msdd6000 source upgraded and enabled
[debian/gnuradio] / gr-msdd6000 / src / msdd_source_s.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2006 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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #define MSDD_DEBUG2_TRUE
28
29 #ifdef MSDD_DEBUG2_TRUE
30 #include <iostream>
31 #define MSDD_DEBUG2(x) std::cout << x << std::endl;
32 #else
33 #define MSDD_DEBUG2(x)
34 #endif
35
36 #include <msdd_source_s.h>
37 #include <gr_io_signature.h>
38
39 namespace {
40         static const int NBASIC_SAMPLES_PER_ITEM = 1;
41 }
42
43 msdd_source_s_sptr
44 msdd_make_source_s (int which_board, 
45             unsigned int decim_rate,
46             unsigned int fft_points,
47             double initial_rx_freq,
48             int opp_mode,
49             const char *src, 
50             unsigned short port_src
51                      ) throw (std::runtime_error)
52 {
53   return msdd_source_s_sptr (new msdd_source_s (which_board,
54                                                   decim_rate,
55                                                   fft_points,
56                                                   initial_rx_freq,
57                                               opp_mode,
58                                                   src,
59                                                   port_src
60                                                   ));
61 }
62
63
64 msdd_source_s::msdd_source_s (int which_board,
65                                 unsigned int decim_rate,
66                                 unsigned int fft_points,
67                                 double initial_rx_freq,
68                                 int opp_mode,
69                     const char *src, 
70                     unsigned short port_src
71                                 ) throw (std::runtime_error)
72   : msdd_source_base ("msdd_source_s",
73                        gr_make_io_signature (1, 1, sizeof (int)),
74                        which_board, opp_mode, src, port_src
75                        )
76 {
77
78   switch (sizeof_basic_sample()) {
79   case 1:
80        d_buffer_copy_behavior.reset(
81         new msdd::BufferCopyBehaviorGeneric<short, unsigned char>());
82     break;
83   case 2:
84        d_buffer_copy_behavior.reset(
85         new msdd::BufferCopyBehaviorGeneric<short, float>());
86     break;
87   case 4:
88        d_buffer_copy_behavior.reset(
89         new msdd::BufferCopyBehaviorGeneric<short, int>());
90     break;
91   default:
92        assert(false);
93   }
94
95 }
96
97 msdd_source_s::~msdd_source_s ()
98 {
99 }
100
101 int
102 msdd_source_s::ninput_bytes_reqd_for_noutput_items (int noutput_items)
103 {
104   return noutput_items * NBASIC_SAMPLES_PER_ITEM * sizeof_basic_sample();
105 }
106
107 void
108 msdd_source_s::copy_from_msdd_buffer (gr_vector_void_star &output_items,
109                                        int output_index,
110                                        int output_items_available,
111                                        int &output_items_produced,
112                                        const void *msdd_buffer,
113                                        int buffer_length,
114                                        int &bytes_read)
115 {
116   MSDD_DEBUG2("copy_from_msdd_buffer: output_index: " << output_index << " output_items_available: " << output_items_available << " buflen: " << buffer_length)
117
118   unsigned nmsdd_bytes_per_item 
119     (msdd_source_s::ninput_bytes_reqd_for_noutput_items(1));
120   
121   unsigned int nitems = std::min (output_items_available,
122                          (int)(buffer_length / nmsdd_bytes_per_item));
123   
124   MSDD_DEBUG2("copy_from_msdd_buffer: nmsdd_bytes_per_item: " << nmsdd_bytes_per_item << " nitems: " << nitems)
125
126   (*d_buffer_copy_behavior.get())(output_items, msdd_buffer, output_index, nitems);
127
128   output_items_produced = nitems;
129   bytes_read = nitems * nmsdd_bytes_per_item;
130 }