summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/include/uhd/config.hpp4
-rw-r--r--host/include/uhd/types/device_addr.hpp10
-rw-r--r--host/include/uhd/types/dict.hpp4
-rw-r--r--host/include/uhd/usrp/dboard_base.hpp24
-rw-r--r--host/include/uhd/usrp/dboard_id.hpp64
-rw-r--r--host/include/uhd/usrp/dboard_manager.hpp2
-rw-r--r--host/include/uhd/utils/algorithm.hpp30
-rw-r--r--host/include/uhd/utils/assert.hpp18
-rw-r--r--host/lib/CMakeLists.txt3
-rw-r--r--host/lib/device.cpp4
-rw-r--r--host/lib/types.cpp4
-rw-r--r--host/lib/usrp/dboard/db_basic_and_lf.cpp20
-rw-r--r--host/lib/usrp/dboard/db_rfx.cpp18
-rw-r--r--host/lib/usrp/dboard/db_xcvr2450.cpp10
-rw-r--r--host/lib/usrp/dboard_base.cpp42
-rw-r--r--host/lib/usrp/dboard_ctor_args.hpp32
-rw-r--r--host/lib/usrp/dboard_eeprom.cpp13
-rw-r--r--host/lib/usrp/dboard_id.cpp68
-rw-r--r--host/lib/usrp/dboard_manager.cpp73
-rw-r--r--host/lib/usrp/usrp2/dboard_iface.cpp57
-rw-r--r--host/test/CMakeLists.txt2
-rw-r--r--host/test/addr_test.cpp17
-rw-r--r--host/test/dict_test.cpp72
-rw-r--r--host/test/error_test.cpp40
-rw-r--r--host/utils/uhd_burn_db_eeprom.cpp8
-rw-r--r--host/utils/uhd_find_devices.cpp2
26 files changed, 453 insertions, 188 deletions
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp
index 941219ac7..227c473ce 100644
--- a/host/include/uhd/config.hpp
+++ b/host/include/uhd/config.hpp
@@ -46,12 +46,12 @@
// http://gcc.gnu.org/wiki/Visibility
// Generic helper definitions for shared library support
-#if defined _WIN32 || defined __CYGWIN__
+#if BOOST_HAS_DECLSPEC
#define UHD_HELPER_DLL_IMPORT __declspec(dllimport)
#define UHD_HELPER_DLL_EXPORT __declspec(dllexport)
#define UHD_HELPER_DLL_LOCAL
#else
- #if __GNUC__ >= 4
+ #if __GNUG__ >= 4
#define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default")))
#define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default")))
#define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden")))
diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp
index e8da2a1ab..e359d9467 100644
--- a/host/include/uhd/types/device_addr.hpp
+++ b/host/include/uhd/types/device_addr.hpp
@@ -40,7 +40,7 @@ namespace uhd{
* An arguments string, is a way to represent a device address
* using a single string with delimiter characters.
* - Ex: addr=192.168.10.2
- * - Ex: addr=192.168.10.2, rx_buff_size=1e6
+ * - Ex: addr=192.168.10.2, recv_buff_size=1e6
*/
class UHD_API device_addr_t : public dict<std::string, std::string>{
public:
@@ -51,17 +51,17 @@ namespace uhd{
device_addr_t(const std::string &args = "");
/*!
- * Convert a device address into a printable string.
- * \return string good for use with std::cout <<
+ * Convert a device address into a pretty print string.
+ * \return a printable string representing the device address
*/
- std::string to_string(void) const;
+ std::string to_pp_string(void) const;
/*!
* Convert the device address into an args string.
* The args string contains delimiter symbols.
* \return a string with delimiter markup
*/
- std::string to_args_str(void) const;
+ std::string to_string(void) const;
};
//handy typedef for a vector of device addresses
diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp
index c8fbc5a9f..b5fb11120 100644
--- a/host/include/uhd/types/dict.hpp
+++ b/host/include/uhd/types/dict.hpp
@@ -29,7 +29,7 @@ namespace uhd{
/*!
* A templated dictionary class with a python-like interface.
*/
- template <class Key, class Val> class dict{
+ template <typename Key, typename Val> class dict{
public:
typedef std::pair<Key, Val> pair_t;
@@ -130,7 +130,7 @@ namespace uhd{
BOOST_FOREACH(pair_t &p, _map){
if (p.first == key) return p.second;
}
- _map.push_back(pair_t(key, Val()));
+ _map.push_back(std::make_pair(key, Val()));
return _map.back().second;
}
diff --git a/host/include/uhd/usrp/dboard_base.hpp b/host/include/uhd/usrp/dboard_base.hpp
index 2025760ee..28bf2ae66 100644
--- a/host/include/uhd/usrp/dboard_base.hpp
+++ b/host/include/uhd/usrp/dboard_base.hpp
@@ -22,7 +22,6 @@
#include <uhd/wax.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
-#include <boost/tuple/tuple.hpp>
#include <uhd/usrp/dboard_id.hpp>
#include <uhd/usrp/dboard_iface.hpp>
@@ -35,13 +34,15 @@ namespace uhd{ namespace usrp{
class UHD_API dboard_base : boost::noncopyable{
public:
typedef boost::shared_ptr<dboard_base> sptr;
- //the constructor args consist of a subdev name, interface, and ids
- //derived classes should pass the args into the dboard_base class ctor
- //but should not have to deal with the internals of the args
- typedef boost::tuple<std::string, dboard_iface::sptr, dboard_id_t, dboard_id_t> ctor_args_t;
+ /*!
+ * An opaque type for the dboard constructor args.
+ * Derived classes should pass the args into the base class,
+ * but should not deal with the internals of the args.
+ */
+ struct ctor_args_impl; typedef ctor_args_impl* ctor_args_t;
//structors
- dboard_base(ctor_args_t const&);
+ dboard_base(ctor_args_t);
virtual ~dboard_base(void);
//interface
@@ -57,9 +58,8 @@ protected:
dboard_id_t get_tx_id(void);
private:
- std::string _subdev_name;
- dboard_iface::sptr _dboard_iface;
- dboard_id_t _rx_id, _tx_id;
+ struct dboard_base_impl;
+ dboard_base_impl *_impl;
};
/*!
@@ -71,7 +71,7 @@ public:
/*!
* Create a new xcvr dboard object, override in subclasses.
*/
- xcvr_dboard_base(ctor_args_t const&);
+ xcvr_dboard_base(ctor_args_t);
virtual ~xcvr_dboard_base(void);
};
@@ -85,7 +85,7 @@ public:
/*!
* Create a new rx dboard object, override in subclasses.
*/
- rx_dboard_base(ctor_args_t const&);
+ rx_dboard_base(ctor_args_t);
virtual ~rx_dboard_base(void);
@@ -103,7 +103,7 @@ public:
/*!
* Create a new rx dboard object, override in subclasses.
*/
- tx_dboard_base(ctor_args_t const&);
+ tx_dboard_base(ctor_args_t);
virtual ~tx_dboard_base(void);
diff --git a/host/include/uhd/usrp/dboard_id.hpp b/host/include/uhd/usrp/dboard_id.hpp
index afacaf8ff..8b6eaf6bd 100644
--- a/host/include/uhd/usrp/dboard_id.hpp
+++ b/host/include/uhd/usrp/dboard_id.hpp
@@ -20,16 +20,70 @@
#include <uhd/config.hpp>
#include <boost/cstdint.hpp>
+#include <boost/operators.hpp>
#include <string>
namespace uhd{ namespace usrp{
-typedef boost::uint16_t dboard_id_t;
+ class UHD_API dboard_id_t : boost::equality_comparable1<dboard_id_t>{
+ public:
+ /*!
+ * Create a dboard id from an integer.
+ * \param id the integer representation
+ */
+ dboard_id_t(boost::uint16_t id = 0xffff);
-namespace dboard_id{
- static const dboard_id_t NONE = 0xffff;
- UHD_API std::string to_string(const dboard_id_t &id);
-}
+ /*!
+ * Obtain a dboard id that represents no dboard.
+ * \return the dboard id with the 0xffff id.
+ */
+ static dboard_id_t none(void);
+
+ /*!
+ * Create a new dboard id from an integer representation.
+ * \param uint16 an unsigned 16 bit integer
+ * \return a new dboard id containing the integer
+ */
+ static dboard_id_t from_uint16(boost::uint16_t uint16);
+
+ /*!
+ * Get the dboard id represented as an integer.
+ * \return an unsigned 16 bit integer representation
+ */
+ boost::uint16_t to_uint16(void) const;
+
+ /*!
+ * Create a new dboard id from a string representation.
+ * If the string has a 0x prefix, it will be parsed as hex.
+ * \param string a numeric string, possibly hex
+ * \return a new dboard id containing the integer
+ */
+ static dboard_id_t from_string(const std::string &string);
+
+ /*!
+ * Get the dboard id represented as an integer.
+ * \return a hex string representation with 0x prefix
+ */
+ std::string to_string(void) const;
+
+ /*!
+ * Get the pretty print representation of this dboard id.
+ * \return a string with the dboard name and id number
+ */
+ std::string to_pp_string(void) const;
+
+ private:
+ boost::uint16_t _id; //internal representation
+ };
+
+ /*!
+ * Comparator operator overloaded for dboard ids.
+ * The boost::equality_comparable provides the !=.
+ * \param lhs the dboard id to the left of the operator
+ * \param rhs the dboard id to the right of the operator
+ * \return true when the dboard ids are equal
+ */
+ UHD_API bool operator==(const dboard_id_t &lhs, const dboard_id_t &rhs);
}} //namespace
diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp
index 007d85bb4..b84fee4e7 100644
--- a/host/include/uhd/usrp/dboard_manager.hpp
+++ b/host/include/uhd/usrp/dboard_manager.hpp
@@ -37,7 +37,7 @@ public:
typedef boost::shared_ptr<dboard_manager> sptr;
//dboard constructor (each dboard should have a ::make with this signature)
- typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t const&);
+ typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t);
/*!
* Register a dboard into the system.
diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp
index 8fe9cde82..72b655745 100644
--- a/host/include/uhd/utils/algorithm.hpp
+++ b/host/include/uhd/utils/algorithm.hpp
@@ -19,43 +19,25 @@
#define INCLUDED_UHD_UTILS_ALGORITHM_HPP
#include <algorithm>
+#include <boost/range/functions.hpp>
/*!
* Useful templated functions and classes that I like to pretend are part of stl
*/
namespace std{
- template<class T, class InputIterator, class Function>
- T reduce(InputIterator first, InputIterator last, Function fcn, T init = 0){
- T tmp = init;
- for ( ; first != last; ++first ){
- tmp = fcn(tmp, *first);
- }
- return tmp;
+ template<typename Range, typename T> inline
+ bool has(const Range &range, const T &value){
+ return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
}
- template<class T, class Iterable, class Function>
- T reduce(Iterable iterable, Function fcn, T init = 0){
- return reduce(iterable.begin(), iterable.end(), fcn, init);
- }
-
- template<class T, class InputIterator>
- bool has(InputIterator first, InputIterator last, const T &elem){
- return last != std::find(first, last, elem);
- }
-
- template<class T, class Iterable>
- bool has(const Iterable &iterable, const T &elem){
- return has(iterable.begin(), iterable.end(), elem);
- }
-
- template<class T> T signum(T n){
+ template<typename T> inline T signum(T n){
if (n < 0) return -1;
if (n > 0) return 1;
return 0;
}
- template<class T> T clip(T val, T minVal, T maxVal){
+ template<typename T> inline T clip(T val, T minVal, T maxVal){
return std::min(std::max(val, minVal), maxVal);
}
diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp
index 01beed757..ed0a95535 100644
--- a/host/include/uhd/utils/assert.hpp
+++ b/host/include/uhd/utils/assert.hpp
@@ -46,28 +46,28 @@ namespace uhd{
* The "what" in the error will show what is
* being set and a list of known good values.
*
- * \param iterable a list of possible settings
- * \param elem an element that may be in the list
+ * \param range a list of possible settings
+ * \param value an element that may be in the list
* \param what a description of what is being set
* \throw assertion_error when elem not in list
*/
- template<class T, class Iterable> void assert_has(
- const Iterable &iterable,
- const T &elem,
+ template<typename T, typename Range> void assert_has(
+ const Range &range,
+ const T &value,
const std::string &what = "unknown"
){
- if (std::has(iterable, elem)) return;
+ if (std::has(range, value)) return;
std::string possible_values = "";
size_t i = 0;
- BOOST_FOREACH(const T &e, iterable){
+ BOOST_FOREACH(const T &v, range){
if (i++ > 0) possible_values += ", ";
- possible_values += boost::lexical_cast<std::string>(e);
+ possible_values += boost::lexical_cast<std::string>(v);
}
boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format(
"Error: %s is not a valid %s. "
"Possible values are: [%s]."
)
- % boost::lexical_cast<std::string>(elem)
+ % boost::lexical_cast<std::string>(value)
% what % possible_values
)));
}
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index d11ecf13b..c9cff3263 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -57,8 +57,9 @@ SET(libuhd_sources
transport/udp_simple.cpp
usrp/dboard_base.cpp
usrp/dboard_eeprom.cpp
- usrp/simple_usrp.cpp
+ usrp/dboard_id.cpp
usrp/dboard_manager.cpp
+ usrp/simple_usrp.cpp
usrp/tune_helper.cpp
)
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index 88bd2cff4..f139ecb20 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -105,14 +105,14 @@ device::sptr device::make(const device_addr_t &hint, size_t which){
//check that we found any devices
if (dev_addr_makers.size() == 0){
throw std::runtime_error(str(
- boost::format("No devices found for ----->\n%s") % hint.to_string()
+ boost::format("No devices found for ----->\n%s") % hint.to_pp_string()
));
}
//check that the which index is valid
if (dev_addr_makers.size() <= which){
throw std::runtime_error(str(
- boost::format("No device at index %d for ----->\n%s") % which % hint.to_string()
+ boost::format("No device at index %d for ----->\n%s") % which % hint.to_pp_string()
));
}
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
index 14f7651d4..ec9c8ac01 100644
--- a/host/lib/types.cpp
+++ b/host/lib/types.cpp
@@ -143,7 +143,7 @@ device_addr_t::device_addr_t(const std::string &args){
}
}
-std::string device_addr_t::to_string(void) const{
+std::string device_addr_t::to_pp_string(void) const{
if (this->size() == 0) return "Empty Device Address";
std::stringstream ss;
@@ -153,7 +153,7 @@ std::string device_addr_t::to_string(void) const{
return ss.str();
}
-std::string device_addr_t::to_args_str(void) const{
+std::string device_addr_t::to_string(void) const{
std::string args_str;
BOOST_FOREACH(const std::string &key, this->keys()){
args_str += key + pair_delim + (*this)[key] + arg_delim;
diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp
index b0fbbd2ec..23ac98872 100644
--- a/host/lib/usrp/dboard/db_basic_and_lf.cpp
+++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp
@@ -34,7 +34,7 @@ using namespace boost::assign;
**********************************************************************/
class basic_rx : public rx_dboard_base{
public:
- basic_rx(ctor_args_t const& args, double max_freq);
+ basic_rx(ctor_args_t args, double max_freq);
~basic_rx(void);
void rx_get(const wax::obj &key, wax::obj &val);
@@ -46,7 +46,7 @@ private:
class basic_tx : public tx_dboard_base{
public:
- basic_tx(ctor_args_t const& args, double max_freq);
+ basic_tx(ctor_args_t args, double max_freq);
~basic_tx(void);
void tx_get(const wax::obj &key, wax::obj &val);
@@ -59,19 +59,19 @@ private:
/***********************************************************************
* Register the basic and LF dboards
**********************************************************************/
-static dboard_base::sptr make_basic_rx(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_basic_rx(dboard_base::ctor_args_t args){
return dboard_base::sptr(new basic_rx(args, 90e9));
}
-static dboard_base::sptr make_basic_tx(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_basic_tx(dboard_base::ctor_args_t args){
return dboard_base::sptr(new basic_tx(args, 90e9));
}
-static dboard_base::sptr make_lf_rx(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_lf_rx(dboard_base::ctor_args_t args){
return dboard_base::sptr(new basic_rx(args, 32e6));
}
-static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t args){
return dboard_base::sptr(new basic_tx(args, 32e6));
}
@@ -85,7 +85,7 @@ UHD_STATIC_BLOCK(reg_basic_and_lf_dboards){
/***********************************************************************
* Basic and LF RX dboard
**********************************************************************/
-basic_rx::basic_rx(ctor_args_t const& args, double max_freq) : rx_dboard_base(args){
+basic_rx::basic_rx(ctor_args_t args, double max_freq) : rx_dboard_base(args){
_max_freq = max_freq;
}
@@ -101,7 +101,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){
switch(key.as<subdev_prop_t>()){
case SUBDEV_PROP_NAME:
val = std::string(str(boost::format("%s - %s")
- % dboard_id::to_string(get_rx_id())
+ % get_rx_id().to_pp_string()
% get_subdev_name()
));
return;
@@ -187,7 +187,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){
/***********************************************************************
* Basic and LF TX dboard
**********************************************************************/
-basic_tx::basic_tx(ctor_args_t const& args, double max_freq) : tx_dboard_base(args){
+basic_tx::basic_tx(ctor_args_t args, double max_freq) : tx_dboard_base(args){
_max_freq = max_freq;
}
@@ -202,7 +202,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<subdev_prop_t>()){
case SUBDEV_PROP_NAME:
- val = dboard_id::to_string(get_tx_id());
+ val = get_tx_id().to_pp_string();
return;
case SUBDEV_PROP_OTHERS:
diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp
index 175f55eab..bbc9716b1 100644
--- a/host/lib/usrp/dboard/db_rfx.cpp
+++ b/host/lib/usrp/dboard/db_rfx.cpp
@@ -63,7 +63,7 @@ static const float _max_rx_pga0_gain = 45;
class rfx_xcvr : public xcvr_dboard_base{
public:
rfx_xcvr(
- ctor_args_t const& args,
+ ctor_args_t args,
const freq_range_t &freq_range,
bool rx_div2, bool tx_div2
);
@@ -108,23 +108,23 @@ private:
/***********************************************************************
* Register the RFX dboards (min freq, max freq, rx div2, tx div2)
**********************************************************************/
-static dboard_base::sptr make_rfx_flex400(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_rfx_flex400(dboard_base::ctor_args_t args){
return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(400e6, 500e6), false, true));
}
-static dboard_base::sptr make_rfx_flex900(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_rfx_flex900(dboard_base::ctor_args_t args){
return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(750e6, 1050e6), true, true));
}
-static dboard_base::sptr make_rfx_flex1800(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_rfx_flex1800(dboard_base::ctor_args_t args){
return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(1500e6, 2100e6), false, false));
}
-static dboard_base::sptr make_rfx_flex1200(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_rfx_flex1200(dboard_base::ctor_args_t args){
return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(1150e6, 1450e6), true, true));
}
-static dboard_base::sptr make_rfx_flex2400(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_rfx_flex2400(dboard_base::ctor_args_t args){
return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(2300e6, 2900e6), false, false));
}
@@ -149,7 +149,7 @@ UHD_STATIC_BLOCK(reg_rfx_dboards){
* Structors
**********************************************************************/
rfx_xcvr::rfx_xcvr(
- ctor_args_t const& args,
+ ctor_args_t args,
const freq_range_t &freq_range,
bool rx_div2, bool tx_div2
) : xcvr_dboard_base(args){
@@ -351,7 +351,7 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<subdev_prop_t>()){
case SUBDEV_PROP_NAME:
- val = dboard_id::to_string(get_rx_id());
+ val = get_rx_id().to_pp_string();
return;
case SUBDEV_PROP_OTHERS:
@@ -448,7 +448,7 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<subdev_prop_t>()){
case SUBDEV_PROP_NAME:
- val = dboard_id::to_string(get_tx_id());
+ val = get_tx_id().to_pp_string();
return;
case SUBDEV_PROP_OTHERS:
diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp
index 0dfef2a0a..3bf866fc8 100644
--- a/host/lib/usrp/dboard/db_xcvr2450.cpp
+++ b/host/lib/usrp/dboard/db_xcvr2450.cpp
@@ -89,7 +89,7 @@ static const uhd::dict<std::string, gain_range_t> xcvr_rx_gain_ranges = map_list
**********************************************************************/
class xcvr2450 : public xcvr_dboard_base{
public:
- xcvr2450(ctor_args_t const& args);
+ xcvr2450(ctor_args_t args);
~xcvr2450(void);
void rx_get(const wax::obj &key, wax::obj &val);
@@ -152,7 +152,7 @@ private:
/***********************************************************************
* Register the XCVR 2450 dboard
**********************************************************************/
-static dboard_base::sptr make_xcvr2450(dboard_base::ctor_args_t const& args){
+static dboard_base::sptr make_xcvr2450(dboard_base::ctor_args_t args){
return dboard_base::sptr(new xcvr2450(args));
}
@@ -165,7 +165,7 @@ UHD_STATIC_BLOCK(reg_xcvr2450_dboard){
/***********************************************************************
* Structors
**********************************************************************/
-xcvr2450::xcvr2450(ctor_args_t const& args) : xcvr_dboard_base(args){
+xcvr2450::xcvr2450(ctor_args_t args) : xcvr_dboard_base(args){
//enable only the clocks we need
this->get_iface()->set_clock_enabled(dboard_iface::UNIT_TX, true);
@@ -444,7 +444,7 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<subdev_prop_t>()){
case SUBDEV_PROP_NAME:
- val = dboard_id::to_string(get_rx_id());
+ val = get_rx_id().to_pp_string();
return;
case SUBDEV_PROP_OTHERS:
@@ -542,7 +542,7 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<subdev_prop_t>()){
case SUBDEV_PROP_NAME:
- val = dboard_id::to_string(get_tx_id());
+ val = get_tx_id().to_pp_string();
return;
case SUBDEV_PROP_OTHERS:
diff --git a/host/lib/usrp/dboard_base.cpp b/host/lib/usrp/dboard_base.cpp
index 68e4743d1..bd4b37ef3 100644
--- a/host/lib/usrp/dboard_base.cpp
+++ b/host/lib/usrp/dboard_base.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include "dboard_ctor_args.hpp"
#include <uhd/usrp/dboard_base.hpp>
#include <boost/format.hpp>
#include <stdexcept>
@@ -24,43 +25,48 @@ using namespace uhd::usrp;
/***********************************************************************
* dboard_base dboard dboard_base class
**********************************************************************/
-dboard_base::dboard_base(ctor_args_t const& args){
- boost::tie(_subdev_name, _dboard_iface, _rx_id, _tx_id) = args;
+struct dboard_base::dboard_base_impl{
+ ctor_args_impl args;
+ dboard_base_impl(ctor_args_t args) : args(*args){}
+};
+
+dboard_base::dboard_base(ctor_args_t args){
+ _impl = new dboard_base_impl(args);
}
dboard_base::~dboard_base(void){
- /* NOP */
+ delete _impl;
}
std::string dboard_base::get_subdev_name(void){
- return _subdev_name;
+ return _impl->args.sd_name;
}
dboard_iface::sptr dboard_base::get_iface(void){
- return _dboard_iface;
+ return _impl->args.db_iface;
}
dboard_id_t dboard_base::get_rx_id(void){
- return _rx_id;
+ return _impl->args.rx_id;
}
dboard_id_t dboard_base::get_tx_id(void){
- return _tx_id;
+ return _impl->args.tx_id;
}
/***********************************************************************
* xcvr dboard dboard_base class
**********************************************************************/
-xcvr_dboard_base::xcvr_dboard_base(ctor_args_t const& args) : dboard_base(args){
- if (get_rx_id() == dboard_id::NONE){
+xcvr_dboard_base::xcvr_dboard_base(ctor_args_t args) : dboard_base(args){
+ if (get_rx_id() == dboard_id_t::none()){
throw std::runtime_error(str(boost::format(
"cannot create xcvr board when the rx id is \"%s\""
- ) % dboard_id::to_string(dboard_id::NONE)));
+ ) % dboard_id_t::none().to_pp_string()));
}
- if (get_tx_id() == dboard_id::NONE){
+ if (get_tx_id() == dboard_id_t::none()){
throw std::runtime_error(str(boost::format(
"cannot create xcvr board when the tx id is \"%s\""
- ) % dboard_id::to_string(dboard_id::NONE)));
+ ) % dboard_id_t::none().to_pp_string()));
}
}
@@ -71,12 +77,12 @@ xcvr_dboard_base::~xcvr_dboard_base(void){
/***********************************************************************
* rx dboard dboard_base class
**********************************************************************/
-rx_dboard_base::rx_dboard_base(ctor_args_t const& args) : dboard_base(args){
- if (get_tx_id() != dboard_id::NONE){
+rx_dboard_base::rx_dboard_base(ctor_args_t args) : dboard_base(args){
+ if (get_tx_id() != dboard_id_t::none()){
throw std::runtime_error(str(boost::format(
"cannot create rx board when the tx id is \"%s\""
" -> expected a tx id of \"%s\""
- ) % dboard_id::to_string(get_tx_id()) % dboard_id::to_string(dboard_id::NONE)));
+ ) % get_tx_id().to_pp_string() % dboard_id_t::none().to_pp_string()));
}
}
@@ -95,12 +101,12 @@ void rx_dboard_base::tx_set(const wax::obj &, const wax::obj &){
/***********************************************************************
* tx dboard dboard_base class
**********************************************************************/
-tx_dboard_base::tx_dboard_base(ctor_args_t const& args) : dboard_base(args){
- if (get_rx_id() != dboard_id::NONE){
+tx_dboard_base::tx_dboard_base(ctor_args_t args) : dboard_base(args){
+ if (get_rx_id() != dboard_id_t::none()){
throw std::runtime_error(str(boost::format(
"cannot create tx board when the rx id is \"%s\""
" -> expected a rx id of \"%s\""
- ) % dboard_id::to_string(get_rx_id()) % dboard_id::to_string(dboard_id::NONE)));
+ ) % get_rx_id().to_pp_string() % dboard_id_t::none().to_pp_string()));
}
}
diff --git a/host/lib/usrp/dboard_ctor_args.hpp b/host/lib/usrp/dboard_ctor_args.hpp
new file mode 100644
index 000000000..13abe79e8
--- /dev/null
+++ b/host/lib/usrp/dboard_ctor_args.hpp
@@ -0,0 +1,32 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_DBOARD_CTOR_ARGS_HPP
+#define INCLUDED_DBOARD_CTOR_ARGS_HPP
+
+#include <uhd/usrp/dboard_id.hpp>
+#include <uhd/usrp/dboard_base.hpp>
+#include <uhd/usrp/dboard_iface.hpp>
+#include <string>
+
+struct uhd::usrp::dboard_base::ctor_args_impl{
+ std::string sd_name;
+ dboard_iface::sptr db_iface;
+ dboard_id_t rx_id, tx_id;
+};
+
+#endif /* INCLUDED_DBOARD_CTOR_ARGS_HPP */
diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp
index 54e7a4fd9..fa3631948 100644
--- a/host/lib/usrp/dboard_eeprom.cpp
+++ b/host/lib/usrp/dboard_eeprom.cpp
@@ -80,19 +80,20 @@ dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){
UHD_ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN);
UHD_ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE);
UHD_ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes));
- id = \
- (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) |
- (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) ;
+ id = dboard_id_t::from_uint16(0
+ | (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0)
+ | (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8)
+ );
}catch(const uhd::assert_error &){
- id = dboard_id::NONE;
+ id = dboard_id_t::none();
}
}
byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){
byte_vector_t bytes(DB_EEPROM_CLEN, 0); //defaults to all zeros
bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE;
- bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id >> 0);
- bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id >> 8);
+ bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id.to_uint16() >> 0);
+ bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id.to_uint16() >> 8);
bytes[DB_EEPROM_CHKSUM] = checksum(bytes);
return bytes;
}
diff --git a/host/lib/usrp/dboard_id.cpp b/host/lib/usrp/dboard_id.cpp
new file mode 100644
index 000000000..3028d2a3b
--- /dev/null
+++ b/host/lib/usrp/dboard_id.cpp
@@ -0,0 +1,68 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/usrp/dboard_id.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/format.hpp>
+#include <sstream>
+#include <iostream>
+
+using namespace uhd::usrp;
+
+dboard_id_t::dboard_id_t(boost::uint16_t id){
+ _id = id;
+}
+
+dboard_id_t dboard_id_t::none(void){
+ return dboard_id_t();
+}
+
+dboard_id_t dboard_id_t::from_uint16(boost::uint16_t uint16){
+ return dboard_id_t(uint16);
+}
+
+boost::uint16_t dboard_id_t::to_uint16(void) const{
+ return _id;
+}
+
+//used with lexical cast to parse a hex string
+template <class T> struct to_hex{
+ T value;
+ operator T() const {return value;}
+ friend std::istream& operator>>(std::istream& in, to_hex& out){
+ in >> std::hex >> out.value;
+ return in;
+ }
+};
+
+dboard_id_t dboard_id_t::from_string(const std::string &string){
+ if (string.substr(0, 2) == "0x"){
+ return dboard_id_t::from_uint16(boost::lexical_cast<to_hex<boost::uint16_t> >(string));
+ }
+ return dboard_id_t::from_uint16(boost::lexical_cast<boost::uint16_t>(string));
+}
+
+std::string dboard_id_t::to_string(void) const{
+ return str(boost::format("0x%04x") % this->to_uint16());
+}
+
+//Note: to_pp_string is implemented in the dboard manager
+//because it needs access to the dboard registration table
+
+bool uhd::usrp::operator==(const dboard_id_t &lhs, const dboard_id_t &rhs){
+ return lhs.to_uint16() == rhs.to_uint16();
+}
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 390c1d3c9..4f5d0a473 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include "dboard_ctor_args.hpp"
#include <uhd/usrp/dboard_manager.hpp>
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/utils/gain_handler.hpp>
@@ -26,6 +27,7 @@
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
+#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
@@ -49,15 +51,18 @@ void dboard_manager::register_dboard(
//std::cout << "registering: " << name << std::endl;
if (get_id_to_args_map().has_key(dboard_id)){
throw std::runtime_error(str(boost::format(
- "The dboard id 0x%04x is already registered to %s."
- ) % dboard_id % dboard_id::to_string(dboard_id)));
+ "The dboard id %s is already registered to %s."
+ ) % dboard_id.to_string() % dboard_id.to_pp_string()));
}
get_id_to_args_map()[dboard_id] = args_t(dboard_ctor, name, subdev_names);
}
-std::string dboard_id::to_string(const dboard_id_t &id){
- std::string name = (get_id_to_args_map().has_key(id))? get_id_to_args_map()[id].get<1>() : "unknown";
- return str(boost::format("%s (0x%04x)") % name % id);
+std::string dboard_id_t::to_pp_string(void) const{
+ std::string name = "unknown";
+ if (get_id_to_args_map().has_key(*this)){
+ name = get_id_to_args_map()[*this].get<1>();
+ }
+ return str(boost::format("%s (%s)") % name % this->to_string());
}
/***********************************************************************
@@ -162,26 +167,27 @@ dboard_manager::sptr dboard_manager::make(
* implementation class methods
**********************************************************************/
static args_t get_dboard_args(
- dboard_id_t dboard_id,
- std::string const& xx_type
+ dboard_iface::unit_t unit,
+ dboard_id_t dboard_id
){
- //special case, its rx and the none id (0xffff)
- if (xx_type == "rx" and dboard_id == dboard_id::NONE){
- return get_dboard_args(0x0001, xx_type);
- }
-
- //special case, its tx and the none id (0xffff)
- if (xx_type == "tx" and dboard_id == dboard_id::NONE){
- return get_dboard_args(0x0000, xx_type);
+ //special case, the none id was provided, use the following ids
+ if (dboard_id == dboard_id_t::none()){
+ std::cerr << boost::format(
+ "Warning: unregistered dboard id: %s"
+ " -> defaulting to a basic board"
+ ) % dboard_id.to_pp_string() << std::endl;
+ UHD_ASSERT_THROW(get_id_to_args_map().has_key(0x0001));
+ UHD_ASSERT_THROW(get_id_to_args_map().has_key(0x0000));
+ switch(unit){
+ case dboard_iface::UNIT_RX: return get_dboard_args(unit, 0x0001);
+ case dboard_iface::UNIT_TX: return get_dboard_args(unit, 0x0000);
+ default: UHD_ASSERT_THROW(false);
+ }
}
//verify that there is a registered constructor for this id
if (not get_id_to_args_map().has_key(dboard_id)){
- /*throw std::runtime_error(str(
- boost::format("Unregistered %s dboard id: %s")
- % xx_type % dboard_id::to_string(dboard_id)
- ));*/
- return get_dboard_args(dboard_id::NONE, xx_type);
+ return get_dboard_args(unit, dboard_id_t::none());
}
//return the dboard args for this id
@@ -196,21 +202,26 @@ dboard_manager_impl::dboard_manager_impl(
_iface = iface;
dboard_ctor_t rx_dboard_ctor; std::string rx_name; prop_names_t rx_subdevs;
- boost::tie(rx_dboard_ctor, rx_name, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx");
+ boost::tie(rx_dboard_ctor, rx_name, rx_subdevs) = get_dboard_args(dboard_iface::UNIT_RX, rx_dboard_id);
dboard_ctor_t tx_dboard_ctor; std::string tx_name; prop_names_t tx_subdevs;
- boost::tie(tx_dboard_ctor, tx_name, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx");
+ boost::tie(tx_dboard_ctor, tx_name, tx_subdevs) = get_dboard_args(dboard_iface::UNIT_TX, tx_dboard_id);
//initialize the gpio pins before creating subdevs
set_nice_dboard_if();
+ //dboard constructor args
+ dboard_base::ctor_args_impl db_ctor_args;
+ db_ctor_args.db_iface = iface;
+ db_ctor_args.rx_id = rx_dboard_id;
+ db_ctor_args.tx_id = tx_dboard_id;
+
//make xcvr subdevs (make one subdev for both rx and tx dboards)
if (rx_dboard_ctor == tx_dboard_ctor){
UHD_ASSERT_THROW(rx_subdevs == tx_subdevs);
BOOST_FOREACH(const std::string &subdev, rx_subdevs){
- dboard_base::sptr xcvr_dboard = rx_dboard_ctor(
- dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, tx_dboard_id)
- );
+ db_ctor_args.sd_name = subdev;
+ dboard_base::sptr xcvr_dboard = rx_dboard_ctor(&db_ctor_args);
//create a rx proxy for this xcvr board
_rx_dboards[subdev] = subdev_proxy::sptr(
new subdev_proxy(xcvr_dboard, subdev_proxy::RX_TYPE)
@@ -226,9 +237,9 @@ dboard_manager_impl::dboard_manager_impl(
else{
//make the rx subdevs
BOOST_FOREACH(const std::string &subdev, rx_subdevs){
- dboard_base::sptr rx_dboard = rx_dboard_ctor(
- dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, dboard_id::NONE)
- );
+ db_ctor_args.sd_name = subdev;
+ db_ctor_args.tx_id = dboard_id_t::none();
+ dboard_base::sptr rx_dboard = rx_dboard_ctor(&db_ctor_args);
//create a rx proxy for this rx board
_rx_dboards[subdev] = subdev_proxy::sptr(
new subdev_proxy(rx_dboard, subdev_proxy::RX_TYPE)
@@ -236,9 +247,9 @@ dboard_manager_impl::dboard_manager_impl(
}
//make the tx subdevs
BOOST_FOREACH(const std::string &subdev, tx_subdevs){
- dboard_base::sptr tx_dboard = tx_dboard_ctor(
- dboard_base::ctor_args_t(subdev, iface, dboard_id::NONE, tx_dboard_id)
- );
+ db_ctor_args.sd_name = subdev;
+ db_ctor_args.rx_id = dboard_id_t::none();
+ dboard_base::sptr tx_dboard = tx_dboard_ctor(&db_ctor_args);
//create a tx proxy for this tx board
_tx_dboards[subdev] = subdev_proxy::sptr(
new subdev_proxy(tx_dboard, subdev_proxy::TX_TYPE)
diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp
index 74d80163c..372a5af07 100644
--- a/host/lib/usrp/usrp2/dboard_iface.cpp
+++ b/host/lib/usrp/usrp2/dboard_iface.cpp
@@ -29,6 +29,7 @@
using namespace uhd;
using namespace uhd::usrp;
+using namespace boost::assign;
class usrp2_dboard_iface : public dboard_iface{
public:
@@ -122,49 +123,42 @@ double usrp2_dboard_iface::get_clock_rate(unit_t){
void usrp2_dboard_iface::set_clock_enabled(unit_t unit, bool enb){
switch(unit){
- case UNIT_RX:
- _clk_ctrl->enable_rx_dboard_clock(enb);
- return;
- case UNIT_TX:
- _clk_ctrl->enable_tx_dboard_clock(enb);
- return;
+ case UNIT_RX: _clk_ctrl->enable_rx_dboard_clock(enb); return;
+ case UNIT_TX: _clk_ctrl->enable_tx_dboard_clock(enb); return;
}
}
/***********************************************************************
* GPIO
**********************************************************************/
-static int unit_to_shift(dboard_iface::unit_t unit){
- switch(unit){
- case dboard_iface::UNIT_RX: return 0;
- case dboard_iface::UNIT_TX: return 16;
- }
- throw std::runtime_error("unknown unit type");
-}
+static const uhd::dict<dboard_iface::unit_t, int> unit_to_shift = map_list_of
+ (dboard_iface::UNIT_RX, 0)
+ (dboard_iface::UNIT_TX, 16)
+;
void usrp2_dboard_iface::set_gpio_ddr(unit_t unit, boost::uint16_t value){
_ddr_shadow = \
- (_ddr_shadow & ~(0xffff << unit_to_shift(unit))) |
- (boost::uint32_t(value) << unit_to_shift(unit));
+ (_ddr_shadow & ~(0xffff << unit_to_shift[unit])) |
+ (boost::uint32_t(value) << unit_to_shift[unit]);
_iface->poke32(FR_GPIO_DDR, _ddr_shadow);
}
boost::uint16_t usrp2_dboard_iface::read_gpio(unit_t unit){
- return boost::uint16_t(_iface->peek32(FR_GPIO_IO) >> unit_to_shift(unit));
+ return boost::uint16_t(_iface->peek32(FR_GPIO_IO) >> unit_to_shift[unit]);
}
void usrp2_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){
//define mapping of unit to atr regs to register address
static const uhd::dict<
unit_t, uhd::dict<atr_reg_t, boost::uint32_t>
- > unit_to_atr_to_addr = boost::assign::map_list_of
- (UNIT_RX, boost::assign::map_list_of
+ > unit_to_atr_to_addr = map_list_of
+ (UNIT_RX, map_list_of
(ATR_REG_IDLE, FR_ATR_IDLE_RXSIDE)
(ATR_REG_TX_ONLY, FR_ATR_INTX_RXSIDE)
(ATR_REG_RX_ONLY, FR_ATR_INRX_RXSIDE)
(ATR_REG_FULL_DUPLEX, FR_ATR_FULL_RXSIDE)
)
- (UNIT_TX, boost::assign::map_list_of
+ (UNIT_TX, map_list_of
(ATR_REG_IDLE, FR_ATR_IDLE_TXSIDE)
(ATR_REG_TX_ONLY, FR_ATR_INTX_TXSIDE)
(ATR_REG_RX_ONLY, FR_ATR_INRX_TXSIDE)
@@ -177,19 +171,10 @@ void usrp2_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t
/***********************************************************************
* SPI
**********************************************************************/
-/*!
- * Static function to convert a unit type enum
- * to an over-the-wire value for the spi device.
- * \param unit the dboard interface unit type enum
- * \return an over the wire representation
- */
-static boost::uint8_t unit_to_otw_spi_dev(dboard_iface::unit_t unit){
- switch(unit){
- case dboard_iface::UNIT_TX: return SPI_SS_TX_DB;
- case dboard_iface::UNIT_RX: return SPI_SS_RX_DB;
- }
- throw std::invalid_argument("unknown unit type");
-}
+static const uhd::dict<dboard_iface::unit_t, int> unit_to_spi_dev = map_list_of
+ (dboard_iface::UNIT_TX, SPI_SS_TX_DB)
+ (dboard_iface::UNIT_RX, SPI_SS_RX_DB)
+;
void usrp2_dboard_iface::write_spi(
unit_t unit,
@@ -197,7 +182,7 @@ void usrp2_dboard_iface::write_spi(
boost::uint32_t data,
size_t num_bits
){
- _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, false /*no rb*/);
+ _iface->transact_spi(unit_to_spi_dev[unit], config, data, num_bits, false /*no rb*/);
}
boost::uint32_t usrp2_dboard_iface::read_write_spi(
@@ -206,7 +191,7 @@ boost::uint32_t usrp2_dboard_iface::read_write_spi(
boost::uint32_t data,
size_t num_bits
){
- return _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, true /*rb*/);
+ return _iface->transact_spi(unit_to_spi_dev[unit], config, data, num_bits, true /*rb*/);
}
/***********************************************************************
@@ -224,7 +209,7 @@ byte_vector_t usrp2_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes
* Aux DAX/ADC
**********************************************************************/
void usrp2_dboard_iface::_write_aux_dac(unit_t unit){
- static const uhd::dict<unit_t, int> unit_to_spi_dac = boost::assign::map_list_of
+ static const uhd::dict<unit_t, int> unit_to_spi_dac = map_list_of
(UNIT_RX, SPI_SS_RX_DAC)
(UNIT_TX, SPI_SS_TX_DAC)
;
@@ -248,7 +233,7 @@ void usrp2_dboard_iface::write_aux_dac(unit_t unit, int which, float value){
}
float usrp2_dboard_iface::read_aux_adc(unit_t unit, int which){
- static const uhd::dict<unit_t, int> unit_to_spi_adc = boost::assign::map_list_of
+ static const uhd::dict<unit_t, int> unit_to_spi_adc = map_list_of
(UNIT_RX, SPI_SS_RX_ADC)
(UNIT_TX, SPI_SS_TX_ADC)
;
diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt
index 1791d9082..61b0b503d 100644
--- a/host/test/CMakeLists.txt
+++ b/host/test/CMakeLists.txt
@@ -21,6 +21,8 @@
ADD_EXECUTABLE(main_test
main_test.cpp
addr_test.cpp
+ dict_test.cpp
+ error_test.cpp
gain_handler_test.cpp
vrt_test.cpp
wax_test.cpp
diff --git a/host/test/addr_test.cpp b/host/test/addr_test.cpp
index 93b7cc0df..0c50200d6 100644
--- a/host/test/addr_test.cpp
+++ b/host/test/addr_test.cpp
@@ -18,6 +18,7 @@
#include <boost/test/unit_test.hpp>
#include <uhd/types/mac_addr.hpp>
#include <uhd/types/device_addr.hpp>
+#include <uhd/usrp/dboard_id.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include <algorithm>
@@ -41,8 +42,8 @@ BOOST_AUTO_TEST_CASE(test_device_addr){
dev_addr["key2"] = "val2";
//convert to and from args string
- std::cout << "Pretty Print: " << std::endl << dev_addr.to_string();
- std::string args_str = dev_addr.to_args_str();
+ std::cout << "Pretty Print: " << std::endl << dev_addr.to_pp_string();
+ std::string args_str = dev_addr.to_string();
std::cout << "Args String: " << args_str << std::endl;
uhd::device_addr_t new_dev_addr(args_str);
@@ -65,3 +66,15 @@ BOOST_AUTO_TEST_CASE(test_device_addr){
new_dev_addr_vals.begin(), new_dev_addr_vals.end()
);
}
+
+BOOST_AUTO_TEST_CASE(test_dboard_id){
+ std::cout << "Testing dboard id..." << std::endl;
+
+ using namespace uhd::usrp;
+
+ BOOST_CHECK(dboard_id_t() == dboard_id_t::none());
+ BOOST_CHECK_EQUAL(dboard_id_t().to_uint16(), dboard_id_t::none().to_uint16());
+ BOOST_CHECK_EQUAL(dboard_id_t::from_string("0x1234").to_uint16(), 0x1234);
+ BOOST_CHECK_EQUAL(dboard_id_t::from_string("1234").to_uint16(), 1234);
+ std::cout << "Pretty Print: " << std::endl << dboard_id_t::none().to_pp_string();
+}
diff --git a/host/test/dict_test.cpp b/host/test/dict_test.cpp
new file mode 100644
index 000000000..0501a7878
--- /dev/null
+++ b/host/test/dict_test.cpp
@@ -0,0 +1,72 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <boost/test/unit_test.hpp>
+#include <uhd/types/dict.hpp>
+#include <boost/assign/list_of.hpp>
+
+BOOST_AUTO_TEST_CASE(test_dict_init){
+ uhd::dict<int, int> d;
+ d[-1] = 3;
+ d[0] = 4;
+ d[1] = 5;
+ BOOST_CHECK(d.has_key(0));
+ BOOST_CHECK(not d.has_key(2));
+ BOOST_CHECK(d.keys()[1] == 0);
+ BOOST_CHECK(d.vals()[1] == 4);
+ BOOST_CHECK_EQUAL(d[-1], 3);
+}
+
+BOOST_AUTO_TEST_CASE(test_dict_assign){
+ uhd::dict<int, int> d = boost::assign::map_list_of
+ (-1, 3)
+ (0, 4)
+ (1, 5)
+ ;
+ BOOST_CHECK(d.has_key(0));
+ BOOST_CHECK(not d.has_key(2));
+ BOOST_CHECK(d.keys()[1] == 0);
+ BOOST_CHECK(d.vals()[1] == 4);
+ BOOST_CHECK_EQUAL(d[-1], 3);
+}
+
+BOOST_AUTO_TEST_CASE(test_const_dict){
+ const uhd::dict<int, int> d = boost::assign::map_list_of
+ (-1, 3)
+ (0, 4)
+ (1, 5)
+ ;
+ BOOST_CHECK(d.has_key(0));
+ BOOST_CHECK(not d.has_key(2));
+ BOOST_CHECK(d.keys()[1] == 0);
+ BOOST_CHECK(d.vals()[1] == 4);
+ BOOST_CHECK_EQUAL(d[-1], 3);
+ BOOST_CHECK_THROW(d[2], std::exception);
+}
+
+BOOST_AUTO_TEST_CASE(test_dict_pop){
+ uhd::dict<int, int> d = boost::assign::map_list_of
+ (-1, 3)
+ (0, 4)
+ (1, 5)
+ ;
+ BOOST_CHECK(d.has_key(0));
+ BOOST_CHECK_EQUAL(d.pop(0), 4);
+ BOOST_CHECK(not d.has_key(0));
+ BOOST_CHECK(d.keys()[0] == -1);
+ BOOST_CHECK(d.keys()[1] == 1);
+}
diff --git a/host/test/error_test.cpp b/host/test/error_test.cpp
new file mode 100644
index 000000000..c5b0af45e
--- /dev/null
+++ b/host/test/error_test.cpp
@@ -0,0 +1,40 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <boost/test/unit_test.hpp>
+#include <uhd/utils/assert.hpp>
+#include <boost/exception/diagnostic_information.hpp>
+#include <vector>
+#include <iostream>
+
+BOOST_AUTO_TEST_CASE(test_assert_has){
+ std::vector<int> vec;
+ vec.push_back(2);
+ vec.push_back(3);
+ vec.push_back(5);
+
+ //verify the std::has utility
+ BOOST_CHECK(std::has(vec, 2));
+ BOOST_CHECK(not std::has(vec, 1));
+
+ std::cout << "The output of the assert_has error:" << std::endl;
+ try{
+ uhd::assert_has(vec, 1, "prime");
+ }catch(const boost::exception &e){
+ std::cout << boost::diagnostic_information(e) << std::endl;
+ }
+}
diff --git a/host/utils/uhd_burn_db_eeprom.cpp b/host/utils/uhd_burn_db_eeprom.cpp
index c07b43f16..dfd9decba 100644
--- a/host/utils/uhd_burn_db_eeprom.cpp
+++ b/host/utils/uhd_burn_db_eeprom.cpp
@@ -24,11 +24,9 @@
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/usrp/dboard_props.hpp>
#include <boost/program_options.hpp>
-#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <boost/assign.hpp>
#include <iostream>
-#include <sstream>
using namespace uhd;
using namespace uhd::usrp;
@@ -89,14 +87,14 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
if (vm.count("id") == 0){
std::cout << boost::format("Getting dbid on %s dboard...") % prefix << std::endl;
dboard_id_t id = dboard[DBOARD_PROP_DBOARD_ID].as<dboard_id_t>();
- std::cout << boost::format(" Current dbid: %s") % dboard_id::to_string(id) << std::endl;
+ std::cout << boost::format(" Current dbid: %s") % id.to_pp_string() << std::endl;
}
//write a new dboard id to eeprom
else{
- dboard_id_t id = boost::lexical_cast<to_hex<dboard_id_t> >(vm["id"].as<std::string>());
+ dboard_id_t id = dboard_id_t::from_string(vm["id"].as<std::string>());
std::cout << boost::format("Setting dbid on %s dboard...") % prefix << std::endl;
- std::cout << boost::format(" New dbid: %s") % dboard_id::to_string(id) << std::endl;
+ std::cout << boost::format(" New dbid: %s") % id.to_pp_string() << std::endl;
dboard[DBOARD_PROP_DBOARD_ID] = id;
}
diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp
index 69e550fd4..b778eeb68 100644
--- a/host/utils/uhd_find_devices.cpp
+++ b/host/utils/uhd_find_devices.cpp
@@ -52,7 +52,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
std::cout << "--------------------------------------------------" << std::endl;
std::cout << "-- UHD Device " << i << std::endl;
std::cout << "--------------------------------------------------" << std::endl;
- std::cout << device_addrs[i].to_string() << std::endl << std::endl;
+ std::cout << device_addrs[i].to_pp_string() << std::endl << std::endl;
//uhd::device::make(device_addrs[i]); //test make
}