diff options
Diffstat (limited to 'lib/usrp')
-rw-r--r-- | lib/usrp/mboard/test.cpp | 4 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 62 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_fw_common.h | 30 | ||||
-rw-r--r-- | lib/usrp/usrp.cpp | 15 |
4 files changed, 87 insertions, 24 deletions
diff --git a/lib/usrp/mboard/test.cpp b/lib/usrp/mboard/test.cpp index 9ad11c046..b4ac66eb7 100644 --- a/lib/usrp/mboard/test.cpp +++ b/lib/usrp/mboard/test.cpp @@ -109,8 +109,10 @@ private: * test usrp mboard class **********************************************************************/ test::test(const device_addr_t &device_addr){ + //extract the number of dboards + size_t num_dboards = boost::lexical_cast<size_t>(device_addr["num_dboards"]); //create a manager for each dboard - for (size_t i = 0; i < device_addr.virtual_args.num_dboards; i++){ + for (size_t i = 0; i < num_dboards; i++){ dboard::interface::sptr ifc(new dummy_interface()); _dboard_managers[boost::lexical_cast<std::string>(i)] = dboard::manager::sptr( new dboard::manager(dboard::ID_BASIC_RX, dboard::ID_BASIC_TX, ifc) 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 &){ + +} diff --git a/lib/usrp/mboard/usrp2_fw_common.h b/lib/usrp/mboard/usrp2_fw_common.h index 217d8cf1c..4ea9d5467 100644 --- a/lib/usrp/mboard/usrp2_fw_common.h +++ b/lib/usrp/mboard/usrp2_fw_common.h @@ -28,24 +28,38 @@ extern "C" { #endif // udp ports for the usrp2 communication -// Dynamic and/or private ports: 49152–65535 +// Dynamic and/or private ports: 49152-65535 #define USRP2_UDP_CTRL_PORT 49152 #define USRP2_UDP_DATA_PORT 49153 typedef enum{ - USRP2_CTRL_ID_NONE, - USRP2_CTRL_ID_HELLO + USRP2_CTRL_ID_HUH_WHAT, + //USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums + //USRP2_CTRL_ID_SUX_MAN, + USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO, + USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE, + USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO, + USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO, + USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE, + USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO } usrp2_ctrl_id_t; typedef struct{ uint32_t id; uint32_t seq; union{ - struct{ - uint32_t ip_addr; - uint8_t mac_addr[6]; - uint8_t _padding[2]; - } discovery_addrs; + uint32_t ip_addr; + uint8_t mac_addr[6]; + /*struct { + uint8_t bank; + uint16_t ddr; + uint16_t mask; + } gpio_ddr_args; + struct { + uint8_t bank; + uint16_t val; + uint16_t mask; + } gpio_val_args;*/ } data; } usrp2_ctrl_data_t; diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp index c49a63d49..68b423538 100644 --- a/lib/usrp/usrp.cpp +++ b/lib/usrp/usrp.cpp @@ -16,6 +16,7 @@ // #include <uhd/usrp/usrp.hpp> +#include <uhd/usrp/mboard/usrp2.hpp> #include <uhd/usrp/mboard/test.hpp> #include <uhd/utils.hpp> #include <boost/format.hpp> @@ -32,22 +33,28 @@ static void send_raw_default(const std::vector<boost::asio::const_buffer> &){ throw std::runtime_error("No callback registered for send raw"); } -static boost::asio::const_buffer recv_raw_default(void){ +static uhd::shared_iovec recv_raw_default(void){ throw std::runtime_error("No callback registered for recv raw"); } /*********************************************************************** * the usrp device wrapper **********************************************************************/ -usrp::usrp(const device_addr_t & device_addr){ +usrp::usrp(const device_addr_t &device_addr){ //set the default callbacks, the code below should replace them _send_raw_cb = boost::bind(&send_raw_default, _1); _recv_raw_cb = boost::bind(&recv_raw_default); //create mboard based on the device addr - if (device_addr.type == DEVICE_ADDR_TYPE_VIRTUAL){ + if (not device_addr.has_key("type")){ + //TODO nothing + } + else if (device_addr["type"] == "test"){ _mboards[""] = mboard::base::sptr(new mboard::test(device_addr)); } + else if (device_addr["type"] == "udp"){ + _mboards[""] = mboard::base::sptr(new mboard::usrp2(device_addr)); + } } usrp::~usrp(void){ @@ -87,6 +94,6 @@ void usrp::send_raw(const std::vector<boost::asio::const_buffer> &buffs){ return _send_raw_cb(buffs); } -boost::asio::const_buffer usrp::recv_raw(void){ +uhd::shared_iovec usrp::recv_raw(void){ return _recv_raw_cb(); } |