switch source package format to 3.0 quilt
[debian/gnuradio] / gr-usrp2 / src / usrp2_sink_32fc.cc
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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <usrp2_sink_32fc.h>
28 #include <usrp2/metadata.h>
29 #include <gr_io_signature.h>
30 #include <iostream>
31
32 // FIXME hack until VRT replaces libusrp2
33 #define U2_MIN_SAMPLES 9
34
35 usrp2_sink_32fc_sptr
36 usrp2_make_sink_32fc(const std::string &ifc, const std::string &mac_addr) 
37   throw (std::runtime_error)
38 {
39   return gnuradio::get_initial_sptr(new usrp2_sink_32fc(ifc, mac_addr));
40 }
41
42 usrp2_sink_32fc::usrp2_sink_32fc(const std::string &ifc, const std::string &mac_addr) 
43   throw (std::runtime_error)
44   : usrp2_sink_base("usrp2_sink_32fc",
45                     gr_make_io_signature(1, 1, sizeof(gr_complex)),
46                     ifc, mac_addr)
47 {
48   // NOP
49 }
50
51 usrp2_sink_32fc::~usrp2_sink_32fc()
52 {
53   // NOP
54 }
55
56 int
57 usrp2_sink_32fc::work(int noutput_items,
58                       gr_vector_const_void_star &input_items,
59                       gr_vector_void_star &output_items)
60 {
61   gr_complex *in = (gr_complex *)input_items[0];
62
63   // FIXME: Current libusrp2 can't handle short packets.
64   // Returning 0 assumes there will be more samples
65   // the next round...
66   if (noutput_items < U2_MIN_SAMPLES)
67     return 0;
68
69   usrp2::tx_metadata metadata;
70   metadata.timestamp = -1;
71   metadata.send_now = 1;
72   metadata.start_of_burst = 1;
73
74   bool ok = d_u2->tx_32fc(0, // FIXME: someday, streams will have channel numbers
75                           in, noutput_items, &metadata);
76   if (!ok){
77     std::cerr << "usrp2_sink_32fc: tx_32fc failed" << std::endl;
78     return -1;  // say we're done
79   }
80
81   return noutput_items;
82 }