summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-07 10:03:46 -0800
committerJosh Blum <josh@joshknows.com>2011-01-07 10:03:46 -0800
commitf879a50989a35a2ba4886630164d71353a560c2e (patch)
tree7d9edd5c5e810e8f6e426f75ba973a99c464d467 /host
parent771b5cebda250f2a6a65aa7788e9051c94974c2b (diff)
downloaduhd-f879a50989a35a2ba4886630164d71353a560c2e.tar.gz
uhd-f879a50989a35a2ba4886630164d71353a560c2e.tar.bz2
uhd-f879a50989a35a2ba4886630164d71353a560c2e.zip
uhd: create sensor value from string
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/types/sensors.hpp15
-rw-r--r--host/lib/types/sensors.cpp12
2 files changed, 26 insertions, 1 deletions
diff --git a/host/include/uhd/types/sensors.hpp b/host/include/uhd/types/sensors.hpp
index e1a21e4c9..6f003bb40 100644
--- a/host/include/uhd/types/sensors.hpp
+++ b/host/include/uhd/types/sensors.hpp
@@ -85,6 +85,18 @@ namespace uhd{
const std::string &formatter = "%f"
);
+ /*!
+ * Create a sensor value from a string.
+ * \param name the name of the sensor
+ * \param value the real number value
+ * \param unit the associated unit type
+ */
+ sensor_value_t(
+ const std::string &name,
+ const std::string &value,
+ const std::string &unit
+ );
+
//! The name of the sensor value
const std::string name;
@@ -106,7 +118,8 @@ namespace uhd{
const enum{
BOOLEAN = 'b',
INTEGER = 'i',
- REALNUM = 'r'
+ REALNUM = 'r',
+ STRING = 's'
} type;
//! Convert this sensor value into a printable string
diff --git a/host/lib/types/sensors.cpp b/host/lib/types/sensors.cpp
index 497f4bfd5..2bff136a4 100644
--- a/host/lib/types/sensors.cpp
+++ b/host/lib/types/sensors.cpp
@@ -57,12 +57,24 @@ sensor_value_t::sensor_value_t(
/* NOP */
}
+sensor_value_t::sensor_value_t(
+ const std::string &name,
+ const std::string &value,
+ const std::string &unit
+):
+ name(name), value(value),
+ unit(unit), type(STRING)
+{
+ /* NOP */
+}
+
std::string sensor_value_t::to_pp_string(void) const{
switch(type){
case BOOLEAN:
return str(boost::format("%s: %s") % name % unit);
case INTEGER:
case REALNUM:
+ case STRING:
return str(boost::format("%s: %s %s") % name % value % unit);
}
UHD_THROW_INVALID_CODE_PATH();