diff options
| author | Brent Stapleton <brent.stapleton@ettus.com> | 2018-05-04 16:45:08 -0700 | 
|---|---|---|
| committer | Martin Braun <martin.braun@ettus.com> | 2018-05-14 18:02:45 -0700 | 
| commit | 388ebd00f618e75941c3f2045f448c10e514dcd4 (patch) | |
| tree | e90fdeabf9ac450d2476cef031287429e6745ecc /host/lib | |
| parent | e942181f600b6b35f2200244b9899e23b20cf6cf (diff) | |
| download | uhd-388ebd00f618e75941c3f2045f448c10e514dcd4.tar.gz uhd-388ebd00f618e75941c3f2045f448c10e514dcd4.tar.bz2 uhd-388ebd00f618e75941c3f2045f448c10e514dcd4.zip  | |
types: convert sensor_value_t to a map
Diffstat (limited to 'host/lib')
| -rw-r--r-- | host/lib/types/sensors.cpp | 27 | 
1 files changed, 27 insertions, 0 deletions
diff --git a/host/lib/types/sensors.cpp b/host/lib/types/sensors.cpp index e9f7ab506..982e02f05 100644 --- a/host/lib/types/sensors.cpp +++ b/host/lib/types/sensors.cpp @@ -76,6 +76,24 @@ static sensor_value_t::data_type_t _string_to_type(      }  } +static std::string _type_to_string( +    const sensor_value_t::data_type_t &type +) { +    if (type == sensor_value_t::STRING) { +        return "STRING"; +    } else if (type == sensor_value_t::REALNUM) { +        return "REALNUM"; +    } else if (type == sensor_value_t::INTEGER) { +        return "INTEGER"; +    } else if (type == sensor_value_t::BOOLEAN) { +        return "BOOLEAN"; +    } else { +        throw uhd::value_error( +            std::string("Invalid raw sensor value type.") +        ); +    } +} +  sensor_value_t::sensor_value_t(      const std::map<std::string, std::string> &sensor_dict  ): @@ -139,6 +157,15 @@ double sensor_value_t::to_real(void) const{      return std::stod(value);  } +sensor_value_t::sensor_map_t sensor_value_t::to_map(void) const{ +    sensor_map_t ret_map; +    ret_map["name"] = name; +    ret_map["value"] = value; +    ret_map["unit"] = unit; +    ret_map["type"] = _type_to_string(type); +    return ret_map; +} +  sensor_value_t& sensor_value_t::operator=(const sensor_value_t& rhs)  {      this->name = rhs.name;  | 
