root / host / lib / usrp / single_usrp.cpp @ 1190bc5c
History | View | Annotate | Download (10.6 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include <uhd/usrp/single_usrp.hpp> |
| 19 |
#include <uhd/usrp/tune_helper.hpp> |
| 20 |
#include <uhd/utils/assert.hpp> |
| 21 |
#include <uhd/utils/gain_group.hpp> |
| 22 |
#include <uhd/usrp/subdev_props.hpp> |
| 23 |
#include <uhd/usrp/mboard_props.hpp> |
| 24 |
#include <uhd/usrp/device_props.hpp> |
| 25 |
#include <uhd/usrp/dboard_props.hpp> |
| 26 |
#include <uhd/usrp/dsp_props.hpp> |
| 27 |
#include <boost/foreach.hpp> |
| 28 |
#include <boost/format.hpp> |
| 29 |
#include <stdexcept> |
| 30 |
#include <iostream> |
| 31 |
|
| 32 |
using namespace uhd; |
| 33 |
using namespace uhd::usrp; |
| 34 |
|
| 35 |
static inline freq_range_t add_dsp_shift(const freq_range_t &range, wax::obj dsp){ |
| 36 |
double codec_rate = dsp[DSP_PROP_CODEC_RATE].as<double>(); |
| 37 |
return freq_range_t(range.min - codec_rate/2.0, range.max + codec_rate/2.0); |
| 38 |
} |
| 39 |
|
| 40 |
/***********************************************************************
|
| 41 |
* Simple USRP Implementation
|
| 42 |
**********************************************************************/
|
| 43 |
class single_usrp_impl : public single_usrp{ |
| 44 |
public:
|
| 45 |
single_usrp_impl(const device_addr_t &addr){
|
| 46 |
_dev = device::make(addr); |
| 47 |
} |
| 48 |
|
| 49 |
~single_usrp_impl(void){
|
| 50 |
/* NOP */
|
| 51 |
} |
| 52 |
|
| 53 |
device::sptr get_device(void){
|
| 54 |
return _dev;
|
| 55 |
} |
| 56 |
|
| 57 |
/*******************************************************************
|
| 58 |
* Mboard methods
|
| 59 |
******************************************************************/
|
| 60 |
std::string get_pp_string(void){ |
| 61 |
std::string buff = str(boost::format(
|
| 62 |
"Single USRP:\n"
|
| 63 |
" Device: %s\n"
|
| 64 |
" Mboard: %s\n"
|
| 65 |
) |
| 66 |
% (*_dev)[DEVICE_PROP_NAME].as<std::string>()
|
| 67 |
% _mboard()[MBOARD_PROP_NAME].as<std::string>()
|
| 68 |
); |
| 69 |
|
| 70 |
//----------- rx side of life ----------------------------------
|
| 71 |
buff += str(boost::format( |
| 72 |
" RX DSP: %s\n"
|
| 73 |
) |
| 74 |
% _rx_dsp()[DSP_PROP_NAME].as<std::string>()
|
| 75 |
); |
| 76 |
for (size_t chan = 0; chan < this->get_rx_subdev_spec().size(); chan++){ |
| 77 |
buff += str(boost::format( |
| 78 |
" RX Channel: %u\n"
|
| 79 |
" RX Dboard: %s\n"
|
| 80 |
" RX Subdev: %s\n"
|
| 81 |
) % chan |
| 82 |
% _rx_dboard(chan)[DBOARD_PROP_NAME].as<std::string>()
|
| 83 |
% _rx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>()
|
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
//----------- tx side of life ----------------------------------
|
| 88 |
buff += str(boost::format( |
| 89 |
" TX DSP: %s\n"
|
| 90 |
) |
| 91 |
% _tx_dsp()[DSP_PROP_NAME].as<std::string>()
|
| 92 |
); |
| 93 |
for (size_t chan = 0; chan < this->get_tx_subdev_spec().size(); chan++){ |
| 94 |
buff += str(boost::format( |
| 95 |
" TX Channel: %u\n"
|
| 96 |
" TX Dboard: %s\n"
|
| 97 |
" TX Subdev: %s\n"
|
| 98 |
) % chan |
| 99 |
% _tx_dboard(chan)[DBOARD_PROP_NAME].as<std::string>()
|
| 100 |
% _tx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>()
|
| 101 |
); |
| 102 |
} |
| 103 |
|
| 104 |
return buff;
|
| 105 |
} |
| 106 |
|
| 107 |
std::string get_mboard_name(void){ |
| 108 |
return _mboard()[MBOARD_PROP_NAME].as<std::string>(); |
| 109 |
} |
| 110 |
|
| 111 |
time_spec_t get_time_now(void){
|
| 112 |
return _mboard()[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
|
| 113 |
} |
| 114 |
|
| 115 |
void set_time_now(const time_spec_t &time_spec){ |
| 116 |
_mboard()[MBOARD_PROP_TIME_NOW] = time_spec; |
| 117 |
} |
| 118 |
|
| 119 |
void set_time_next_pps(const time_spec_t &time_spec){ |
| 120 |
_mboard()[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; |
| 121 |
} |
| 122 |
|
| 123 |
void issue_stream_cmd(const stream_cmd_t &stream_cmd){ |
| 124 |
_mboard()[MBOARD_PROP_STREAM_CMD] = stream_cmd; |
| 125 |
} |
| 126 |
|
| 127 |
void set_clock_config(const clock_config_t &clock_config){ |
| 128 |
_mboard()[MBOARD_PROP_CLOCK_CONFIG] = clock_config; |
| 129 |
} |
| 130 |
|
| 131 |
/*******************************************************************
|
| 132 |
* RX methods
|
| 133 |
******************************************************************/
|
| 134 |
void set_rx_subdev_spec(const subdev_spec_t &spec){ |
| 135 |
_mboard()[MBOARD_PROP_RX_SUBDEV_SPEC] = spec; |
| 136 |
} |
| 137 |
|
| 138 |
subdev_spec_t get_rx_subdev_spec(void){
|
| 139 |
return _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();
|
| 140 |
} |
| 141 |
|
| 142 |
std::string get_rx_subdev_name(size_t chan){
|
| 143 |
return _rx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>(); |
| 144 |
} |
| 145 |
|
| 146 |
void set_rx_rate(double rate){ |
| 147 |
_rx_dsp()[DSP_PROP_HOST_RATE] = rate; |
| 148 |
} |
| 149 |
|
| 150 |
double get_rx_rate(void){ |
| 151 |
return _rx_dsp()[DSP_PROP_HOST_RATE].as<double>(); |
| 152 |
} |
| 153 |
|
| 154 |
tune_result_t set_rx_freq(double target_freq, size_t chan){
|
| 155 |
return tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan, target_freq);
|
| 156 |
} |
| 157 |
|
| 158 |
tune_result_t set_rx_freq(double target_freq, double lo_off, size_t chan){ |
| 159 |
return tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan, target_freq, lo_off);
|
| 160 |
} |
| 161 |
|
| 162 |
double get_rx_freq(size_t chan){
|
| 163 |
return derive_freq_from_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan);
|
| 164 |
} |
| 165 |
|
| 166 |
freq_range_t get_rx_freq_range(size_t chan){
|
| 167 |
return add_dsp_shift(_rx_subdev(chan)[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _rx_dsp());
|
| 168 |
} |
| 169 |
|
| 170 |
void set_rx_gain(float gain, size_t chan){ |
| 171 |
return _rx_gain_group(chan)->set_value(gain);
|
| 172 |
} |
| 173 |
|
| 174 |
float get_rx_gain(size_t chan){
|
| 175 |
return _rx_gain_group(chan)->get_value();
|
| 176 |
} |
| 177 |
|
| 178 |
gain_range_t get_rx_gain_range(size_t chan){
|
| 179 |
return _rx_gain_group(chan)->get_range();
|
| 180 |
} |
| 181 |
|
| 182 |
void set_rx_antenna(const std::string &ant, size_t chan){ |
| 183 |
_rx_subdev(chan)[SUBDEV_PROP_ANTENNA] = ant; |
| 184 |
} |
| 185 |
|
| 186 |
std::string get_rx_antenna(size_t chan){
|
| 187 |
return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA].as<std::string>(); |
| 188 |
} |
| 189 |
|
| 190 |
std::vector<std::string> get_rx_antennas(size_t chan){
|
| 191 |
return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
|
| 192 |
} |
| 193 |
|
| 194 |
bool get_rx_lo_locked(size_t chan){
|
| 195 |
return _rx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>(); |
| 196 |
} |
| 197 |
|
| 198 |
float read_rssi(size_t chan){
|
| 199 |
return _rx_subdev(chan)[SUBDEV_PROP_RSSI].as<float>(); |
| 200 |
} |
| 201 |
|
| 202 |
dboard_iface::sptr get_rx_dboard_iface(size_t chan){
|
| 203 |
return _rx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
|
| 204 |
} |
| 205 |
|
| 206 |
/*******************************************************************
|
| 207 |
* TX methods
|
| 208 |
******************************************************************/
|
| 209 |
void set_tx_subdev_spec(const subdev_spec_t &spec){ |
| 210 |
_mboard()[MBOARD_PROP_TX_SUBDEV_SPEC] = spec; |
| 211 |
} |
| 212 |
|
| 213 |
subdev_spec_t get_tx_subdev_spec(void){
|
| 214 |
return _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();
|
| 215 |
} |
| 216 |
|
| 217 |
std::string get_tx_subdev_name(size_t chan){
|
| 218 |
return _tx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>(); |
| 219 |
} |
| 220 |
|
| 221 |
void set_tx_rate(double rate){ |
| 222 |
_tx_dsp()[DSP_PROP_HOST_RATE] = rate; |
| 223 |
} |
| 224 |
|
| 225 |
double get_tx_rate(void){ |
| 226 |
return _tx_dsp()[DSP_PROP_HOST_RATE].as<double>(); |
| 227 |
} |
| 228 |
|
| 229 |
tune_result_t set_tx_freq(double target_freq, size_t chan){
|
| 230 |
return tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan, target_freq);
|
| 231 |
} |
| 232 |
|
| 233 |
tune_result_t set_tx_freq(double target_freq, double lo_off, size_t chan){ |
| 234 |
return tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan, target_freq, lo_off);
|
| 235 |
} |
| 236 |
|
| 237 |
double get_tx_freq(size_t chan){
|
| 238 |
return derive_freq_from_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan);
|
| 239 |
} |
| 240 |
|
| 241 |
freq_range_t get_tx_freq_range(size_t chan){
|
| 242 |
return add_dsp_shift(_tx_subdev(chan)[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _tx_dsp());
|
| 243 |
} |
| 244 |
|
| 245 |
void set_tx_gain(float gain, size_t chan){ |
| 246 |
return _tx_gain_group(chan)->set_value(gain);
|
| 247 |
} |
| 248 |
|
| 249 |
float get_tx_gain(size_t chan){
|
| 250 |
return _tx_gain_group(chan)->get_value();
|
| 251 |
} |
| 252 |
|
| 253 |
gain_range_t get_tx_gain_range(size_t chan){
|
| 254 |
return _tx_gain_group(chan)->get_range();
|
| 255 |
} |
| 256 |
|
| 257 |
void set_tx_antenna(const std::string &ant, size_t chan){ |
| 258 |
_tx_subdev(chan)[SUBDEV_PROP_ANTENNA] = ant; |
| 259 |
} |
| 260 |
|
| 261 |
std::string get_tx_antenna(size_t chan){
|
| 262 |
return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA].as<std::string>(); |
| 263 |
} |
| 264 |
|
| 265 |
std::vector<std::string> get_tx_antennas(size_t chan){
|
| 266 |
return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
|
| 267 |
} |
| 268 |
|
| 269 |
bool get_tx_lo_locked(size_t chan){
|
| 270 |
return _tx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>(); |
| 271 |
} |
| 272 |
|
| 273 |
dboard_iface::sptr get_tx_dboard_iface(size_t chan){
|
| 274 |
return _tx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
|
| 275 |
} |
| 276 |
|
| 277 |
private:
|
| 278 |
device::sptr _dev; |
| 279 |
wax::obj _mboard(void){
|
| 280 |
return (*_dev)[DEVICE_PROP_MBOARD];
|
| 281 |
} |
| 282 |
wax::obj _rx_dsp(void){
|
| 283 |
return _mboard()[MBOARD_PROP_RX_DSP];
|
| 284 |
} |
| 285 |
wax::obj _tx_dsp(void){
|
| 286 |
return _mboard()[MBOARD_PROP_TX_DSP];
|
| 287 |
} |
| 288 |
wax::obj _rx_dboard(size_t chan){
|
| 289 |
std::string db_name = this->get_rx_subdev_spec().at(chan).db_name; |
| 290 |
return _mboard()[named_prop_t(MBOARD_PROP_RX_DBOARD, db_name)];
|
| 291 |
} |
| 292 |
wax::obj _tx_dboard(size_t chan){
|
| 293 |
std::string db_name = this->get_tx_subdev_spec().at(chan).db_name; |
| 294 |
return _mboard()[named_prop_t(MBOARD_PROP_TX_DBOARD, db_name)];
|
| 295 |
} |
| 296 |
wax::obj _rx_subdev(size_t chan){
|
| 297 |
std::string sd_name = this->get_rx_subdev_spec().at(chan).sd_name; |
| 298 |
return _rx_dboard(chan)[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
|
| 299 |
} |
| 300 |
wax::obj _tx_subdev(size_t chan){
|
| 301 |
std::string sd_name = this->get_tx_subdev_spec().at(chan).sd_name; |
| 302 |
return _tx_dboard(chan)[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
|
| 303 |
} |
| 304 |
gain_group::sptr _rx_gain_group(size_t chan){
|
| 305 |
std::string sd_name = this->get_rx_subdev_spec().at(chan).sd_name; |
| 306 |
return _rx_dboard(chan)[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
|
| 307 |
} |
| 308 |
gain_group::sptr _tx_gain_group(size_t chan){
|
| 309 |
std::string sd_name = this->get_tx_subdev_spec().at(chan).sd_name; |
| 310 |
return _tx_dboard(chan)[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
|
| 311 |
} |
| 312 |
}; |
| 313 |
|
| 314 |
/***********************************************************************
|
| 315 |
* The Make Function
|
| 316 |
**********************************************************************/
|
| 317 |
single_usrp::sptr single_usrp::make(const device_addr_t &dev_addr){
|
| 318 |
return sptr(new single_usrp_impl(dev_addr)); |
| 319 |
} |