diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-12 18:07:55 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-12 18:07:55 -0800 |
commit | 9fff25f4e5da179ea29ff44278e0415a337870cb (patch) | |
tree | cfbee4cf2921fd4bd415e3af1c1d466f79bab3d7 /lib/usrp/mboard/usrp2.cpp | |
parent | 350f5c5decca20a54132867283448fd32226bbc2 (diff) | |
download | uhd-9fff25f4e5da179ea29ff44278e0415a337870cb.tar.gz uhd-9fff25f4e5da179ea29ff44278e0415a337870cb.tar.bz2 uhd-9fff25f4e5da179ea29ff44278e0415a337870cb.zip |
Added a templated dictionary class because its more useful than map.
Made the device addrs into a string:string dict.
If its all strings we dont have to change the top level caller for new product.
Created shared_iovec class to manage memory for device recvs.
Work on the bro/dude control protocol for usrp2.
Diffstat (limited to 'lib/usrp/mboard/usrp2.cpp')
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/lib/usrp/mboard/usrp2.cpp b/lib/usrp/mboard/usrp2.cpp index 9282a541a..9de478672 100644 --- a/lib/usrp/mboard/usrp2.cpp +++ b/lib/usrp/mboard/usrp2.cpp @@ -16,7 +16,6 @@ // #include <uhd/usrp/mboard/usrp2.hpp> -#include <uhd/transport/udp.hpp> #include "usrp2_fw_common.h" #include <uhd/device.hpp> #include <boost/thread.hpp> @@ -29,35 +28,40 @@ using namespace uhd::usrp::mboard; /*********************************************************************** * Discovery over the udp transport **********************************************************************/ -std::vector<uhd::device_addr_t> usrp2::discover(const device_addr_t &hint){ - std::vector<uhd::device_addr_t> usrp2_addrs; +uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ + device_addrs_t usrp2_addrs; //create a udp transport to communicate + //TODO if an addr is not provided, search all interfaces? std::string ctrl_port = boost::lexical_cast<std::string>(USRP2_UDP_CTRL_PORT); - uhd::transport::udp udp_transport(hint.udp_args.addr, ctrl_port, true); + uhd::transport::udp udp_transport(hint["addr"], ctrl_port, true); //send a hello control packet usrp2_ctrl_data_t ctrl_data_out; - ctrl_data_out.id = htonl(USRP2_CTRL_ID_HELLO); + ctrl_data_out.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO); udp_transport.send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); //loop and recieve until the time is up size_t num_timeouts = 0; while(true){ - boost::asio::const_buffer buff = udp_transport.recv(); + uhd::shared_iovec iov = udp_transport.recv(); //std::cout << boost::asio::buffer_size(buff) << "\n"; - if (boost::asio::buffer_size(buff) < sizeof(usrp2_ctrl_data_t)){ + if (iov.len < sizeof(usrp2_ctrl_data_t)){ //sleep a little so we dont burn cpu if (num_timeouts++ > 50) break; boost::this_thread::sleep(boost::posix_time::milliseconds(1)); }else{ //handle the received data - const usrp2_ctrl_data_t *ctrl_data_in = boost::asio::buffer_cast<const usrp2_ctrl_data_t *>(buff); + const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(iov.base); switch(ntohl(ctrl_data_in->id)){ - case USRP2_CTRL_ID_HELLO: + case USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE: //make a boost asio ipv4 with the raw addr in host byte order - boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.discovery_addrs.ip_addr)); - std::cout << "hello " << ip_addr.to_string() << "\n"; + boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); + device_addr_t new_addr; + new_addr["name"] = "USRP2"; + new_addr["type"] = "udp"; + new_addr["addr"] = ip_addr.to_string(); + usrp2_addrs.push_back(new_addr); break; } } @@ -65,3 +69,39 @@ std::vector<uhd::device_addr_t> usrp2::discover(const device_addr_t &hint){ return usrp2_addrs; } + +/*********************************************************************** + * Structors + **********************************************************************/ +usrp2::usrp2(const device_addr_t &device_addr){ + _udp_ctrl_transport = uhd::transport::udp::sptr( + new uhd::transport::udp( + device_addr["addr"], + boost::lexical_cast<std::string>(USRP2_UDP_CTRL_PORT) + ) + ); + _udp_data_transport = uhd::transport::udp::sptr( + new uhd::transport::udp( + device_addr["addr"], + boost::lexical_cast<std::string>(USRP2_UDP_DATA_PORT) + ) + ); +} + +usrp2::~usrp2(void){ + /* NOP */ +} + +/*********************************************************************** + * Get Properties + **********************************************************************/ +void usrp2::get(const wax::obj &, wax::obj &){ + +} + +/*********************************************************************** + * Set Properties + **********************************************************************/ +void usrp2::set(const wax::obj &, const wax::obj &){ + +} |