3 * Copyright 2008 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef INCLUDED_RX_NOP_HANDLER_H
20 #define INCLUDED_RX_NOP_HANDLER_H
22 #include <usrp2/rx_sample_handler.h>
23 #include <boost/shared_ptr.hpp>
28 * Base class for receive handlers that must copy into potentially limited
29 * range destination buffers.
31 * Maintains counters for number of items copied, times invoked, and test
32 * for whether maximum has been reached.
34 * Derived classes should override the () operator, but call this
35 * parent class method at some point at the start of their own operations.
40 class rx_nop_handler : public rx_sample_handler
42 uint64_t d_max_samples;
43 uint64_t d_max_quantum;
52 // Shared pointer to an instance of this class
53 typedef boost::shared_ptr<rx_nop_handler> sptr;
58 * \param max_samples Maximum number of samples to copy. Use zero for no maximum.
59 * \param max_quantum Maximum number of samples required to accept in one call.
60 * Use 0 to indicate no maximum.
62 rx_nop_handler(uint64_t max_samples, uint64_t max_quantum=0)
63 : d_max_samples(max_samples), d_max_quantum(max_quantum),
64 d_nsamples(0), d_nframes(0), d_err(false) {}
67 * Destructor. Derived classes must implement their own, non-inline destructor.
69 virtual ~rx_nop_handler();
72 * \brief Returns number of frames this copier was called with
74 uint64_t nframes() const { return d_nframes; }
77 * \brief Returns actual number of samples copied
79 uint64_t nsamples() const { return d_nsamples; }
82 * \brief Returns maximum number of samples that will be copied
84 uint64_t max_samples() const { return d_max_samples; }
87 * Returns true if an error has occurred. Derived classes must set d_err to true
88 * when an error occurs in the () operator
90 bool has_errored_p() const { return d_err; }
93 * \brief Returns true if this instance has reached the maximum number of samples
95 bool has_finished_p() const
96 { return d_max_samples == 0 ? false : d_nsamples >= d_max_samples-d_max_quantum; }
100 * Function operator invoked by USRP2 RX API. Derived classes must override this method
101 * but then invoke it at the start of their processing. This operator will always be
102 * called at least once.
104 * \param items points to the first 32-bit word of uninterpreted sample data in the frame.
105 * \param nitems is the number of entries in the frame in units of uint32_t's.
106 * \param metadata is the additional per frame data provided by the USRP2 FPGA.
108 * \p items points to the raw sample data received off of the ethernet. The data is
109 * packed into big-endian 32-bit unsigned ints for transport, but the actual format
110 * of the data is dependent on the current configuration of the USRP2. The most common
111 * format is 16-bit I & Q, with I in the top of the 32-bit word.
113 * \returns true if the object wants to be called again with new data;
114 * false if no additional data is wanted.
116 virtual bool operator()(const uint32_t *items, size_t nitems, const rx_metadata *metadata)
118 // printf("W0: %08x TS: %08x\n", metadata->word0, metadata->timestamp);
119 // printf("I0: %08x\n", items[0]);
121 d_nsamples += nitems;
124 return !has_finished_p();
128 } /* namespace usrp2 */
130 #endif /* INCLUDED_RX_NOP_HANDLER */