在multi_usrp.hpp中以API的方式为用户提供了对USRP的操作方法,用户可以定义usrp指针后直接调用这些方法:即usrp.xxx()。然而,如果如果用户想进行API中没有提供的设置,就需要直接对USRP的属性树进行操作,通过属性树的根节点进入到叶子节点,然后调用叶子节点相应的方法:如usrp->get_device->get_tree()->access<type>("path").get()/set()等。
编译:g++ tree.cpp -o tree -luhd
运行结果:
注意,对于射频子板的操作需要使用list()方法,比如得到射频子板的名称的程序如下:
std::string db_name=usrp->get_device()->get->tree()->list("mboards/0/dboards").at(0);
否则直接向上面使用access()会出现未进行初始化的错误。
其他的节点参考multi_usrp.cpp中的函数。
#include<uhd/usrp/multi_usrp.hpp> //#include<uhd/property_tree.hpp> #include<uhd/usrp/multi_usrp.hpp> #include<iostream> using namespace uhd; using namespace uhd::usrp; int main(){ std::string args=""; uhd::usrp::multi_usrp::sptr usrp=uhd::usrp::multi_usrp::make(args); //get mother board name std::string mb_name; //mb_name=usrp->get_mboard_name(0); mb_name=usrp->get_device()->get_tree()->access<std::string>("mboards/0/name").get(); std::cout<<mb_name<<std::endl; //get time now time_spec_t time_now; time_now=usrp->get_time_now(0); std::cout<<time_now.get_full_secs()<<std::endl; std::cout<<time_now.get_frac_secs()<<std::endl; time_spec_t time_now1; time_now1=usrp->get_device()->get_tree()->access<time_spec_t>("mboards/0/time/now").get(); std::cout<<time_now1.get_full_secs()<<std::endl; //get banks std::vector<std::string>banks; banks=usrp->get_gpio_banks(0); std::cout<<"banks:"<<std::endl; for (int i=0;i<banks.size();i++) std::cout<<"\t"<<banks[i]<<std::endl; std::cout<<std::endl; //get dboard name std::string db_name=usrp->get_device()->get_tree()->list("mboards/0/dboards").at(0); std::cout<<"dboard name:"<<std::endl; std::cout<<"\t"<<db_name<<std::endl; //get RX antenna std::vector<std::string> RX_ANT; RX_ANT=usrp->get_device()->get_tree()->access<std::vector<std::string> >("mboards/0/dboards/A/rx_frontends/0/antenna/options").get(); std::cout<<"RX antenna:"<<std::endl; for (int j=0;j<RX_ANT.size();j++) std::cout<<"\t"<<RX_ANT[j]<<std::endl; //get gain const boost::uint32_t rx_gain=usrp->get_device()->get_tree()->access<boost::uint32_t>("mboards/0/dboards/A/rx_frontends/0/gains/PGA0/value").get(); std::cout<<"RX gain:"<<std::endl; std::cout<<"\t"<<rx_gain<<std::endl; return 0; }
时间: 2024-10-29 06:58:37