Imported Upstream version 3.2.2
[debian/gnuradio] / gr-usrp / src / usrp_sink_c.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 #include <usrp_sink_c.h>
28 #include <gr_io_signature.h>
29 #include <usrp_standard.h>
30 #include <usrp_bytesex.h>
31
32 usrp_sink_c_sptr
33 usrp_make_sink_c (int which_board,
34                    unsigned int interp_rate,
35                    int nchan,
36                    int mux,
37                    int fusb_block_size,
38                    int fusb_nblocks,
39                    const std::string fpga_filename,
40                    const std::string firmware_filename
41                    ) throw (std::runtime_error)
42 {
43   return usrp_sink_c_sptr (new usrp_sink_c (which_board,
44                                               interp_rate,
45                                               nchan,
46                                               mux,
47                                               fusb_block_size,
48                                               fusb_nblocks,
49                                               fpga_filename,
50                                               firmware_filename
51                                               ));
52 }
53
54
55 usrp_sink_c::usrp_sink_c (int which_board,
56                             unsigned int interp_rate,
57                             int nchan,
58                             int mux,
59                             int fusb_block_size,
60                             int fusb_nblocks,
61                             const std::string fpga_filename,
62                             const std::string firmware_filename
63                             ) throw (std::runtime_error)
64   : usrp_sink_base ("usrp_sink_c",
65                      gr_make_io_signature (1, 1, sizeof (gr_complex)),
66                      which_board, interp_rate, nchan, mux,
67                      fusb_block_size, fusb_nblocks,
68                      fpga_filename, firmware_filename)
69 {
70 }
71
72 usrp_sink_c::~usrp_sink_c ()
73 {
74   // NOP
75 }
76
77 /*
78  * Take one complex input stream and format it into interleaved short I & Q
79  * for the usrp.
80  */
81 void
82 usrp_sink_c::copy_to_usrp_buffer (gr_vector_const_void_star &input_items,
83                                    int  input_index,
84                                    int  input_items_available,
85                                    int  &input_items_consumed,  // out
86                                    void *usrp_buffer,
87                                    int  usrp_buffer_length,
88                                    int  &bytes_written)         // out
89 {
90   gr_complex *in = &((gr_complex *) input_items[0])[input_index];
91   short *dst = (short *) usrp_buffer;
92
93   static const int usrp_bytes_per_input_item = 2 * sizeof (short); // I & Q
94
95   int nitems = std::min (input_items_available,
96                          usrp_buffer_length / usrp_bytes_per_input_item);
97
98   for (int i = 0; i < nitems; i++){
99     dst[2*i + 0] = host_to_usrp_short((short) real(in[i]));     // FIXME saturate?
100     dst[2*i + 1] = host_to_usrp_short((short) imag(in[i]));     // FIXME saturate?
101   }
102
103   input_items_consumed = nitems;
104   bytes_written = nitems * usrp_bytes_per_input_item;
105 }
106