SoDaRadio-5.0.3-master:8901fb5
TRControl_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/N200Control.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: N200Control_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  std::vector<std::string> banks = usrp->get_gpio_banks(0);
94  BOOST_FOREACH(std::string bank, banks) {
95  std::cerr << boost::format("GPIO Bank [%s]\n") % bank;
96  }
97 
98 
100 
101  sleep(5);
102 
103  for(int i = 0; i < 8; i++) {
104  ctrl->setTXOn();
105  sleep(2);
106  ctrl->setTXOff();
107  sleep(2);
108  }
109 }
int main(int argc, char **argv)
Generic Control class to activate T/R switching, band switching, and other control functions...
Definition: TRControl.hxx:51
virtual bool setTXOn()=0
activate external controls to enable transmit mode.
virtual bool setTXOff()=0
activate external controls to disable transmit mode.
void dumpProps(uhd::usrp::multi_usrp::sptr usrp)
std::string getMbName(uhd::usrp::multi_usrp::sptr usrp)
static TRControl * makeTRControl(uhd::usrp::multi_usrp::sptr usrp, int mboard=0)
make the appropriate TR control widget given a pointer to a USRP device.
Definition: TRControl.cxx:45