Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / simple_usrp.cpp @ 695dd535

History | View | Annotate | Download (7.1 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/usrp/subdev_props.hpp>
22
#include <uhd/usrp/mboard_props.hpp>
23
#include <uhd/usrp/device_props.hpp>
24
#include <uhd/usrp/dboard_props.hpp>
25
#include <uhd/usrp/dsp_props.hpp>
26
#include <boost/foreach.hpp>
27
#include <boost/format.hpp>
28
#include <stdexcept>
29

    
30
using namespace uhd;
31
using namespace uhd::usrp;
32

    
33
/***********************************************************************
34
 * Simple Device Implementation
35
 **********************************************************************/
36
class simple_usrp_impl : public simple_usrp{
37
public:
38
    simple_usrp_impl(const device_addr_t &addr){
39
        _dev = device::make(addr);
40
        _mboard = (*_dev)[DEVICE_PROP_MBOARD];
41
        _rx_dsp = _mboard[MBOARD_PROP_RX_DSP];
42
        _tx_dsp = _mboard[MBOARD_PROP_TX_DSP];
43

    
44
        //extract rx subdevice
45
        _rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD];
46
        std::string rx_subdev_in_use = _rx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
47
        _rx_subdev = _rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)];
48

    
49
        //extract tx subdevice
50
        _tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD];
51
        std::string tx_subdev_in_use = _tx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
52
        _tx_subdev = _tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)];
53
    }
54

    
55
    ~simple_usrp_impl(void){
56
        /* NOP */
57
    }
58

    
59
    device::sptr get_device(void){
60
        return _dev;
61
    }
62

    
63
    std::string get_name(void){
64
        return str(boost::format(
65
            "Simple USRP:\n"
66
            "  Device: %s\n"
67
            "  Mboard: %s\n"
68
            "  RX DSP: %s\n"
69
            "  RX Dboard: %s\n"
70
            "  RX Subdev: %s\n"
71
            "  TX DSP: %s\n"
72
            "  TX Dboard: %s\n"
73
            "  TX Subdev: %s\n"
74
        )
75
            % (*_dev)[DEVICE_PROP_NAME].as<std::string>()
76
            % _mboard[MBOARD_PROP_NAME].as<std::string>()
77
            % _rx_dsp[DSP_PROP_NAME].as<std::string>()
78
            % _rx_dboard[DBOARD_PROP_NAME].as<std::string>()
79
            % _rx_subdev[SUBDEV_PROP_NAME].as<std::string>()
80
            % _tx_dsp[DSP_PROP_NAME].as<std::string>()
81
            % _tx_dboard[DBOARD_PROP_NAME].as<std::string>()
82
            % _tx_subdev[SUBDEV_PROP_NAME].as<std::string>()
83
        );
84
    }
85

    
86
    /*******************************************************************
87
     * Misc
88
     ******************************************************************/
89
    void set_time_now(const time_spec_t &time_spec){
90
        _mboard[MBOARD_PROP_TIME_NOW] = time_spec;
91
    }
92

    
93
    void set_time_next_pps(const time_spec_t &time_spec){
94
        _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
95
    }
96

    
97
    void issue_stream_cmd(const stream_cmd_t &stream_cmd){
98
        _mboard[MBOARD_PROP_STREAM_CMD] = stream_cmd;
99
    }
100

    
101
    void set_clock_config(const clock_config_t &clock_config){
102
        _mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config;
103
    }
104

    
105
    float read_rssi(void){
106
        return _rx_subdev[SUBDEV_PROP_RSSI].as<float>();
107
    }
108

    
109
    /*******************************************************************
110
     * RX methods
111
     ******************************************************************/
112
    void set_rx_rate(double rate){
113
        _rx_dsp[DSP_PROP_HOST_RATE] = rate;
114
    }
115

    
116
    double get_rx_rate(void){
117
        return _rx_dsp[DSP_PROP_HOST_RATE].as<double>();
118
    }
119

    
120
    tune_result_t set_rx_freq(double target_freq){
121
        return tune_rx_subdev_and_ddc(_rx_subdev, _rx_dsp, target_freq);
122
    }
123

    
124
    tune_result_t set_rx_freq(double target_freq, double lo_off){
125
        return tune_rx_subdev_and_ddc(_rx_subdev, _rx_dsp, target_freq, lo_off);
126
    }
127

    
128
    freq_range_t get_rx_freq_range(void){
129
        return _rx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
130
    }
131

    
132
    void set_rx_gain(float gain){
133
        _rx_subdev[SUBDEV_PROP_GAIN] = gain;
134
    }
135

    
136
    float get_rx_gain(void){
137
        return _rx_subdev[SUBDEV_PROP_GAIN].as<float>();
138
    }
139

    
140
    gain_range_t get_rx_gain_range(void){
141
        return _rx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
142
    }
143

    
144
    void set_rx_antenna(const std::string &ant){
145
        _rx_subdev[SUBDEV_PROP_ANTENNA] = ant;
146
    }
147

    
148
    std::string get_rx_antenna(void){
149
        return _rx_subdev[SUBDEV_PROP_ANTENNA].as<std::string>();
150
    }
151

    
152
    std::vector<std::string> get_rx_antennas(void){
153
        return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
154
    }
155

    
156
    bool get_rx_lo_locked(void){
157
        return _rx_subdev[SUBDEV_PROP_LO_LOCKED].as<bool>();
158
    }
159

    
160
    /*******************************************************************
161
     * TX methods
162
     ******************************************************************/
163
    void set_tx_rate(double rate){
164
        _tx_dsp[DSP_PROP_HOST_RATE] = rate;
165
    }
166

    
167
    double get_tx_rate(void){
168
        return _tx_dsp[DSP_PROP_HOST_RATE].as<double>();
169
    }
170

    
171
    tune_result_t set_tx_freq(double target_freq){
172
        return tune_tx_subdev_and_duc(_tx_subdev, _tx_dsp, target_freq);
173
    }
174

    
175
    tune_result_t set_tx_freq(double target_freq, double lo_off){
176
        return tune_tx_subdev_and_duc(_tx_subdev, _tx_dsp, target_freq, lo_off);
177
    }
178

    
179
    freq_range_t get_tx_freq_range(void){
180
        return _tx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
181
    }
182

    
183
    void set_tx_gain(float gain){
184
        _tx_subdev[SUBDEV_PROP_GAIN] = gain;
185
    }
186

    
187
    float get_tx_gain(void){
188
        return _tx_subdev[SUBDEV_PROP_GAIN].as<float>();
189
    }
190

    
191
    gain_range_t get_tx_gain_range(void){
192
        return _tx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
193
    }
194

    
195
    void set_tx_antenna(const std::string &ant){
196
        _tx_subdev[SUBDEV_PROP_ANTENNA] = ant;
197
    }
198

    
199
    std::string get_tx_antenna(void){
200
        return _tx_subdev[SUBDEV_PROP_ANTENNA].as<std::string>();
201
    }
202

    
203
    std::vector<std::string> get_tx_antennas(void){
204
        return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
205
    }
206

    
207
    bool get_tx_lo_locked(void){
208
        return _tx_subdev[SUBDEV_PROP_LO_LOCKED].as<bool>();
209
    }
210

    
211
private:
212
    device::sptr _dev;
213
    wax::obj _mboard;
214
    wax::obj _rx_dsp;
215
    wax::obj _tx_dsp;
216
    wax::obj _rx_dboard;
217
    wax::obj _tx_dboard;
218
    wax::obj _rx_subdev;
219
    wax::obj _tx_subdev;
220
};
221

    
222
/***********************************************************************
223
 * The Make Function
224
 **********************************************************************/
225
simple_usrp::sptr simple_usrp::make(const device_addr_t &dev_addr){
226
    return sptr(new simple_usrp_impl(dev_addr));
227
}