Skip to content

Commit c3b0ee6

Browse files
committed
added ParamParser to devices: FrameTransformGet_nws_yarp
added ParamParser to devices: FrameTransformGet_nwc_yarp added ParamParser to devices: FrameTransformSet_nws_yarp added ParamParser to devices: FrameTransformSet_nwc_yarp
1 parent aa77f8b commit c3b0ee6

24 files changed

+1203
-61
lines changed

src/devices/networkWrappers/frameTransformGet_nwc_yarp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ yarp_prepare_plugin(frameTransformGet_nwc_yarp
1010
EXTRA_CONFIG
1111
WRAPPER=frameTransformGet_nws_yarp
1212
DEFAULT ON
13+
GENERATE_PARSER
1314
)
1415

1516
if(NOT SKIP_frameTransformGet_nwc_yarp)
@@ -19,6 +20,8 @@ if(NOT SKIP_frameTransformGet_nwc_yarp)
1920
PRIVATE
2021
FrameTransformGet_nwc_yarp.cpp
2122
FrameTransformGet_nwc_yarp.h
23+
FrameTransformGet_nwc_yarp_ParamsParser.cpp
24+
FrameTransformGet_nwc_yarp_ParamsParser.h
2225
)
2326

2427
target_sources(yarp_frameTransformGet_nwc_yarp PRIVATE $<TARGET_OBJECTS:frameTransformStorageMsgs>)

src/devices/networkWrappers/frameTransformGet_nwc_yarp/FrameTransformGet_nwc_yarp.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ YARP_LOG_COMPONENT(FRAMETRANSFORMGETNWCYARP, "yarp.devices.FrameTransformGet_nwc
1515

1616
bool FrameTransformGet_nwc_yarp::open(yarp::os::Searchable& config)
1717
{
18-
if (!yarp::os::NetworkBase::checkNetwork()) {
19-
yCError(FRAMETRANSFORMGETNWCYARP,"Error! YARP Network is not initialized");
20-
return false;
21-
}
18+
if (!parseParams(config)) { return false; }
19+
2220
std::string prefix;
2321
//checking default config params
2422
bool default_config = true;
@@ -71,11 +69,7 @@ bool FrameTransformGet_nwc_yarp::open(yarp::os::Searchable& config)
7169
}
7270

7371
//checking streaming_enabled param
74-
if(config.check("streaming_enabled")) {
75-
m_streaming_port_enabled = config.find("streaming_enabled").asString() == "true";
76-
}
77-
78-
if (m_streaming_port_enabled)
72+
if (m_streaming_enabled)
7973
{
8074
yCInfo(FRAMETRANSFORMGETNWCYARP) << "Receiving transforms from Yarp port enabled";
8175
if (config.check("input_streaming_port_prefix")){
@@ -128,7 +122,7 @@ bool FrameTransformGet_nwc_yarp::open(yarp::os::Searchable& config)
128122

129123
bool FrameTransformGet_nwc_yarp::close()
130124
{
131-
if (m_streaming_port_enabled)
125+
if (m_streaming_enabled)
132126
{
133127
m_dataReader->close();
134128
}
@@ -145,7 +139,7 @@ bool FrameTransformGet_nwc_yarp::close()
145139

146140
ReturnValue FrameTransformGet_nwc_yarp::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
147141
{
148-
if (!m_streaming_port_enabled)
142+
if (!m_streaming_enabled)
149143
{
150144
return_getAllTransforms retrievedFromRPC = m_frameTransformStorageGetRPC.getTransformsRPC();
151145
if(!retrievedFromRPC.retvalue)

src/devices/networkWrappers/frameTransformGet_nwc_yarp/FrameTransformGet_nwc_yarp.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <yarp/dev/DeviceDriver.h>
1212
#include <yarp/dev/IFrameTransformStorage.h>
1313

14-
1514
#include <FrameTransformStorageGetRPC.h>
15+
#include "FrameTransformGet_nwc_yarp_ParamsParser.h"
1616

1717
/**
1818
* @ingroup dev_impl_nwc_yarp
@@ -25,17 +25,8 @@
2525
* When it a method of the interface is called, the request is forwarded on a RPC port (which uses the thrift FrameTransformStorageGetRPC interface) and it returns all the transforms received
2626
* from the port to the caller.
2727
* For further information see \subpage FrameTransform.
28-
29-
* Parameters required by this device are:
30-
* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description |
31-
* |:----------------------------:|:-------------|:-------:|:------:|:--------------:|:------- -:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
32-
* | default-client | - | bool | - | true | No | tells whether or not the nwc is instantiated by the frameTransformClient device. If true, "/frameTransformClient" will appended to the port name prefix |
33-
* | default-server | - | bool | - | true | No | tells whether or not the nws is instantiated by the frameTransformServer device. If true, "/frameTransformServer/frameTransformGet_nws_yarp" will appended to the port name prefix |
34-
* | nwc_thrift_port_prefix | - | string | - | "" | No | a prefix for the nwc thrift rpc port name |
35-
* | nws_thrift_port_prefix | - | string | - | "" | No | a prefix for the nws thrift rpc port name |
36-
* | input_streaming_port_prefix | - | string | - | - | No | a prefix for the input streaming port name (if the port is enabled) |
37-
* | output_streaming_port_prefix | - | string | - | - | No | a prefix for the output streaming port name (if the port is enabled) |
38-
* | streaming_enabled | - | bool | - | false | No | if enabled, tfs are received from the streaming port instead of using RPCs |
28+
*
29+
* Parameters required by this device are shown in class: FrameTransformGet_nwc_yarpParamsParser
3930
*
4031
* \section FrameTransformGet_nwc_yarp_port_example Port names examples
4132
* Here follow some examples of port names obtained with different parameters configurations
@@ -98,7 +89,8 @@
9889
*/
9990
class FrameTransformGet_nwc_yarp:
10091
public yarp::dev::DeviceDriver,
101-
public yarp::dev::IFrameTransformStorageGet
92+
public yarp::dev::IFrameTransformStorageGet,
93+
public FrameTransformGet_nwc_yarp_ParamsParser
10294
{
10395
class DataReader : public yarp::os::BufferedPort<return_getAllTransforms>
10496
{
@@ -135,7 +127,6 @@ class FrameTransformGet_nwc_yarp:
135127
std::string m_defaultServerPrefix{"/frameTransformServer/frameTransformGet_nws_yarp"};
136128

137129
//streaming port
138-
bool m_streaming_port_enabled = false;
139130
std::string m_streaming_input_port_name;
140131
std::string m_streaming_output_port_name;
141132
DataReader* m_dataReader =nullptr;
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
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: Mon May 26 10:28:39 2025
12+
13+
14+
#include "FrameTransformGet_nwc_yarp_ParamsParser.h"
15+
#include <yarp/os/LogStream.h>
16+
#include <yarp/os/Value.h>
17+
18+
namespace {
19+
YARP_LOG_COMPONENT(FrameTransformGet_nwc_yarpParamsCOMPONENT, "yarp.device.FrameTransformGet_nwc_yarp")
20+
}
21+
22+
23+
FrameTransformGet_nwc_yarp_ParamsParser::FrameTransformGet_nwc_yarp_ParamsParser()
24+
{
25+
}
26+
27+
28+
std::vector<std::string> FrameTransformGet_nwc_yarp_ParamsParser::getListOfParams() const
29+
{
30+
std::vector<std::string> params;
31+
params.push_back("streaming_enabled");
32+
params.push_back("output_streaming_port_prefix");
33+
params.push_back("input_streaming_port_prefix");
34+
params.push_back("nws_thrift_port_prefix");
35+
params.push_back("nwc_thrift_port_prefix");
36+
params.push_back("default_server");
37+
params.push_back("default_client");
38+
return params;
39+
}
40+
41+
42+
bool FrameTransformGet_nwc_yarp_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
43+
{
44+
if (paramName =="streaming_enabled")
45+
{
46+
if (m_streaming_enabled==true) paramValue = "true";
47+
else paramValue = "false";
48+
return true;
49+
}
50+
if (paramName =="output_streaming_port_prefix")
51+
{
52+
if (m_output_streaming_port_prefix==true) paramValue = "true";
53+
else paramValue = "false";
54+
return true;
55+
}
56+
if (paramName =="input_streaming_port_prefix")
57+
{
58+
paramValue = m_input_streaming_port_prefix;
59+
return true;
60+
}
61+
if (paramName =="nws_thrift_port_prefix")
62+
{
63+
paramValue = m_nws_thrift_port_prefix;
64+
return true;
65+
}
66+
if (paramName =="nwc_thrift_port_prefix")
67+
{
68+
paramValue = m_nwc_thrift_port_prefix;
69+
return true;
70+
}
71+
if (paramName =="default_server")
72+
{
73+
paramValue = m_default_server;
74+
return true;
75+
}
76+
if (paramName =="default_client")
77+
{
78+
if (m_default_client==true) paramValue = "true";
79+
else paramValue = "false";
80+
return true;
81+
}
82+
83+
yError() <<"parameter '" << paramName << "' was not found";
84+
return false;
85+
86+
}
87+
88+
89+
std::string FrameTransformGet_nwc_yarp_ParamsParser::getConfiguration() const
90+
{
91+
//This is a sub-optimal solution.
92+
//Ideally getConfiguration() should return all parameters but it is currently
93+
//returning only user provided parameters (excluding default values)
94+
//This behaviour will be fixed in the near future.
95+
std::string s_cfg = m_provided_configuration;
96+
return s_cfg;
97+
}
98+
99+
bool FrameTransformGet_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config)
100+
{
101+
//Check for --help option
102+
if (config.check("help"))
103+
{
104+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams();
105+
}
106+
107+
m_provided_configuration = config.toString();
108+
yarp::os::Property prop_check(m_provided_configuration.c_str());
109+
//Parser of parameter streaming_enabled
110+
{
111+
if (config.check("streaming_enabled"))
112+
{
113+
m_streaming_enabled = config.find("streaming_enabled").asBool();
114+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'streaming_enabled' using value:" << m_streaming_enabled;
115+
}
116+
else
117+
{
118+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'streaming_enabled' using DEFAULT value:" << m_streaming_enabled;
119+
}
120+
prop_check.unput("streaming_enabled");
121+
}
122+
123+
//Parser of parameter output_streaming_port_prefix
124+
{
125+
if (config.check("output_streaming_port_prefix"))
126+
{
127+
m_output_streaming_port_prefix = config.find("output_streaming_port_prefix").asBool();
128+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'output_streaming_port_prefix' using value:" << m_output_streaming_port_prefix;
129+
}
130+
else
131+
{
132+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'output_streaming_port_prefix' using DEFAULT value:" << m_output_streaming_port_prefix;
133+
}
134+
prop_check.unput("output_streaming_port_prefix");
135+
}
136+
137+
//Parser of parameter input_streaming_port_prefix
138+
{
139+
if (config.check("input_streaming_port_prefix"))
140+
{
141+
m_input_streaming_port_prefix = config.find("input_streaming_port_prefix").asString();
142+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'input_streaming_port_prefix' using value:" << m_input_streaming_port_prefix;
143+
}
144+
else
145+
{
146+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'input_streaming_port_prefix' using DEFAULT value:" << m_input_streaming_port_prefix;
147+
}
148+
prop_check.unput("input_streaming_port_prefix");
149+
}
150+
151+
//Parser of parameter nws_thrift_port_prefix
152+
{
153+
if (config.check("nws_thrift_port_prefix"))
154+
{
155+
m_nws_thrift_port_prefix = config.find("nws_thrift_port_prefix").asString();
156+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'nws_thrift_port_prefix' using value:" << m_nws_thrift_port_prefix;
157+
}
158+
else
159+
{
160+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'nws_thrift_port_prefix' using DEFAULT value:" << m_nws_thrift_port_prefix;
161+
}
162+
prop_check.unput("nws_thrift_port_prefix");
163+
}
164+
165+
//Parser of parameter nwc_thrift_port_prefix
166+
{
167+
if (config.check("nwc_thrift_port_prefix"))
168+
{
169+
m_nwc_thrift_port_prefix = config.find("nwc_thrift_port_prefix").asString();
170+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'nwc_thrift_port_prefix' using value:" << m_nwc_thrift_port_prefix;
171+
}
172+
else
173+
{
174+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'nwc_thrift_port_prefix' using DEFAULT value:" << m_nwc_thrift_port_prefix;
175+
}
176+
prop_check.unput("nwc_thrift_port_prefix");
177+
}
178+
179+
//Parser of parameter default_server
180+
{
181+
if (config.check("default_server"))
182+
{
183+
m_default_server = config.find("default_server").asString();
184+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'default_server' using value:" << m_default_server;
185+
}
186+
else
187+
{
188+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'default_server' using DEFAULT value:" << m_default_server;
189+
}
190+
prop_check.unput("default_server");
191+
}
192+
193+
//Parser of parameter default_client
194+
{
195+
if (config.check("default_client"))
196+
{
197+
m_default_client = config.find("default_client").asBool();
198+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'default_client' using value:" << m_default_client;
199+
}
200+
else
201+
{
202+
yCInfo(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "Parameter 'default_client' using DEFAULT value:" << m_default_client;
203+
}
204+
prop_check.unput("default_client");
205+
}
206+
207+
/*
208+
//This code check if the user set some parameter which are not check by the parser
209+
//If the parser is set in strict mode, this will generate an error
210+
if (prop_check.size() > 0)
211+
{
212+
bool extra_params_found = false;
213+
for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
214+
{
215+
if (m_parser_is_strict)
216+
{
217+
yCError(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
218+
extra_params_found = true;
219+
}
220+
else
221+
{
222+
yCWarning(FrameTransformGet_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
223+
}
224+
}
225+
226+
if (m_parser_is_strict && extra_params_found)
227+
{
228+
return false;
229+
}
230+
}
231+
*/
232+
return true;
233+
}
234+
235+
236+
std::string FrameTransformGet_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const
237+
{
238+
std::string doc;
239+
doc = doc + std::string("\n=============================================\n");
240+
doc = doc + std::string("This is the help for device: FrameTransformGet_nwc_yarp\n");
241+
doc = doc + std::string("\n");
242+
doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
243+
doc = doc + std::string("'streaming_enabled': tells whether or not the nwc is instantiated by the frameTransformClient device. If true, \"/frameTransformClient\" will appended to the port name prefix\n");
244+
doc = doc + std::string("'output_streaming_port_prefix': tells whether or not the nws is instantiated by the frameTransformServer device. If true, \"/frameTransformServer/frameTransformGet_nws_yarp\" will appended to the port name prefix\n");
245+
doc = doc + std::string("'input_streaming_port_prefix': a prefix for the nwc thrift rpc port name\n");
246+
doc = doc + std::string("'nws_thrift_port_prefix': a prefix for the nws thrift rpc port name\n");
247+
doc = doc + std::string("'nwc_thrift_port_prefix': a prefix for the input streaming port name (if the port is enabled)\n");
248+
doc = doc + std::string("'default_server': a prefix for the output streaming port name (if the port is enabled)\n");
249+
doc = doc + std::string("'default_client': if enabled, tfs are received from the streaming port instead of using RPCs\n");
250+
doc = doc + std::string("\n");
251+
doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
252+
doc = doc + " yarpdev --device frameTransformGet_nwc_yarp --streaming_enabled true --output_streaming_port_prefix true --input_streaming_port_prefix <optional_value> --nws_thrift_port_prefix <optional_value> --nwc_thrift_port_prefix <optional_value> --default_server <optional_value> --default_client false\n";
253+
doc = doc + std::string("Using only mandatory params:\n");
254+
doc = doc + " yarpdev --device frameTransformGet_nwc_yarp\n";
255+
doc = doc + std::string("=============================================\n\n"); return doc;
256+
}

0 commit comments

Comments
 (0)