3 * Copyright 2008,2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
27 #include <vrt_source_32fc.h>
28 #include <vrt/expanded_header.h>
29 #include <vrt/copiers.h>
30 #include <gr_io_signature.h>
31 #include <missing_pkt_checker.h>
34 #define VERBOSE 1 // define to 0 or 1
37 class rx_32fc_handler : public vrt::rx_packet_handler
40 std::complex<float> *d_out;
41 int *d_oo; // output index
42 std::vector< std::complex<float> > &d_remainder;
43 missing_pkt_checker &d_checker;
48 rx_32fc_handler(int noutput_items, std::complex<float> *out,
49 int *oo, std::vector< std::complex<float> > &remainder,
50 missing_pkt_checker &checker)
51 : d_noutput_items(noutput_items), d_out(out),
52 d_oo(oo), d_remainder(remainder), d_checker(checker) {}
56 bool operator()(const uint32_t *payload,
58 const vrt::expanded_header *hdr);
61 rx_32fc_handler::~rx_32fc_handler()
66 rx_32fc_handler::operator()(const uint32_t *payload,
68 const vrt::expanded_header *hdr)
70 int nmissing = d_checker.check(hdr);
71 if (VERBOSE && nmissing != 0){
72 std::cerr << "S" << nmissing;
75 // copy as many as will fit into the output buffer.
77 size_t n = std::min(n32_bit_words, (size_t)(d_noutput_items - *d_oo));
78 vrt::copy_net_16sc_to_host_32fc(n, payload, &d_out[*d_oo]);
81 // if there are any left over, copy them into remainder and tell
82 // our caller we're had enough for now.
84 size_t r = n32_bit_words - n;
86 assert(d_remainder.size() == 0);
87 d_remainder.resize(r);
88 vrt::copy_net_16sc_to_host_32fc(r, &payload[n], &d_remainder[0]);
89 return false; // Stop calling us.
92 return true; // Keep calling us, we've got more room
96 // ------------------------------------------------------------------------
98 vrt_source_32fc::vrt_source_32fc(const char *name)
100 : vrt_source_base(name,
101 gr_make_io_signature(1, 1, sizeof(gr_complex)))
105 vrt_source_32fc::~vrt_source_32fc()
108 std::cerr << "\nvrt_source_32fc: npackets = " << d_checker.npackets()
109 << " nwrong_pkt_cnt = " << d_checker.nwrong_pkt_cnt()
110 << " nmissing_pkt_est = " << d_checker.nmissing_pkt_est()
116 vrt_source_32fc::work(int noutput_items,
117 gr_vector_const_void_star &input_items,
118 gr_vector_void_star &output_items)
120 gr_complex *out = (gr_complex *)output_items[0];
123 // Handle any samples left over from the last call.
124 int t = std::min(noutput_items, (int)d_remainder.size());
126 for (int i = 0; i < t; i++)
127 out[i] = d_remainder[i];
128 d_remainder.erase(d_remainder.begin(), d_remainder.begin()+t);
131 if (noutput_items - oo == 0)
134 // While we've got room, and there are packets, handle them
135 rx_32fc_handler h(noutput_items, out, &oo, d_remainder, d_checker);
136 bool ok = vrt_rx()->rx_packets(&h);
139 std::cerr << "vrt_source_32fc: vrt::rx_packets() failed" << std::endl;
140 return -1; // say we're done