-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT) | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#message (Looking for CMakeFiles into this folder: ${YARP_MODULE_DIR}) | ||
include(${YARP_MODULE_DIR}/YarpDeviceParamsParserGenerator.cmake) | ||
|
||
add_subdirectory(deviceTemplate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/devices/deviceTemplate/DeviceTemplate_ParamsParser.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
|
||
// Generated by yarpDeviceParamParserGenerator (1.0) | ||
// | ||
// This is an automatically generated file. Please do not edit it. | ||
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. | ||
|
||
// Generated on: Thu Jan 25 14:38:34 2024 | ||
|
||
|
||
#include "DeviceTemplate_ParamsParser.h" | ||
#include <yarp/os/LogStream.h> | ||
#include <yarp/os/Value.h> | ||
|
||
namespace { | ||
YARP_LOG_COMPONENT(DeviceTemplateParamsCOMPONENT, "yarp.device.DeviceTemplate") | ||
} | ||
|
||
|
||
std::vector<std::string> DeviceTemplate_ParamsParser::getListOfParams() const | ||
{ | ||
std::vector<std::string> params; | ||
params.push_back("dummy_group::dummy_param1"); | ||
params.push_back("dummy_param2"); | ||
return params; | ||
} | ||
|
||
|
||
bool DeviceTemplate_ParamsParser::parseParams(const yarp::os::Searchable & config) | ||
{ | ||
std::string config_string = config.toString(); | ||
yarp::os::Property prop_check(config_string.c_str()); | ||
//Parser of parameter dummy_group::dummy_param1 | ||
{ | ||
yarp::os::Bottle sectionp; | ||
sectionp = config.findGroup("dummy_group"); | ||
if (sectionp.check("dummy_param1")) | ||
{ | ||
m_dummy_group_dummy_param1 = sectionp.find("dummy_param1").asString(); | ||
yCInfo(DeviceTemplateParamsCOMPONENT) << "Parameter 'dummy_group::dummy_param1' using value:" << m_dummy_group_dummy_param1; | ||
} | ||
else | ||
{ | ||
yCError(DeviceTemplateParamsCOMPONENT) << "Mandatory parameter 'dummy_group::dummy_param1' not found!"; | ||
yCError(DeviceTemplateParamsCOMPONENT) << "Description of the parameter: This is the description of dummy_param1"; | ||
return false; | ||
} | ||
prop_check.unput("dummy_group::dummy_param1"); | ||
} | ||
|
||
//Parser of parameter dummy_param2 | ||
{ | ||
if (config.check("dummy_param2")) | ||
{ | ||
m_dummy_param2 = config.find("dummy_param2").asFloat64(); | ||
yCInfo(DeviceTemplateParamsCOMPONENT) << "Parameter 'dummy_param2' using value:" << m_dummy_param2; | ||
} | ||
else | ||
{ | ||
yCInfo(DeviceTemplateParamsCOMPONENT) << "Parameter 'dummy_param2' using DEFAULT value:" << m_dummy_param2; | ||
} | ||
prop_check.unput("dummy_param2"); | ||
} | ||
|
||
/* | ||
//This code check if the user set some parameter which are not check by the parser | ||
//If the parser is set in strict mode, this will generate an error | ||
if (prop_check.size() > 0) | ||
{ | ||
bool extra_params_found = false; | ||
for (auto it=prop_check.begin(); it!=prop_check.end(); it++) | ||
{ | ||
if (m_parser_is_strict) | ||
{ | ||
yCError(DeviceTemplateParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!"; | ||
extra_params_found = true; | ||
} | ||
else | ||
{ | ||
yCWarning(DeviceTemplateParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; | ||
} | ||
} | ||
if (m_parser_is_strict && extra_params_found) | ||
{ | ||
return false; | ||
} | ||
} | ||
*/ | ||
return true; | ||
} | ||
|
||
|
||
std::string DeviceTemplate_ParamsParser::getDocumentationOfDeviceParams() const | ||
{ | ||
std::string doc; | ||
doc = doc + std::string("'dummy_group::dummy_param1': This is the description of dummy_param1\n"); | ||
doc = doc + std::string("'dummy_param2': This is the description of dummy_param2\n"); | ||
doc = doc + std::string("\n"); | ||
doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); | ||
doc = doc + " yarpdev --device DeviceTemplate --dummy_group::dummy_param1 dummy_default_value --dummy_param2 9.81\n"; | ||
doc = doc + std::string("Using only mandatory params:\n"); | ||
doc = doc + " yarpdev --device DeviceTemplate --dummy_group::dummy_param1 dummy_default_value\n"; | ||
doc = doc + std::string("\n"); | ||
return doc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
|
||
// Generated by yarpDeviceParamParserGenerator (1.0) | ||
// | ||
// This is an automatically generated file. Please do not edit it. | ||
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. | ||
|
||
// Generated on: Thu Jan 25 14:38:34 2024 | ||
|
||
|
||
#ifndef DEVICETEMPLATE_PARAMSPARSER_H | ||
#define DEVICETEMPLATE_PARAMSPARSER_H | ||
|
||
#include <yarp/os/Searchable.h> | ||
#include <yarp/dev/IDeviceDriverParams.h> | ||
#include <string> | ||
|
||
/** | ||
* This class is the parameters parser for class DeviceTemplate. | ||
* | ||
* These are the used parameters: | ||
* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | | ||
* |:-----------:|:--------------:|:------:|:-----:|:-------------------:|:--------:|:---------------------------------------:|:-----------------------------------------:| | ||
* | dummy_group | dummy_param1 | string | - | dummy_default_value | 1 | This is the description of dummy_param1 | Here are additional notes | | ||
* | - | dummy_param2 | double | m/s^2 | 9.81 | 0 | This is the description of dummy_param2 | The default value is the gravity constant | | ||
* | ||
* The device can be launched by yarpdev using one of the following examples: | ||
* \code{.unparsed} | ||
* yarpdev --device DeviceTemplate --dummy_group::dummy_param1 dummy_default_value --dummy_param2 9.81 | ||
* \endcode | ||
* | ||
* \code{.unparsed} | ||
* yarpdev --device DeviceTemplate --dummy_group::dummy_param1 dummy_default_value | ||
* \endcode | ||
* | ||
*/ | ||
|
||
class DeviceTemplate_ParamsParser : public yarp::dev::IDeviceDriverParams | ||
{ | ||
public: | ||
~DeviceTemplate_ParamsParser() override = default; | ||
|
||
public: | ||
const std::string m_device_type = {"DeviceTemplate"}; | ||
bool m_parser_is_strict = false; | ||
std::string m_dummy_group_dummy_param1 = {"dummy_default_value"}; | ||
double m_dummy_param2 = {9.81}; | ||
|
||
bool parseParams(const yarp::os::Searchable & config) override; | ||
std::string getDeviceType() const override { return m_device_type; } | ||
std::string getDocumentationOfDeviceParams() const override; | ||
std::vector<std::string> getListOfParams() const override; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| dummy_group | dummy_param1 | string | - | dummy_default_value | Yes | This is the description of dummy_param1 | Here are additional notes | | ||
| - | dummy_param2 | double | m/s^2 | 9.81 | No | This is the description of dummy_param2 | The default value is the gravity constant | |