Imported Upstream version 3.2.2
[debian/gnuradio] / gr-usrp2 / src / rx_16sc_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_16SC_HANDLER_H
24 #define INCLUDED_RX_16SC_HANDLER_H
25
26 #include <usrp2/rx_nop_handler.h>
27 #include <usrp2/copiers.h>
28
29 class rx_16sc_handler : public usrp2::rx_nop_handler
30 {
31   std::complex<int16_t> *d_dest;
32
33   // Private constructor
34   rx_16sc_handler(uint64_t max_samples, uint64_t max_quantum, std::complex<int16_t> *dest)
35     : rx_nop_handler(max_samples, max_quantum), d_dest(dest) {}
36
37 public:
38   // Shared pointer to one of these
39   typedef boost::shared_ptr<rx_16sc_handler> sptr;
40
41   // Factory function to return a shared pointer to a new instance
42   static sptr make(uint64_t max_samples, uint64_t max_quantum, std::complex<int16_t> *dest) 
43   {
44     return sptr(new rx_16sc_handler(max_samples, max_quantum, dest));
45   }
46
47   // Invoked by USRP2 API when samples are available
48   bool operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata)
49   {
50     // Copy/reformat/endian swap USRP2 data to destination buffer
51     usrp2::copy_u2_16sc_to_host_16sc(nitems, items, d_dest);
52     d_dest += nitems;
53
54     // FIXME: do something with metadata
55
56     // Call parent to determine if there is room to be called again
57     return rx_nop_handler::operator()(items, nitems, metadata);
58   }
59
60   ~rx_16sc_handler();
61 };
62
63 #endif /* INCLUDED_RX_16SC_HANDLER_H */