SoDaRadio-5.0.3-master:8901fb5
IntN_FreqTable.cxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015, Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include <iostream>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <boost/format.hpp>
33 #include <string>
34 #include <list>
35 #include <uhd/usrp/multi_usrp.hpp>
36 #include <vector>
37 #include <string>
38 #include <boost/foreach.hpp>
39 #include <boost/format.hpp>
40 
41 #include <uhd/utils/safe_main.hpp>
42 #include <uhd/version.hpp>
43 #include <uhd/device.hpp>
44 #include <uhd/types/ranges.hpp>
45 #include <uhd/property_tree.hpp>
46 #include <boost/algorithm/string.hpp> //for split
47 #include <uhd/usrp/dboard_id.hpp>
48 #include <uhd/usrp/mboard_eeprom.hpp>
49 #include <uhd/usrp/dboard_eeprom.hpp>
50 
51 
52 std::string getMbName(uhd::usrp::multi_usrp::sptr usrp)
53 {
54  uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
55  std::string mbname = tree->list("/mboards").at(0);
56  return tree->access<std::string>("/mboards/" + mbname + "/name").get();
57 }
58 
59 void dumpProps(uhd::usrp::multi_usrp::sptr usrp)
60 {
61  uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
62  std::string mbname = tree->list("/mboards").at(0);
63 
64  uhd::usrp::mboard_eeprom_t eeprom = tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/" + mbname + "/eeprom").get();
65  BOOST_FOREACH(const std::string & key, eeprom.keys()) {
66  if( eeprom[key].empty() ) {
67  std::cerr << boost::format("Empty key [%s]\n") % key;
68  }
69  else {
70  std::cerr << boost::format(" eeprom[%s] = [%s]\n") % key % eeprom[key];
71  }
72  }
73 
74  std::cerr << boost::format("went the direct route = [%s]\n")
75  % tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/" + mbname + "/eeprom").get()["ip-addr"];
76 }
77 
78 int main(int argc, char ** argv)
79 {
80  if(argc < 2) {
81  std::cerr << "Usage: IntN_FreqTable dev-arg-string" << std::endl;
82  exit(-1);
83  }
84 
85  std::string devaddr(argv[1]);
86  uhd::device_addr_t rad(devaddr);
87 
88  uhd::usrp::multi_usrp::sptr usrp;
89  // make the device.
90  usrp = uhd::usrp::multi_usrp::make(rad);
91 
92  // now do the RX front end LO experiment.
93  uhd::freq_range_t rx_rf_freq_range, tx_rf_freq_range;
94  rx_rf_freq_range = usrp->get_rx_freq_range();
95  tx_rf_freq_range = usrp->get_tx_freq_range();
96 
97  uhd::tune_result_t tunres_int;
98 
99  // Now sweep from min to max freq, and find the steps along the way.
100  double ff_incr = 1.0e6; // start with a small step...
101  double r_st, r_en, target;
102 
103 
104  // now look through the range
105  for(int i = 0; i < 2; i++) {
106  r_st = (i == 0) ? rx_rf_freq_range.start() : tx_rf_freq_range.start();;
107  r_en = (i == 0) ? rx_rf_freq_range.stop() : tx_rf_freq_range.stop();;
108 
109  // first find the first setting.
110  uhd::tune_request_t treq(r_st);
111  treq.args = uhd::device_addr_t("mode_n=integer");
112  tunres_int = (i == 0) ? usrp->set_rx_freq(treq) : usrp->set_tx_freq(treq);
113  target = tunres_int.actual_rf_freq;
114 
115  for(double ff = target + ff_incr;
116  ff < r_en;
117  ff += ff_incr) {
118  uhd::tune_request_t treq(ff);
119  treq.rf_freq = ff;
120  treq.rf_freq_policy = uhd::tune_request_t::POLICY_MANUAL;
121  treq.args = uhd::device_addr_t("mode_n=integer");
122  tunres_int = (i == 0) ? usrp->set_rx_freq(treq) : usrp->set_tx_freq(treq);
123 
124  std::string mode = (i == 0) ? "RX" : "TX";
125 
126  std::cerr << boost::format("%s Range Check RF_actual %lf DDC = %lf target = %lf requested RF = %lf ddc = %lf\n")
127  % mode
128  % (1e-6 * tunres_int.actual_rf_freq)
129  % (1e-6 * tunres_int.actual_dsp_freq)
130  % (1e-6 * ff)
131  % (1e-6 * treq.rf_freq)
132  % (1e-6 * treq.dsp_freq);
133 
134  if(target != tunres_int.actual_rf_freq) {
135  // we found a new one...
136  r_st = tunres_int.actual_rf_freq;
137  target = r_st;
138  }
139  }
140  }
141 
142 }
int main(int argc, char **argv)
void dumpProps(uhd::usrp::multi_usrp::sptr usrp)
std::string getMbName(uhd::usrp::multi_usrp::sptr usrp)