SoDaRadio-5.0.3-master:8901fb5
USRPFrontEnd_test.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 "../src/USRPFrontEnd.hxx"
30 #include <iostream>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <boost/format.hpp>
34 #include <string>
35 #include <list>
36 #include <uhd/usrp/multi_usrp.hpp>
37 #include <vector>
38 #include <string>
39 #include <boost/foreach.hpp>
40 #include <boost/format.hpp>
41 
42 #include <uhd/utils/safe_main.hpp>
43 #include <uhd/version.hpp>
44 #include <uhd/device.hpp>
45 #include <uhd/types/ranges.hpp>
46 #include <uhd/property_tree.hpp>
47 #include <boost/algorithm/string.hpp> //for split
48 #include <uhd/usrp/dboard_id.hpp>
49 #include <uhd/usrp/mboard_eeprom.hpp>
50 #include <uhd/usrp/dboard_eeprom.hpp>
51 
52 
53 std::string getMbName(uhd::usrp::multi_usrp::sptr usrp)
54 {
55  uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
56  std::string mbname = tree->list("/mboards").at(0);
57  return tree->access<std::string>("/mboards/" + mbname + "/name").get();
58 }
59 
60 void dumpProps(uhd::usrp::multi_usrp::sptr usrp)
61 {
62  uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
63  std::string mbname = tree->list("/mboards").at(0);
64 
65  uhd::usrp::mboard_eeprom_t eeprom = tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/" + mbname + "/eeprom").get();
66  BOOST_FOREACH(const std::string & key, eeprom.keys()) {
67  if( eeprom[key].empty() ) {
68  std::cerr << boost::format("Empty key [%s]\n") % key;
69  }
70  else {
71  std::cerr << boost::format(" eeprom[%s] = [%s]\n") % key % eeprom[key];
72  }
73  }
74 
75  std::cerr << boost::format("went the direct route = [%s]\n")
76  % tree->access<uhd::usrp::mboard_eeprom_t>("/mboards/" + mbname + "/eeprom").get()["ip-addr"];
77 }
78 
79 int main(int argc, char ** argv)
80 {
81  if(argc < 2) {
82  std::cerr << "Usage: USRPFrontEnd_test dev-arg-string" << std::endl;
83  exit(-1);
84  }
85 
86  std::string devaddr(argv[1]);
87  uhd::device_addr_t rad(devaddr);
88 
89  uhd::usrp::multi_usrp::sptr usrp;
90  // make the device.
91  usrp = uhd::usrp::multi_usrp::make(rad);
92 
93  // make the proptree
94  SoDa::PropTree tree(usrp, "Test");
95 
96  SoDa::PropTree * rx_fe = getUSRPFrontEnd(&tree, 'R');
97  SoDa::PropTree * tx_fe = getUSRPFrontEnd(&tree, 'T');
98 
99  BOOST_FOREACH(std::string prn, rx_fe->getPropNames()) {
100  std::cerr << boost::format("RXFE prop [%s]\n") % prn;
101  }
102 
103 
104  BOOST_FOREACH(std::string prn, tx_fe->getPropNames()) {
105  std::cerr << boost::format("TXFE prop [%s]\n") % prn;
106  }
107 
108  }
PropTree * getUSRPFrontEnd(PropTree *tree, char tr_choice)
return a pointer to a PropTree object for the first "T" or "R" front end that provides an IQ or QI st...
void dumpProps(uhd::usrp::multi_usrp::sptr usrp)
PropTree class encapsulates the USRP property tree functions to allow better trap and error recovery ...
Definition: PropTree.hxx:44
std::string getMbName(uhd::usrp::multi_usrp::sptr usrp)
std::vector< std::string > getPropNames(const std::string &path=std::string(""))
Definition: PropTree.hxx:112
int main(int argc, char **argv)