diff options
author | Josh Blum <josh@joshknows.com> | 2011-01-06 11:56:35 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-01-06 11:56:35 -0800 |
commit | fd9962af9ed6682117c3ab224548298907f59c49 (patch) | |
tree | 1043bb61e6613148d45b8c83cf65978384ab70d8 /host/include | |
parent | 6619a40b48029dae1ee1f46db81ba470debaffd2 (diff) | |
download | uhd-fd9962af9ed6682117c3ab224548298907f59c49.tar.gz uhd-fd9962af9ed6682117c3ab224548298907f59c49.tar.bz2 uhd-fd9962af9ed6682117c3ab224548298907f59c49.zip |
uhd: created sensors value, made lib/types and moved files
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/types/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/types/ranges.hpp | 1 | ||||
-rw-r--r-- | host/include/uhd/types/sensors.hpp | 118 |
3 files changed, 119 insertions, 1 deletions
diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index 316a8e14b..51be164aa 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES metadata.hpp otw_type.hpp ranges.hpp + sensors.hpp serial.hpp stream_cmd.hpp time_spec.hpp diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp index 253536a42..f0d0e1c0b 100644 --- a/host/include/uhd/types/ranges.hpp +++ b/host/include/uhd/types/ranges.hpp @@ -22,7 +22,6 @@ #include <uhd/utils/pimpl.hpp> #include <string> #include <vector> -#include <string> namespace uhd{ diff --git a/host/include/uhd/types/sensors.hpp b/host/include/uhd/types/sensors.hpp new file mode 100644 index 000000000..d400b8944 --- /dev/null +++ b/host/include/uhd/types/sensors.hpp @@ -0,0 +1,118 @@ +// +// Copyright 2010-2011 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_UHD_TYPES_SENSORS_HPP +#define INCLUDED_UHD_TYPES_SENSORS_HPP + +#include <uhd/config.hpp> +#include <string> + +namespace uhd{ + + /*! + * A sensor value stores a sensor reading as a string with unit and data type. + * The sensor value class can be used in the following way: + * + * sensor_value_t ref_lock_sensor("Reference", my_lock, "unlocked", "locked"); + * std::cout << ref_lock_sensor.to_pp_string() << std::endl; + * //prints Reference: locked + * + * sensor_value_t temp_sensor("Temperature", my_temp, "C"); + * std::cout << temp_sensor.to_pp_string() << std::endl; + * //prints Temperature: 38.5 C + */ + 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 + * \param value the value true or false + * \param ufalse the unit string when value is false + * \param utrue the unit string when value is true + */ + sensor_value_t( + const std::string &name, + bool value, + const std::string &ufalse, + const std::string &utrue + ); + + /*! + * Create a sensor value from an integer. + * \param name the name of the sensor + * \param value the signed integer value + * \param unit the associated unit type + * \param formatter the formatter string + */ + sensor_value_t( + const std::string &name, + int_type value, + const std::string &unit, + const std::string &formatter = "%d" + ); + + /*! + * Create a sensor value from a real number. + * \param name the name of the sensor + * \param value the real number value + * \param unit the associated unit type + * \param formatter the formatter string + */ + sensor_value_t( + const std::string &name, + real_type value, + const std::string &unit, + const std::string &formatter = "%f" + ); + + //! The name of the sensor value + const std::string name; + + /*! + * The sensor value as a string. + * For integer and real number types, this will be the output of the formatter. + * For boolean types, the value will be the string literal "true" or "false". + */ + const std::string value; + + /*! + * The sensor value's unit type. + * For boolean types, this will be the one of the two units + * depending upon the value of the boolean true or false. + */ + const std::string unit; + + //! The data type of the value + const enum{ + BOOLEAN = 'b', + INTEGER = 'i', + REALNUM = 'r' + } type; + + //! Convert this sensor value into a printable string + std::string to_pp_string(void) const; + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_SENSORS_HPP */ |