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_USRP2_H
20 #define INCLUDED_USRP2_H
22 #include <boost/shared_ptr.hpp>
23 #include <boost/utility.hpp>
27 #include <usrp2/rx_sample_handler.h>
28 #include <usrp2/tune_result.h>
29 #include <usrp2/rx_sample_handler.h>
35 * Structure to hold properties of USRP2 hardware devices.
42 uint8_t fpga_md5sum[16];
43 uint8_t sw_md5sum[16];
46 typedef std::vector<props> props_vector_t;
49 * \brief Search the ethernet for all USRP2s or for a specific USRP2.
51 * \param ifc is the name of the OS ethernet interface (e.g., "eth0")
52 * \param mac_addr is the MAC address of the desired USRP2, or "" to search for all.
53 * mac_addr must be either a zero length string, "", or must be of the form
54 * "01:02:03:04:05:06" or "05:06".
56 * \returns a vector of properties, 1 entry for each matching USRP2 found.
58 props_vector_t find(const std::string &ifc, const std::string &mac_addr="");
62 class usrp2 : boost::noncopyable
65 static const unsigned int MAX_CHAN = 30;
68 * Shared pointer to this class
70 typedef boost::shared_ptr<usrp2> sptr;
73 * Static function to return an instance of usrp2 as a shared pointer
75 * \param ifc Network interface name, e.g., "eth0"
76 * \param addr Network mac address, e.g., "01:23:45:67:89:ab", "89:ab" or "".
77 * If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH
78 * "" will autoselect a USRP2 if there is only a single one on the local ethernet.
80 static sptr make(const std::string &ifc, const std::string &addr="");
88 * Returns the MAC address associated with this USRP
90 std::string mac_addr();
93 * Burn new mac address into EEPROM on USRP2
95 * \param new_addr Network mac address, e.g., "01:23:45:67:89:ab" or "89:ab".
96 * If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH
98 bool burn_mac_addr(const std::string &new_addr);
101 * ----------------------------------------------------------------
102 * Rx configuration and control
103 * ----------------------------------------------------------------
109 bool set_rx_gain(double gain);
112 * Set receiver center frequency
114 bool set_rx_center_freq(double frequency, tune_result *result);
117 * Set receiver sample rate decimation
119 bool set_rx_decim(int decimation_factor);
122 * Set receiver IQ magnitude scaling
124 bool set_rx_scale_iq(int scale_i, int scale_q);
127 * Set received sample format
129 * domain: complex or real
130 * type: floating, fixed point, or raw
131 * depth: bits per sample
133 * Sets format over the wire for samples from USRP2.
135 // bool set_rx_format(...);
138 * Start streaming receive mode. USRP2 will send a continuous stream of
139 * DSP pipeline samples to host. Call rx_samples(...) to access.
141 * \param channel Stream channel number (0-30)
142 * \param items_per_frame Number of 32-bit items per frame.
144 bool start_rx_streaming(unsigned int channel=0, unsigned int items_per_frame=0);
147 * Stop streaming receive mode.
149 bool stop_rx_streaming(unsigned int channel=0);
152 * \brief Receive data from the specified channel
153 * This method is used to receive all data: streaming or discrete.
155 bool rx_samples(unsigned int channel, rx_sample_handler *handler);
158 * Returns number of times receive overruns have occurred
160 unsigned int rx_overruns();
163 * Returns total number of missing frames from overruns.
165 unsigned int rx_missing();
168 * ----------------------------------------------------------------
169 * Tx configuration and control
170 * ----------------------------------------------------------------
174 * Set transmitter gain
176 bool set_tx_gain(double gain);
179 * Set transmitter center frequency
181 bool set_tx_center_freq(double frequency, tune_result *result);
184 * Set transmitter sample rate interpolation
186 bool set_tx_interp(int interpolation_factor);
189 * Set transmit IQ magnitude scaling
191 bool set_tx_scale_iq(int scale_i, int scale_q);
194 * Set transmit sample format
196 * domain: complex or real
197 * type: floating, fixed point, or raw
198 * depth: bits per sample
200 * Sets format over the wire for samples to USRP2.
202 // bool set_tx_format(...);
205 * \brief transmit complex<float> samples to USRP2
207 * \param channel specifies the channel to send them to
208 * \param samples are the samples to transmit
209 * \param nsamples is the number of samples to transmit
210 * \param metadata provides the timestamp and flags
212 bool tx_complex_float(unsigned int channel,
213 const std::complex<float> *samples,
215 const tx_metadata *metadata);
218 * \brief transmit complex<int16_t> samples to USRP2
220 * \param channel specifies the channel to send them to
221 * \param samples are the samples to transmit
222 * \param nsamples is the number of samples to transmit
223 * \param metadata provides the timestamp and flags
225 bool tx_complex_int16(unsigned int channel,
226 const std::complex<int16_t> *samples,
228 const tx_metadata *metadata);
231 * \brief transmit raw uint32_t data items to USRP2
233 * The caller is responsible for ensuring that the items are
234 * formatted appropriately for the USRP2 and its configuration.
235 * This method is used primarily by the system itself. Users
236 * should call tx_complex_float or tx_complex_16 instead.
238 * \param channel specifies the channel to send them to
239 * \param items are the data items to transmit
240 * \param nitems is the number of items to transmit
241 * \param metadata provides the timestamp and flags
243 bool tx_raw(unsigned int channel,
244 const uint32_t *items,
246 const tx_metadata *metadata);
248 // ----------------------------------------------------------------
251 * \brief MIMO configuration
253 * \param flags from usrp2_mimo_config.h
262 * and optionally this:
264 * MC_PROVIDE_CLK_TO_MIMO
267 bool config_mimo(int flags);
269 class impl; // implementation details
272 // Static function to retrieve or create usrp2 instance
273 static sptr find_existing_or_make_new(const std::string &ifc, props *p);
275 // Only class members can instantiate this class
276 usrp2(const std::string &ifc, props *p);
278 // All private state is held in opaque pointer
279 std::auto_ptr<impl> d_impl;
284 std::ostream& operator<<(std::ostream &os, const usrp2::props &x);
287 #endif /* INCLUDED_USRP2_H */