Renamed identifiers for consistency: s/complex_float/32fc/ s/complex_16/16sc/.
[debian/gnuradio] / gr-usrp2 / src / rx_32fc_handler.h
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 #ifndef INCLUDED_RX_32FC_HANDLER_H
24 #define INCLUDED_RX_32FC_HANDLER_H
25
26 #include <usrp2/rx_nop_handler.h>
27 #include <usrp2/copiers.h>
28 #include <gr_complex.h>
29
30 #define RX_32FC_HANDLER_DEBUG 0
31
32 class rx_32fc_handler : public usrp2::rx_nop_handler
33 {
34   gr_complex *d_dest;
35
36   // Private constructor
37   rx_32fc_handler(uint64_t max_samples, uint64_t max_quantum, gr_complex *dest)
38     : rx_nop_handler(max_samples, max_quantum), d_dest(dest) {}
39
40 public:
41   // Shared pointer to one of these
42   typedef boost::shared_ptr<rx_32fc_handler> sptr;
43
44   // Factory function to return a shared pointer to a new instance
45   static sptr make(uint64_t max_samples, uint64_t max_quantum, gr_complex *dest) 
46   {
47     if (RX_32FC_HANDLER_DEBUG)
48       printf("rx_32fc_handler: max_samples=%li max_quantum=%li\n", max_samples, max_quantum);
49       
50     return sptr(new rx_32fc_handler(max_samples, max_quantum, dest));
51   }
52
53   // Invoked by USRP2 API when samples are available
54   bool operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata)
55   {
56     if (RX_32FC_HANDLER_DEBUG)
57       printf("rx_32fc_handler: called with items=%zu ", nitems);
58
59     // Copy/reformat/endian swap USRP2 data to destination buffer
60     usrp2::copy_u2_16sc_to_host_32fc(nitems, items, d_dest);
61     d_dest += nitems;
62
63     // FIXME: do something with metadata
64
65     // Determine if there is room to be called again
66     bool ok = rx_nop_handler::operator()(items, nitems, metadata);
67     if (RX_32FC_HANDLER_DEBUG)
68       printf("ok to call again=%i\n", ok);
69
70     return ok;
71   }
72
73   ~rx_32fc_handler();
74 };
75
76 #endif /* INCLUDED_RX_32FC_HANDLER_H */