diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-12 19:46:09 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-12 19:46:09 -0800 |
commit | 51e5396079d8af7cf8287b586ff2351a19ae8381 (patch) | |
tree | 166c580e317aff50cb00eb840cc05124aad04161 /lib/usrp/mboard/usrp2.cpp | |
parent | 259f5babf1e1bc1595ad54c6588c1ff5117dc2e3 (diff) | |
download | uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.tar.gz uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.tar.bz2 uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.zip |
Reading the dboard ids from the usrp2.
Diffstat (limited to 'lib/usrp/mboard/usrp2.cpp')
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/usrp/mboard/usrp2.cpp b/lib/usrp/mboard/usrp2.cpp index 9de478672..f744dce59 100644 --- a/lib/usrp/mboard/usrp2.cpp +++ b/lib/usrp/mboard/usrp2.cpp @@ -16,12 +16,12 @@ // #include <uhd/usrp/mboard/usrp2.hpp> -#include "usrp2_fw_common.h" #include <uhd/device.hpp> -#include <boost/thread.hpp> #include <boost/lexical_cast.hpp> +#include <boost/format.hpp> #include <boost/thread.hpp> #include <netinet/in.h> +#include "usrp2_fw_common.h" using namespace uhd::usrp::mboard; @@ -74,6 +74,7 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ * Structors **********************************************************************/ usrp2::usrp2(const device_addr_t &device_addr){ + //initialize the transports for udp _udp_ctrl_transport = uhd::transport::udp::sptr( new uhd::transport::udp( device_addr["addr"], @@ -86,6 +87,15 @@ usrp2::usrp2(const device_addr_t &device_addr){ boost::lexical_cast<std::string>(USRP2_UDP_DATA_PORT) ) ); + //grab the dboard ids over the control line + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO); + usrp2_ctrl_data_t in_data = _ctrl_send_and_recv(out_data); + //TODO assert the control data id response + std::cout << boost::format("rx id 0x%.2x, tx id 0x%.2x") + % ntohs(in_data.data.dboard_ids.rx_id) + % ntohs(in_data.data.dboard_ids.tx_id) << std::endl; + //TODO setup the dboard manager with the dboard ids } usrp2::~usrp2(void){ @@ -93,6 +103,35 @@ usrp2::~usrp2(void){ } /*********************************************************************** + * Transactions + **********************************************************************/ +template <class T> T usrp2::_ctrl_send_and_recv(const T &out_data){ + //fill in the seq number and send + T out_copy = out_data; + out_copy.seq = htonl(++_ctrl_seq_num); + _udp_ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(T))); + + //loop and recieve until the time is up + size_t num_timeouts = 0; + while(true){ + uhd::shared_iovec iov = _udp_ctrl_transport->recv(); + if (iov.len < sizeof(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 + T in_data = *reinterpret_cast<const T *>(iov.base); + if (ntohl(in_data.seq) == _ctrl_seq_num){ + return in_data; + } + //didnt get seq, continue on... + } + } + throw std::runtime_error("usrp2 no control response"); +} + +/*********************************************************************** * Get Properties **********************************************************************/ void usrp2::get(const wax::obj &, wax::obj &){ |