MotionLib  1.0.0
SamBuCa motion library
DeviceBase.hpp
1 /*
2  * Copyright (C) 2021 CERN
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  *
20  * Created on: 2021-10-27
21  * Author: Michal Mysior <mmysior> <michal.mysior@cern.ch>
22  *
23  */
24 
25 #ifndef DEVICE_BASE_HPP__
26 #define DEVICE_BASE_HPP__
27 
28 #include <future>
29 #include <memory>
30 #include <set>
31 #include <string>
32 
33 #include <ccut/Signal.hpp>
34 
35 #include "../Units.hpp"
36 #include "../util/serialize.hpp"
37 
38 namespace smc {
39 
51 enum class DeviceType
52 {
53  AXIS,
55  GPIO,
56  TRIGGER,
57  PLATFORM,
59  UNKNOWN = -1
60 };
61 
67 const std::string &to_string(DeviceType type);
68 
75 template<>
76 DeviceType from_string(const std::string &str);
77 
83 template<>
84 const std::set<DeviceType> &getEnumValues();
85 
86 typedef std::string DeviceId;
87 
88 class DeviceBase : public std::enable_shared_from_this<DeviceBase>
89 {
90 public:
92  typedef std::shared_ptr<DeviceBase> Shared;
93 
94  virtual ~DeviceBase() = default;
95 
96  virtual DeviceType type() const = 0;
97 
103  DeviceId uid() const;
104 
108  virtual std::future<std::set<std::string>> listConfig() const;
109 
115  virtual std::future<std::string> getConfig(const std::string &name) const;
116 
122  virtual std::future<void> setConfig(const std::string &name,
123  const std::string &value) const;
124 
134  virtual bool canConvert(const units::Value &value, units::unit_t unit) const;
135 
144  virtual bool convert(units::Value &value, units::unit_t unit) const;
145 
149  std::string toString() const;
150 
155  ccut::Signal<const DeviceBase::Shared &> updateSignal;
156 
157 protected:
163  DeviceBase(const std::string &uid);
164 
165  const std::string m_uid;
166 };
167 
170 } /* namespace smc */
171 
172 #endif /* DEVICE_BASE_HPP__ */
virtual std::future< std::set< std::string > > listConfig() const
list device configuration options
Definition: DeviceBase.cpp:91
virtual bool convert(units::Value &value, units::unit_t unit) const
Convert value in a manner specific to this device.
Definition: DeviceBase.cpp:86
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.
Definition: DeviceBase.cpp:81
virtual std::future< void > setConfig(const std::string &name, const std::string &value) const
set device configuration value
Definition: DeviceBase.cpp:104
ccut::Signal< const DeviceBase::Shared & > updateSignal
device update signal
Definition: DeviceBase.hpp:155
std::string toString() const
debug and logging operation
Definition: DeviceBase.cpp:111
virtual std::future< std::string > getConfig(const std::string &name) const
get device configuration value
Definition: DeviceBase.cpp:98
DeviceBase(const std::string &uid)
Construct a new ABaseDevice, linking pointer to platform object.
Definition: DeviceBase.cpp:74
DeviceId uid() const
Get the address of device.
Definition: DeviceBase.cpp:76
AxisPositionMonitor::State from_string(const std::string &str)
convert string to state
const std::set< AxisPositionMonitor::State > & getEnumValues()
Get devices types list (to be iterated)
const std::string & to_string(Axis::State state)
convert State to string
Definition: Axis.cpp:78
DeviceType
List of possible device types supported.
Definition: DeviceBase.hpp:52
@ AXIS_POSITION_MONITOR
device representing link with axis and position
@ UNKNOWN
unknown device type
@ PLATFORM
special device representing the platform itself
@ AXIS
actuator device
@ GPIO
gpio like device
@ TRIGGER
hardware/software trigger device
@ POSITION_SENSOR
position sensor device
main motion-lib namespace
Definition: Client.cpp:30