From 4d5df2376b204afb724684d0d864ce0d93fe83fb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 3 May 2010 01:20:11 -0700 Subject: Expanded the dboard id API to create dboard id types from strings and ints. And created utility functions to go between representations. Created to_pp_string for pretty print strings for dboard ids and device addrs. Minor changes to the various classes that call these utilities. --- host/include/uhd/types/device_addr.hpp | 10 +++--- host/include/uhd/usrp/dboard_id.hpp | 64 +++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 10 deletions(-) (limited to 'host/include') 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{ 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/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 #include +#include #include namespace uhd{ namespace usrp{ -typedef boost::uint16_t dboard_id_t; + class UHD_API dboard_id_t : boost::equality_comparable1{ + 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 -- cgit v1.2.3