MotionLib  1.0.0
SamBuCa motion library
Axis.cpp
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-11-09
21  * Author: Michal Mysior <mmysior> <michal.mysior@cern.ch>
22  *
23  */
24 
25 #include "Axis.hpp"
26 
27 #include <map>
28 
29 #include <logger/Logger.hpp>
30 
31 #include "Exception.hpp"
32 
33 using namespace logger;
34 
35 static const std::string s_loggerCat{"motionlib:axis"};
36 
37 namespace smc {
38 
39 using namespace units;
40 
41 Axis::Axis(const std::string &address) : DeviceBase{address} {}
42 
43 DeviceBase::DeviceType Axis::type() const
44 {
45  return DeviceBase::DeviceType::AXIS;
46 }
47 
48 std::future<void> Axis::pause() const
49 {
50  throw Exception(ErrorCode::NotSupported,
51  "pause operation not supported on " + uid());
52 }
53 
54 std::future<void> Axis::resume() const
55 {
56  throw Exception(ErrorCode::NotSupported,
57  "resume operation not supported on " + uid());
58 }
59 
60 std::future<void> Axis::setActualPosition(const units::Value &) const
61 {
62  throw Exception(ErrorCode::NotSupported,
63  "setActualPosition operation not supported on " + uid());
64 }
65 
66 std::future<void> Axis::takeReference(const std::chrono::milliseconds &) const
67 {
68  throw Exception(ErrorCode::NotSupported,
69  "takeReference operation not supported on " + uid());
70 }
71 
72 static const std::map<Axis::State, std::string> s_stateToString{
73  {Axis::State::IDLE, "idle"},
74  {Axis::State::RUNNING, "run"},
75  {Axis::State::ERROR, "error"},
76  {Axis::State::UNKNOWN, "unknown"}};
77 
78 const std::string &to_string(Axis::State state)
79 {
80  auto it = s_stateToString.find(state);
81  // if state found return that, else return unknown
82  return (it != s_stateToString.end()) ?
83  it->second :
84  s_stateToString.at(Axis::State::UNKNOWN);
85 }
86 
87 } /* namespace smc */
State
Axis State.
Definition: Axis.hpp:54
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