YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeBattery_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Thu May 22 11:32:31 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(FakeBatteryParamsCOMPONENT, "yarp.device.FakeBattery")
20}
21
22
26
27
28std::vector<std::string> FakeBattery_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("period");
32 params.push_back("charge");
33 params.push_back("voltage");
34 params.push_back("current");
35 params.push_back("temperature");
36 params.push_back("info");
37 params.push_back("rpc_port_name");
38 return params;
39}
40
41
42bool FakeBattery_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
43{
44 if (paramName =="period")
45 {
46 paramValue = std::to_string(m_period);
47 return true;
48 }
49 if (paramName =="charge")
50 {
51 paramValue = std::to_string(m_charge);
52 return true;
53 }
54 if (paramName =="voltage")
55 {
56 paramValue = std::to_string(m_voltage);
57 return true;
58 }
59 if (paramName =="current")
60 {
61 paramValue = std::to_string(m_current);
62 return true;
63 }
64 if (paramName =="temperature")
65 {
66 paramValue = std::to_string(m_temperature);
67 return true;
68 }
69 if (paramName =="info")
70 {
71 paramValue = m_info;
72 return true;
73 }
74 if (paramName =="rpc_port_name")
75 {
76 paramValue = m_rpc_port_name;
77 return true;
78 }
79
80 yError() <<"parameter '" << paramName << "' was not found";
81 return false;
82
83}
84
85
87{
88 //This is a sub-optimal solution.
89 //Ideally getConfiguration() should return all parameters but it is currently
90 //returning only user provided parameters (excluding default values)
91 //This behaviour will be fixed in the near future.
92 std::string s_cfg = m_provided_configuration;
93 return s_cfg;
94}
95
97{
98 //Check for --help option
99 if (config.check("help"))
100 {
101 yCInfo(FakeBatteryParamsCOMPONENT) << getDocumentationOfDeviceParams();
102 }
103
106 //Parser of parameter period
107 {
108 if (config.check("period"))
109 {
110 m_period = config.find("period").asFloat64();
111 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'period' using value:" << m_period;
112 }
113 else
114 {
115 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period;
116 }
117 prop_check.unput("period");
118 }
119
120 //Parser of parameter charge
121 {
122 if (config.check("charge"))
123 {
124 m_charge = config.find("charge").asFloat64();
125 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'charge' using value:" << m_charge;
126 }
127 else
128 {
129 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'charge' using DEFAULT value:" << m_charge;
130 }
131 prop_check.unput("charge");
132 }
133
134 //Parser of parameter voltage
135 {
136 if (config.check("voltage"))
137 {
138 m_voltage = config.find("voltage").asFloat64();
139 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'voltage' using value:" << m_voltage;
140 }
141 else
142 {
143 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'voltage' using DEFAULT value:" << m_voltage;
144 }
145 prop_check.unput("voltage");
146 }
147
148 //Parser of parameter current
149 {
150 if (config.check("current"))
151 {
152 m_current = config.find("current").asFloat64();
153 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'current' using value:" << m_current;
154 }
155 else
156 {
157 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'current' using DEFAULT value:" << m_current;
158 }
159 prop_check.unput("current");
160 }
161
162 //Parser of parameter temperature
163 {
164 if (config.check("temperature"))
165 {
166 m_temperature = config.find("temperature").asFloat64();
167 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'temperature' using value:" << m_temperature;
168 }
169 else
170 {
171 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'temperature' using DEFAULT value:" << m_temperature;
172 }
173 prop_check.unput("temperature");
174 }
175
176 //Parser of parameter info
177 {
178 if (config.check("info"))
179 {
180 m_info = config.find("info").asString();
181 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'info' using value:" << m_info;
182 }
183 else
184 {
185 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'info' using DEFAULT value:" << m_info;
186 }
187 prop_check.unput("info");
188 }
189
190 //Parser of parameter rpc_port_name
191 {
192 if (config.check("rpc_port_name"))
193 {
194 m_rpc_port_name = config.find("rpc_port_name").asString();
195 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'rpc_port_name' using value:" << m_rpc_port_name;
196 }
197 else
198 {
199 yCInfo(FakeBatteryParamsCOMPONENT) << "Parameter 'rpc_port_name' using DEFAULT value:" << m_rpc_port_name;
200 }
201 prop_check.unput("rpc_port_name");
202 }
203
204 /*
205 //This code check if the user set some parameter which are not check by the parser
206 //If the parser is set in strict mode, this will generate an error
207 if (prop_check.size() > 0)
208 {
209 bool extra_params_found = false;
210 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
211 {
212 if (m_parser_is_strict)
213 {
214 yCError(FakeBatteryParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
215 extra_params_found = true;
216 }
217 else
218 {
219 yCWarning(FakeBatteryParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
220 }
221 }
222
223 if (m_parser_is_strict && extra_params_found)
224 {
225 return false;
226 }
227 }
228 */
229 return true;
230}
231
232
234{
235 std::string doc;
236 doc = doc + std::string("\n=============================================\n");
237 doc = doc + std::string("This is the help for device: FakeBattery\n");
238 doc = doc + std::string("\n");
239 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
240 doc = doc + std::string("'period': thread period\n");
241 doc = doc + std::string("'charge': Initial charge\n");
242 doc = doc + std::string("'voltage': Initial voltage\n");
243 doc = doc + std::string("'current': Initial current\n");
244 doc = doc + std::string("'temperature': Initial temperature\n");
245 doc = doc + std::string("'info': Initial battery information\n");
246 doc = doc + std::string("'rpc_port_name': Full rpc port name\n");
247 doc = doc + std::string("\n");
248 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
249 doc = doc + " yarpdev --device fakeBattery --period 0.02 --charge 50.0 --voltage 30.0 --current 3.0 --temperature 20.0 --info Fake battery system v2.0 --rpc_port_name /fakeBattery/rpc\n";
250 doc = doc + std::string("Using only mandatory params:\n");
251 doc = doc + " yarpdev --device fakeBattery\n";
252 doc = doc + std::string("=============================================\n\n"); return doc;
253}
#define yError(...)
Definition Log.h:361
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getConfiguration() const override
Return the configuration of the device.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)