MotionLib  1.0.0
SamBuCa motion library
AxisPositionMonitor.cpp
1 /*
2 ** Copyright (C) 2023 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: 2023-07-17T17:41:57
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #include "AxisPositionMonitor.hpp"
25 
26 #include <map>
27 #include <set>
28 
29 #include <ccut/utils.hpp>
30 
31 namespace smc {
32 
33 using namespace units;
34 
35 static const std::map<AxisPositionMonitor::State, std::string> s_stateToStr{
36  {AxisPositionMonitor::State::DISABLED, "disabled"},
37  {AxisPositionMonitor::State::ENABLED, "enabled"},
38  {AxisPositionMonitor::State::UNKNOWN, "unknown"},
39  {AxisPositionMonitor::State::TRIGGERED, "triggered"}};
40 static const std::map<std::string, AxisPositionMonitor::State> s_stateFromStr{
41  ccut::flip(s_stateToStr)};
42 static const std::set<AxisPositionMonitor::State> s_stateKeys{
43  ccut::keys(s_stateToStr)};
44 
46  const std::string &address,
47  const std::shared_ptr<Axis> &axis,
48  const std::shared_ptr<PositionSensor> &position) :
49  DeviceBase{address},
50  m_axis{axis},
51  m_position{position}
52 {}
53 
55 {
56  return DeviceBase::DeviceType::AXIS_POSITION_MONITOR;
57 }
58 
59 template<>
60 const std::set<AxisPositionMonitor::State> &getEnumValues()
61 {
62  return s_stateKeys;
63 }
64 
65 const std::string &to_string(AxisPositionMonitor::State state)
66 {
67  decltype(s_stateToStr)::const_iterator it = s_stateToStr.find(state);
68  return (it != s_stateToStr.cend()) ?
69  it->second :
70  s_stateToStr.at(AxisPositionMonitor::State::UNKNOWN);
71 }
72 
73 template<>
74 AxisPositionMonitor::State from_string(const std::string &str)
75 {
76  decltype(s_stateFromStr)::const_iterator it = s_stateFromStr.find(str);
77  return (it != s_stateFromStr.cend()) ? it->second :
78  AxisPositionMonitor::State::UNKNOWN;
79 }
80 
81 } /* namespace smc */
DeviceType type() const override
Get device type.
AxisPositionMonitor(const std::string &address, const std::shared_ptr< Axis > &axis, const std::shared_ptr< PositionSensor > &position)
Construct a new AxisPositionMonitor Device.
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
main motion-lib namespace
Definition: Client.cpp:30