root / host / lib / usrp / simple_usrp.cpp @ 48ad3b73
History | View | Annotate | Download (9.5 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/simple_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 simple_usrp_impl : public simple_usrp{ |
| 44 |
public:
|
| 45 |
simple_usrp_impl(const device_addr_t &addr){
|
| 46 |
_dev = device::make(addr); |
| 47 |
} |
| 48 |
|
| 49 |
~simple_usrp_impl(void){
|
| 50 |
/* NOP */
|
| 51 |
} |
| 52 |
|
| 53 |
device::sptr get_device(void){
|
| 54 |
return _dev;
|
| 55 |
} |
| 56 |
|
| 57 |
std::string get_pp_string(void){ |
| 58 |
return str(boost::format(
|
| 59 |
"Simple USRP:\n"
|
| 60 |
" Device: %s\n"
|
| 61 |
" Mboard: %s\n"
|
| 62 |
" RX DSP: %s\n"
|
| 63 |
" RX Dboard: %s\n"
|
| 64 |
" RX Subdev: %s\n"
|
| 65 |
" TX DSP: %s\n"
|
| 66 |
" TX Dboard: %s\n"
|
| 67 |
" TX Subdev: %s\n"
|
| 68 |
) |
| 69 |
% (*_dev)[DEVICE_PROP_NAME].as<std::string>()
|
| 70 |
% _mboard()[MBOARD_PROP_NAME].as<std::string>()
|
| 71 |
% _rx_dsp()[DSP_PROP_NAME].as<std::string>()
|
| 72 |
% _rx_dboard()[DBOARD_PROP_NAME].as<std::string>()
|
| 73 |
% _rx_subdev()[SUBDEV_PROP_NAME].as<std::string>()
|
| 74 |
% _tx_dsp()[DSP_PROP_NAME].as<std::string>()
|
| 75 |
% _tx_dboard()[DBOARD_PROP_NAME].as<std::string>()
|
| 76 |
% _tx_subdev()[SUBDEV_PROP_NAME].as<std::string>()
|
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
/*******************************************************************
|
| 81 |
* Misc
|
| 82 |
******************************************************************/
|
| 83 |
time_spec_t get_time_now(void){
|
| 84 |
return _mboard()[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
|
| 85 |
} |
| 86 |
|
| 87 |
void set_time_now(const time_spec_t &time_spec){ |
| 88 |
_mboard()[MBOARD_PROP_TIME_NOW] = time_spec; |
| 89 |
} |
| 90 |
|
| 91 |
void set_time_next_pps(const time_spec_t &time_spec){ |
| 92 |
_mboard()[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; |
| 93 |
} |
| 94 |
|
| 95 |
void issue_stream_cmd(const stream_cmd_t &stream_cmd){ |
| 96 |
_mboard()[MBOARD_PROP_STREAM_CMD] = stream_cmd; |
| 97 |
} |
| 98 |
|
| 99 |
void set_clock_config(const clock_config_t &clock_config){ |
| 100 |
_mboard()[MBOARD_PROP_CLOCK_CONFIG] = clock_config; |
| 101 |
} |
| 102 |
|
| 103 |
/*******************************************************************
|
| 104 |
* RX methods
|
| 105 |
******************************************************************/
|
| 106 |
void set_rx_subdev_spec(const subdev_spec_t &spec){ |
| 107 |
_mboard()[MBOARD_PROP_RX_SUBDEV_SPEC] = spec; |
| 108 |
std::cout << "RX " << _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().to_pp_string() << std::endl;
|
| 109 |
} |
| 110 |
|
| 111 |
subdev_spec_t get_rx_subdev_spec(void){
|
| 112 |
return _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();
|
| 113 |
} |
| 114 |
|
| 115 |
void set_rx_rate(double rate){ |
| 116 |
_rx_dsp()[DSP_PROP_HOST_RATE] = rate; |
| 117 |
} |
| 118 |
|
| 119 |
double get_rx_rate(void){ |
| 120 |
return _rx_dsp()[DSP_PROP_HOST_RATE].as<double>(); |
| 121 |
} |
| 122 |
|
| 123 |
tune_result_t set_rx_freq(double target_freq){
|
| 124 |
return tune_rx_subdev_and_dsp(_rx_subdev(), _rx_dsp(), target_freq);
|
| 125 |
} |
| 126 |
|
| 127 |
tune_result_t set_rx_freq(double target_freq, double lo_off){ |
| 128 |
return tune_rx_subdev_and_dsp(_rx_subdev(), _rx_dsp(), target_freq, lo_off);
|
| 129 |
} |
| 130 |
|
| 131 |
double get_rx_freq(void){ |
| 132 |
return derive_freq_from_rx_subdev_and_dsp(_rx_subdev(), _rx_dsp());
|
| 133 |
} |
| 134 |
|
| 135 |
freq_range_t get_rx_freq_range(void){
|
| 136 |
return add_dsp_shift(_rx_subdev()[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _rx_dsp());
|
| 137 |
} |
| 138 |
|
| 139 |
void set_rx_gain(float gain){ |
| 140 |
return _rx_gain_group()->set_value(gain);
|
| 141 |
} |
| 142 |
|
| 143 |
float get_rx_gain(void){ |
| 144 |
return _rx_gain_group()->get_value();
|
| 145 |
} |
| 146 |
|
| 147 |
gain_range_t get_rx_gain_range(void){
|
| 148 |
return _rx_gain_group()->get_range();
|
| 149 |
} |
| 150 |
|
| 151 |
void set_rx_antenna(const std::string &ant){ |
| 152 |
_rx_subdev()[SUBDEV_PROP_ANTENNA] = ant; |
| 153 |
} |
| 154 |
|
| 155 |
std::string get_rx_antenna(void){ |
| 156 |
return _rx_subdev()[SUBDEV_PROP_ANTENNA].as<std::string>(); |
| 157 |
} |
| 158 |
|
| 159 |
std::vector<std::string> get_rx_antennas(void){ |
| 160 |
return _rx_subdev()[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
|
| 161 |
} |
| 162 |
|
| 163 |
bool get_rx_lo_locked(void){ |
| 164 |
return _rx_subdev()[SUBDEV_PROP_LO_LOCKED].as<bool>(); |
| 165 |
} |
| 166 |
|
| 167 |
float read_rssi(void){ |
| 168 |
return _rx_subdev()[SUBDEV_PROP_RSSI].as<float>(); |
| 169 |
} |
| 170 |
|
| 171 |
dboard_iface::sptr get_rx_dboard_iface(void){
|
| 172 |
return _rx_dboard()[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
|
| 173 |
} |
| 174 |
|
| 175 |
/*******************************************************************
|
| 176 |
* TX methods
|
| 177 |
******************************************************************/
|
| 178 |
void set_tx_subdev_spec(const subdev_spec_t &spec){ |
| 179 |
_mboard()[MBOARD_PROP_TX_SUBDEV_SPEC] = spec; |
| 180 |
std::cout << "TX " << _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().to_pp_string() << std::endl;
|
| 181 |
} |
| 182 |
|
| 183 |
subdev_spec_t get_tx_subdev_spec(void){
|
| 184 |
return _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();
|
| 185 |
} |
| 186 |
|
| 187 |
void set_tx_rate(double rate){ |
| 188 |
_tx_dsp()[DSP_PROP_HOST_RATE] = rate; |
| 189 |
} |
| 190 |
|
| 191 |
double get_tx_rate(void){ |
| 192 |
return _tx_dsp()[DSP_PROP_HOST_RATE].as<double>(); |
| 193 |
} |
| 194 |
|
| 195 |
tune_result_t set_tx_freq(double target_freq){
|
| 196 |
return tune_tx_subdev_and_dsp(_tx_subdev(), _tx_dsp(), target_freq);
|
| 197 |
} |
| 198 |
|
| 199 |
tune_result_t set_tx_freq(double target_freq, double lo_off){ |
| 200 |
return tune_tx_subdev_and_dsp(_tx_subdev(), _tx_dsp(), target_freq, lo_off);
|
| 201 |
} |
| 202 |
|
| 203 |
double get_tx_freq(void){ |
| 204 |
return derive_freq_from_tx_subdev_and_dsp(_tx_subdev(), _tx_dsp());
|
| 205 |
} |
| 206 |
|
| 207 |
freq_range_t get_tx_freq_range(void){
|
| 208 |
return add_dsp_shift(_tx_subdev()[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _tx_dsp());
|
| 209 |
} |
| 210 |
|
| 211 |
void set_tx_gain(float gain){ |
| 212 |
return _tx_gain_group()->set_value(gain);
|
| 213 |
} |
| 214 |
|
| 215 |
float get_tx_gain(void){ |
| 216 |
return _tx_gain_group()->get_value();
|
| 217 |
} |
| 218 |
|
| 219 |
gain_range_t get_tx_gain_range(void){
|
| 220 |
return _tx_gain_group()->get_range();
|
| 221 |
} |
| 222 |
|
| 223 |
void set_tx_antenna(const std::string &ant){ |
| 224 |
_tx_subdev()[SUBDEV_PROP_ANTENNA] = ant; |
| 225 |
} |
| 226 |
|
| 227 |
std::string get_tx_antenna(void){ |
| 228 |
return _tx_subdev()[SUBDEV_PROP_ANTENNA].as<std::string>(); |
| 229 |
} |
| 230 |
|
| 231 |
std::vector<std::string> get_tx_antennas(void){ |
| 232 |
return _tx_subdev()[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
|
| 233 |
} |
| 234 |
|
| 235 |
bool get_tx_lo_locked(void){ |
| 236 |
return _tx_subdev()[SUBDEV_PROP_LO_LOCKED].as<bool>(); |
| 237 |
} |
| 238 |
|
| 239 |
dboard_iface::sptr get_tx_dboard_iface(void){
|
| 240 |
return _tx_dboard()[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
|
| 241 |
} |
| 242 |
|
| 243 |
private:
|
| 244 |
device::sptr _dev; |
| 245 |
wax::obj _mboard(void){
|
| 246 |
return (*_dev)[DEVICE_PROP_MBOARD];
|
| 247 |
} |
| 248 |
wax::obj _rx_dsp(void){
|
| 249 |
return _mboard()[MBOARD_PROP_RX_DSP];
|
| 250 |
} |
| 251 |
wax::obj _tx_dsp(void){
|
| 252 |
return _mboard()[MBOARD_PROP_TX_DSP];
|
| 253 |
} |
| 254 |
wax::obj _rx_dboard(void){
|
| 255 |
std::string db_name = _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().front().db_name;
|
| 256 |
return _mboard()[named_prop_t(MBOARD_PROP_RX_DBOARD, db_name)];
|
| 257 |
} |
| 258 |
wax::obj _tx_dboard(void){
|
| 259 |
std::string db_name = _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().front().db_name;
|
| 260 |
return _mboard()[named_prop_t(MBOARD_PROP_TX_DBOARD, db_name)];
|
| 261 |
} |
| 262 |
wax::obj _rx_subdev(void){
|
| 263 |
std::string sd_name = _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
|
| 264 |
return _rx_dboard()[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
|
| 265 |
} |
| 266 |
wax::obj _tx_subdev(void){
|
| 267 |
std::string sd_name = _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
|
| 268 |
return _tx_dboard()[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
|
| 269 |
} |
| 270 |
gain_group::sptr _rx_gain_group(void){
|
| 271 |
std::string sd_name = _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
|
| 272 |
return _rx_dboard()[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
|
| 273 |
} |
| 274 |
gain_group::sptr _tx_gain_group(void){
|
| 275 |
std::string sd_name = _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
|
| 276 |
return _tx_dboard()[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
|
| 277 |
} |
| 278 |
}; |
| 279 |
|
| 280 |
/***********************************************************************
|
| 281 |
* The Make Function
|
| 282 |
**********************************************************************/
|
| 283 |
simple_usrp::sptr simple_usrp::make(const device_addr_t &dev_addr){
|
| 284 |
return sptr(new simple_usrp_impl(dev_addr)); |
| 285 |
} |