DeviceConfig.cpp
Go to the documentation of this file.
1 #include "DeviceConfig.h"
2 
4 {
5  DeviceConfig::DeviceConfig(std::string type, std::string name) : DeviceConfigBase(type, name)
6  {
7  }
8 
9  DeviceConfig::DeviceConfig(std::string type,
10  std::string name,
11  std::shared_ptr<DeviceConfigBase> profile) :
12  DeviceConfigBase(type, name, profile)
13  {
14  }
15 
16  DeviceConfigBase::DeviceConfigBase(std::string type, std::string name) : type(type), name(name)
17  {
18  }
19 
21  std::string name,
22  std::shared_ptr<DeviceConfigBase> profile) :
23  ControllerConfig(*profile), type(type), name(name)
24  {
25  this->items = profile->items;
26  }
27 
29  DeviceConfig::getSlaveConfig(const std::uint32_t vendorID,
30  const std::uint32_t productCode,
31  const std::uint32_t serialNumber)
32  {
33  for (auto& slaveConfig : slaveConfigs)
34  {
35  auto id = slaveConfig->getIdentifier();
36  if (id.getVendorID() == vendorID && id.getProductCode() == productCode &&
37  id.getSerialNumber() == serialNumber)
38  {
39  return *slaveConfig;
40  }
41  }
42  std::stringstream ss;
43  ss << "Slave Config with vendorID: " << vendorID << " , productCode: " << productCode
44  << " , serialNumber: " << serialNumber << " not found";
45  throw ConfigElementNotFoundError(ss.str());
46  }
47 
49  DeviceConfig::getSlaveConfig(const std::string type, const std::string name)
50  {
51  for (auto& slaveConfig : slaveConfigs)
52  {
53  if (slaveConfig->getType() == type)
54  {
55  if (name == "" || slaveConfig->getName() == name)
56  {
57  return *slaveConfig;
58  }
59  }
60  }
61  throw ConfigElementNotFoundError("Config Element not found: Type: " + type + ", name: " + name);
62  }
63 
66  {
67  if (slaveConfigs.size() == 1)
68  {
69  return **slaveConfigs.begin();
70  }
72  "There are more than one SlaveConfigs in this DeviceConfig");
73  }
74 
76  DeviceConfig::getSubdeviceConfig(const std::string& subDeviceName)
77  {
78  auto it = subDeviceConfigs.find(subDeviceName);
79  if (it != subDeviceConfigs.end())
80  {
81  return *it->second;
82  }
83  throw ConfigElementNotFoundError("SubDevice with name: " + subDeviceName);
84  }
85 
86  std::list<std::reference_wrapper<DeviceConfigBase>>
87  DeviceConfig::getSubDeviceConfigsWithType(const std::string subDeviceType)
88  {
89  std::list<std::reference_wrapper<DeviceConfigBase>> list;
90  for (auto& subDevice : subDeviceConfigs)
91  {
92  if (subDevice.second->getType() == subDeviceType)
93  {
94  list.push_back(*subDevice.second);
95  }
96  }
97  return list;
98  }
99 
100 
101  std::string
103  {
104  return type;
105  }
106 
107  std::string
109  {
110  return name;
111  }
112 
113  bool
114  DeviceConfig::checkAllItemsRead(std::vector<std::string>& errors) const
115  {
116  bool succ = true;
117  for (auto& slave : slaveConfigs)
118  {
119  succ &= slave->checkAllItemsRead(errors);
120  }
121  for (auto& controller : controllerConfigs)
122  {
123  succ &= controller.second->checkAllItemsRead(errors);
124  }
125  for (auto& sub : subDeviceConfigs)
126  {
127  succ &= sub.second->checkAllItemsRead(errors);
128  }
129  succ &= Config::checkAllItemsRead(errors);
130  return succ;
131  }
132 
133  void
134  DeviceConfig::print(std::stringstream& s, int indention) const
135  {
136  for (int i = 0; i < indention; i++)
137  {
138  s << "\t";
139  }
140  s << "Device type=" << getType() << " name=" << getName() << ":" << std::endl;
141 
142  for (auto& slave : slaveConfigs)
143  {
144  slave->print(s, indention + 1);
145  }
146 
147  for (auto& controller : controllerConfigs)
148  {
149  for (int i = 0; i < indention + 1; i++)
150  {
151  s << "\t";
152  }
153  s << "Controller: " << controller.first << ":" << std::endl;
154  controller.second->print(s, indention + 2);
155  }
156 
157  for (auto& sub : subDeviceConfigs)
158  {
159  sub.second->print(s, indention + 1);
160  }
161 
162  for (int i = 0; i < indention + 1; i++)
163  {
164  s << "\t";
165  }
166  s << "Config:" << std::endl;
167  Config::print(s, indention + 2);
168  }
169 
170  void
171  DeviceConfig::addSlaveConfig(std::shared_ptr<SlaveConfig> slaveConfig)
172  {
173  slaveConfigs.push_back(slaveConfig);
174  }
175 
176  void
177  DeviceConfig::addSubDeviceConfig(const std::string name,
178  std::shared_ptr<DeviceConfigBase> subDeviceConfig)
179  {
180  subDeviceConfigs[name] = subDeviceConfig;
181  }
182 
183  void
185  {
187  for (auto& i : subDeviceConfigs)
188  {
189  i.second->onParsingFinished();
190  }
191  for (auto& i : slaveConfigs)
192  {
193  i->onParsingFinished();
194  }
195  for (auto& i : controllerConfigs)
196  {
197  i.second->onParsingFinished();
198  }
199  }
200 
201  void
202  DeviceConfigBase::print(std::stringstream& s, int indention) const
203  {
204  for (int i = 0; i < indention; i++)
205  {
206  s << "\t";
207  }
208  s << "SubDevice name=" << getName() << ":" << std::endl;
209 
210  for (auto& controller : controllerConfigs)
211  {
212  for (int i = 0; i < indention + 1; i++)
213  {
214  s << "\t";
215  }
216  s << "Controller: " << controller.first << ":" << std::endl;
217  controller.second->print(s, indention + 2);
218  }
219 
220  for (int i = 0; i < indention + 1; i++)
221  {
222  s << "\t";
223  }
224  s << "Config:" << std::endl;
225  Config::print(s, indention + 2);
226  }
227 
228 } // namespace armarx::control::hardware_config
armarx::control::hardware_config::DeviceConfig::checkAllItemsRead
bool checkAllItemsRead(std::vector< std::string > &errors) const override
This method is called once the device has read the configuration data it needs.
Definition: DeviceConfig.cpp:114
armarx::control::hardware_config::ConfigElementNotFoundError
The ConfigElementNotFoundError class represents an error that is thrown when trying to get a config v...
Definition: Errors.h:24
armarx::control::hardware_config::DeviceConfig::onParsingFinished
void onParsingFinished() override
This method is called when the config is completely read form the HardwareConfig file.
Definition: DeviceConfig.cpp:184
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::control::hardware_config::DeviceConfigBase::DeviceConfig
friend class DeviceConfig
Definition: DeviceConfig.h:20
armarx::control::hardware_config
Definition: Config.cpp:3
armarx::control::hardware_config::DeviceConfigBase::DeviceConfigBase
DeviceConfigBase(std::string type, std::string name)
Definition: DeviceConfig.cpp:16
armarx::control::hardware_config::DeviceConfig::getSubDeviceConfigsWithType
std::list< std::reference_wrapper< DeviceConfigBase > > getSubDeviceConfigsWithType(const std::string subDeviceType)
Definition: DeviceConfig.cpp:87
controller
Definition: AddOperation.h:39
armarx::control::hardware_config::DeviceConfig::print
void print(std::stringstream &s, int indention) const override
Print this configuration.
Definition: DeviceConfig.cpp:134
armarx::control::hardware_config::DeviceConfigBase::getName
std::string getName() const
Definition: DeviceConfig.cpp:108
armarx::control::hardware_config::DeviceConfigBase
A base class that does not have Subdevices or Slaves but can be used for Subdevices or DeviceProfiles...
Definition: DeviceConfig.h:17
armarx::control::hardware_config::DeviceConfigBase::getType
std::string getType() const
Definition: DeviceConfig.cpp:102
armarx::control::hardware_config::DeviceConfig::getOnlySlaveConfig
SlaveConfig & getOnlySlaveConfig()
Definition: DeviceConfig.cpp:65
armarx::control::hardware_config::Config::onParsingFinished
virtual void onParsingFinished()
This method is called when the config is completely read form the HardwareConfig file.
Definition: Config.cpp:316
DeviceConfig.h
armarx::control::hardware_config::SlaveConfig::getIdentifier
SlaveIdentifierConfig & getIdentifier()
Definition: SlaveConfig.cpp:23
armarx::control::hardware_config::DeviceConfig::getSlaveConfig
SlaveConfig & getSlaveConfig(const std::uint32_t vendorID, const std::uint32_t productCode, const std::uint32_t serialNumber)
Definition: DeviceConfig.cpp:29
armarx::control::hardware_config::DeviceConfigBase::print
void print(std::stringstream &s, int indention) const override
Print this configuration.
Definition: DeviceConfig.cpp:202
armarx::control::hardware_config::Config::items
std::map< std::string, ConfigItemWithMetadata > items
Definition: Config.h:250
sub
Point sub(const Point &x, const Point &y)
Definition: point.hpp:43
armarx::control::hardware_config::SlaveConfig
Definition: SlaveConfig.h:27
armarx::control::hardware_config::ControllerConfig::controllerConfigs
std::map< std::string, std::shared_ptr< Config > > controllerConfigs
Definition: Config.h:372
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::control::hardware_config::DeviceConfig::getSubdeviceConfig
DeviceConfigBase & getSubdeviceConfig(const std::string &subDeviceName)
Definition: DeviceConfig.cpp:76
armarx::control::hardware_config::ControllerConfig
Config with additional Config objects for controllers.
Definition: Config.h:349
armarx::control::hardware_config::Config::checkAllItemsRead
virtual bool checkAllItemsRead(std::vector< std::string > &errors) const
This method is called once the device has read the configuration data it needs.
Definition: Config.cpp:76
armarx::control::hardware_config::Config::print
virtual void print(std::stringstream &s, int indention) const
Print this configuration.
Definition: Config.cpp:121