summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-11 21:52:13 -0800
committerJosh Blum <josh@joshknows.com>2011-02-11 21:52:13 -0800
commit4613f454c781d258d6d9b210ff1b9043a2125981 (patch)
treeb69eab37b2099a5d699ac6b480673134d29e7fda /host
parent9de6f36bc5d9f5d9d602547166c92b53b278b428 (diff)
downloaduhd-4613f454c781d258d6d9b210ff1b9043a2125981.tar.gz
uhd-4613f454c781d258d6d9b210ff1b9043a2125981.tar.bz2
uhd-4613f454c781d258d6d9b210ff1b9043a2125981.zip
uhd: added to_<type> calls to sensors to make it easy
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/types/sensors.hpp19
-rw-r--r--host/include/uhd/usrp/multi_usrp.hpp7
-rw-r--r--host/lib/types/sensors.cpp17
3 files changed, 29 insertions, 14 deletions
diff --git a/host/include/uhd/types/sensors.hpp b/host/include/uhd/types/sensors.hpp
index 6f003bb40..b6215367f 100644
--- a/host/include/uhd/types/sensors.hpp
+++ b/host/include/uhd/types/sensors.hpp
@@ -37,12 +37,6 @@ namespace uhd{
*/
struct UHD_API sensor_value_t{
- //! typedef for the signed integer type
- typedef signed int_type;
-
- //! typedef for the real number type
- typedef double real_type;
-
/*!
* Create a sensor value from a boolean.
* \param name the name of the sensor
@@ -66,7 +60,7 @@ namespace uhd{
*/
sensor_value_t(
const std::string &name,
- int_type value,
+ signed value,
const std::string &unit,
const std::string &formatter = "%d"
);
@@ -80,7 +74,7 @@ namespace uhd{
*/
sensor_value_t(
const std::string &name,
- real_type value,
+ double value,
const std::string &unit,
const std::string &formatter = "%f"
);
@@ -97,6 +91,15 @@ namespace uhd{
const std::string &unit
);
+ //! convert the sensor value to a boolean
+ bool to_bool(void) const;
+
+ //! convert the sensor value to an integer
+ signed to_int(void) const;
+
+ //! convert the sensor value to real number
+ double to_real(void) const;
+
//! The name of the sensor value
const std::string name;
diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp
index da52e6dce..3c8dd5fac 100644
--- a/host/include/uhd/usrp/multi_usrp.hpp
+++ b/host/include/uhd/usrp/multi_usrp.hpp
@@ -28,7 +28,6 @@
#include <uhd/types/sensors.hpp>
#include <uhd/usrp/subdev_spec.hpp>
#include <uhd/usrp/dboard_iface.hpp>
-#include <boost/lexical_cast.hpp> //needed until deprecated routines removed
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <vector>
@@ -395,7 +394,7 @@ public:
* \return true for locked
*/
UHD_DEPRECATED bool get_rx_lo_locked(size_t chan = 0){
- return this->get_rx_sensor("lo_locked", chan).value == "true";
+ return this->get_rx_sensor("lo_locked", chan).to_bool();
}
/*!
@@ -419,7 +418,7 @@ public:
* \throw exception if RSSI readback not supported
*/
UHD_DEPRECATED double read_rssi(size_t chan = 0){
- return boost::lexical_cast<double>(this->get_rx_sensor("rssi", chan).value);
+ return this->get_rx_sensor("rssi", chan).to_real();
}
/*!
@@ -593,7 +592,7 @@ public:
* \return true for locked
*/
UHD_DEPRECATED bool get_tx_lo_locked(size_t chan = 0){
- return this->get_tx_sensor("lo_locked", chan).value == "true";
+ return this->get_tx_sensor("lo_locked", chan).to_bool();
}
/*!
diff --git a/host/lib/types/sensors.cpp b/host/lib/types/sensors.cpp
index 2bff136a4..5f7115d70 100644
--- a/host/lib/types/sensors.cpp
+++ b/host/lib/types/sensors.cpp
@@ -17,6 +17,7 @@
#include <uhd/types/sensors.hpp>
#include <uhd/utils/exception.hpp>
+#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
using namespace uhd;
@@ -35,7 +36,7 @@ sensor_value_t::sensor_value_t(
sensor_value_t::sensor_value_t(
const std::string &name,
- int_type value,
+ signed value,
const std::string &unit,
const std::string &formatter
):
@@ -47,7 +48,7 @@ sensor_value_t::sensor_value_t(
sensor_value_t::sensor_value_t(
const std::string &name,
- real_type value,
+ double value,
const std::string &unit,
const std::string &formatter
):
@@ -79,3 +80,15 @@ std::string sensor_value_t::to_pp_string(void) const{
}
UHD_THROW_INVALID_CODE_PATH();
}
+
+bool sensor_value_t::to_bool(void) const{
+ return value == "true";
+}
+
+signed sensor_value_t::to_int(void) const{
+ return boost::lexical_cast<signed>(value);
+}
+
+double sensor_value_t::to_real(void) const{
+ return boost::lexical_cast<double>(value);
+}