UHD  003.004.003-26-stable
Public Types | Public Member Functions | Public Attributes
uhd::sensor_value_t Struct Reference

#include <sensors.hpp>

List of all members.

Public Types

enum  data_type_t { BOOLEAN = 'b', INTEGER = 'i', REALNUM = 'r', STRING = 's' }
 Enumeration of possible data types in a sensor. More...

Public Member Functions

 sensor_value_t (const std::string &name, bool value, const std::string &utrue, const std::string &ufalse)
 sensor_value_t (const std::string &name, signed value, const std::string &unit, const std::string &formatter="%d")
 sensor_value_t (const std::string &name, double value, const std::string &unit, const std::string &formatter="%f")
 sensor_value_t (const std::string &name, const std::string &value, const std::string &unit)
bool to_bool (void) const
 convert the sensor value to a boolean
signed to_int (void) const
 convert the sensor value to an integer
double to_real (void) const
 convert the sensor value to real number
std::string to_pp_string (void) const
 Convert this sensor value into a printable string.

Public Attributes

const std::string name
 The name of the sensor value.
const std::string value
const std::string unit
const data_type_t type
 The data type of the value.

Detailed Description

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


Member Enumeration Documentation

Enumeration of possible data types in a sensor.

Enumerator:
BOOLEAN 
INTEGER 
REALNUM 
STRING 

Constructor & Destructor Documentation

uhd::sensor_value_t::sensor_value_t ( const std::string name,
bool  value,
const std::string utrue,
const std::string ufalse 
)

Create a sensor value from a boolean.

Parameters:
namethe name of the sensor
valuethe value true or false
utruethe unit string when value is true
ufalsethe unit string when value is false
uhd::sensor_value_t::sensor_value_t ( const std::string name,
signed  value,
const std::string unit,
const std::string formatter = "%d" 
)

Create a sensor value from an integer.

Parameters:
namethe name of the sensor
valuethe signed integer value
unitthe associated unit type
formatterthe formatter string
uhd::sensor_value_t::sensor_value_t ( const std::string name,
double  value,
const std::string unit,
const std::string formatter = "%f" 
)

Create a sensor value from a real number.

Parameters:
namethe name of the sensor
valuethe real number value
unitthe associated unit type
formatterthe formatter string
uhd::sensor_value_t::sensor_value_t ( const std::string name,
const std::string value,
const std::string unit 
)

Create a sensor value from a string.

Parameters:
namethe name of the sensor
valuethe real number value
unitthe associated unit type

Member Function Documentation

bool uhd::sensor_value_t::to_bool ( void  ) const

convert the sensor value to a boolean

signed uhd::sensor_value_t::to_int ( void  ) const

convert the sensor value to an integer

std::string uhd::sensor_value_t::to_pp_string ( void  ) const

Convert this sensor value into a printable string.

double uhd::sensor_value_t::to_real ( void  ) const

convert the sensor value to real number


Member Data Documentation

The name of the sensor value.

The data type of the 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.

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".


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines