25 #include "DeviceBase.hpp"
31 #include <ccut/async.hpp>
32 #include <ccut/utils.hpp>
34 #include "util/serialize.hpp"
38 static const std::string s_empty;
39 static const std::map<DeviceType, std::string> s_deviceTypesToStr{
47 static const std::map<std::string, DeviceType> s_deviceTypesFromStr{
48 ccut::flip(s_deviceTypesToStr)};
49 static const std::set<DeviceType> s_deviceTypesKeys{
50 ccut::keys(s_deviceTypesToStr)};
54 std::map<DeviceType, std::string>::const_iterator it =
55 s_deviceTypesToStr.find(type);
56 return (it != s_deviceTypesToStr.end()) ? it->second : s_empty;
60 DeviceType from_string<DeviceType>(
const std::string &str)
62 std::map<std::string, DeviceType>::const_iterator it =
63 s_deviceTypesFromStr.find(str);
64 return (it != s_deviceTypesFromStr.end()) ? it->second :
69 const std::set<DeviceType> &getEnumValues<DeviceType>()
71 return s_deviceTypesKeys;
83 return value.canConvert(unit);
88 return value.convert(unit);
93 std::promise<std::set<std::string>> prom;
94 prom.set_value(std::set<std::string>());
95 return prom.get_future();
100 return ccut::make_future_error<std::string>(
Exception(
101 ErrorCode::InvalidArguments,
"no such config value: " + name));
105 const std::string &)
const
107 return ccut::make_future_error(
Exception(ErrorCode::InvalidArguments,
108 "no such config value: " + name));
113 std::stringstream ss;
114 ss <<
"Device{" <<
to_string(type()) <<
", " << m_uid <<
"}";
virtual std::future< std::set< std::string > > listConfig() const
list device configuration options
virtual bool convert(units::Value &value, units::unit_t unit) const
Convert value in a manner specific to this device.
virtual bool canConvert(const units::Value &value, units::unit_t unit) const
Check if unit conversion is possible in a manner specific to this device.
virtual std::future< void > setConfig(const std::string &name, const std::string &value) const
set device configuration value
std::string toString() const
debug and logging operation
virtual std::future< std::string > getConfig(const std::string &name) const
get device configuration value
DeviceBase(const std::string &uid)
Construct a new ABaseDevice, linking pointer to platform object.
DeviceId uid() const
Get the address of device.
Exception thrown by MotionController in case of issues with command.
const std::string & to_string(Axis::State state)
convert State to string
DeviceType
List of possible device types supported.
@ AXIS_POSITION_MONITOR
device representing link with axis and position
@ UNKNOWN
unknown device type
@ PLATFORM
special device representing the platform itself
@ TRIGGER
hardware/software trigger device
@ POSITION_SENSOR
position sensor device
main motion-lib namespace