mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 07:03:34 +08:00
protocol.param.GetSet update - min/max only for numeric types, longer string value
This commit is contained in:
@@ -25,9 +25,10 @@ uint8[<=92] name
|
|||||||
# Empty value indicates that there is no such parameter.
|
# Empty value indicates that there is no such parameter.
|
||||||
Value value
|
Value value
|
||||||
|
|
||||||
Value default_value # Optional
|
Value default_value # Optional
|
||||||
Value max_value # Optional
|
|
||||||
Value min_value # Optional
|
NumericValue max_value # Optional, not applicable for bool/string
|
||||||
|
NumericValue min_value # Optional, not applicable for bool/string
|
||||||
|
|
||||||
# Empty name in response indicates that there is no such parameter
|
# Empty name in response indicates that there is no such parameter
|
||||||
uint8[<=92] name
|
uint8[<=92] name
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#
|
||||||
|
# Numeric-only value.
|
||||||
|
# The actual type should be inferred from the available values, as described below.
|
||||||
|
# If none of the values below are present, the value is considered empty.
|
||||||
|
#
|
||||||
|
|
||||||
|
int64[<=1] value_int # Preferred over float if ambiguous
|
||||||
|
float32[<=1] value_float # Only if int is empty
|
||||||
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
# This type is nested in Value.
|
# This type is nested in Value.
|
||||||
#
|
#
|
||||||
|
|
||||||
uint8[<64] value
|
uint8[<=127] value
|
||||||
@@ -7,4 +7,4 @@
|
|||||||
bool[<=1] value_bool # Preferred over int, float and string if ambiguous
|
bool[<=1] value_bool # Preferred over int, float and string if ambiguous
|
||||||
int64[<=1] value_int # Preferred over float and string if ambiguous
|
int64[<=1] value_int # Preferred over float and string if ambiguous
|
||||||
float32[<=1] value_float # Preferred over string if ambiguous
|
float32[<=1] value_float # Preferred over string if ambiguous
|
||||||
ValueString[<=1] value_string # This one will be used only if all above are empty
|
String[<=1] value_string # This one will be used only if all above are empty
|
||||||
|
|||||||
@@ -19,33 +19,35 @@ namespace uavcan
|
|||||||
class UAVCAN_EXPORT IParamManager
|
class UAVCAN_EXPORT IParamManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename StorageType<typename protocol::param::GetSet::Response::FieldTypes::name>::Type ParamName;
|
typedef typename StorageType<typename protocol::param::GetSet::Response::FieldTypes::name>::Type Name;
|
||||||
typedef typename StorageType<typename protocol::param::GetSet::Request::FieldTypes::index>::Type ParamIndex;
|
typedef typename StorageType<typename protocol::param::GetSet::Request::FieldTypes::index>::Type Index;
|
||||||
typedef protocol::param::Value ParamValue;
|
typedef protocol::param::Value Value;
|
||||||
|
typedef protocol::param::NumericValue NumericValue;
|
||||||
|
|
||||||
virtual ~IParamManager() { }
|
virtual ~IParamManager() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the parameter name to @ref out_name if it exists, otherwise do nothing.
|
* Copy the parameter name to @ref out_name if it exists, otherwise do nothing.
|
||||||
*/
|
*/
|
||||||
virtual void getParamNameByIndex(ParamIndex index, ParamName& out_name) const = 0;
|
virtual void getParamNameByIndex(Index index, Name& out_name) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign by name if exists.
|
* Assign by name if exists.
|
||||||
*/
|
*/
|
||||||
virtual void assignParamValue(const ParamName& name, const ParamValue& value) = 0;
|
virtual void assignParamValue(const Name& name, const Value& value) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read by name if exists, otherwise do nothing.
|
* Read by name if exists, otherwise do nothing.
|
||||||
*/
|
*/
|
||||||
virtual void readParamValue(const ParamName& name, ParamValue& out_value) const = 0;
|
virtual void readParamValue(const Name& name, Value& out_value) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read param's default/max/min if available.
|
* Read param's default/max/min if available.
|
||||||
|
* Note that min/max are only applicable to numeric params.
|
||||||
* Implementation is optional.
|
* Implementation is optional.
|
||||||
*/
|
*/
|
||||||
virtual void readParamDefaultMaxMin(const ParamName& name, ParamValue& out_default,
|
virtual void readParamDefaultMaxMin(const Name& name, Value& out_default,
|
||||||
ParamValue& out_max, ParamValue& out_min) const
|
NumericValue& out_max, NumericValue& out_min) const
|
||||||
{
|
{
|
||||||
(void)name;
|
(void)name;
|
||||||
(void)out_default;
|
(void)out_default;
|
||||||
@@ -66,15 +68,20 @@ public:
|
|||||||
virtual int eraseAllParams() = 0;
|
virtual int eraseAllParams() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method that can be used to check if a param value is empty.
|
* Convenience methods that can be used to check if a param value is empty.
|
||||||
*/
|
*/
|
||||||
static bool isParamValueEmpty(const ParamValue& val)
|
static bool isValueEmpty(const Value& val)
|
||||||
{
|
{
|
||||||
return val.value_bool.empty() &&
|
return val.value_bool.empty() &&
|
||||||
val.value_int.empty() &&
|
val.value_int.empty() &&
|
||||||
val.value_float.empty() &&
|
val.value_float.empty() &&
|
||||||
val.value_string.empty();
|
val.value_string.empty();
|
||||||
}
|
}
|
||||||
|
static bool isValueEmpty(const NumericValue& val)
|
||||||
|
{
|
||||||
|
return val.value_int.empty() &&
|
||||||
|
val.value_float.empty();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ void ParamServer::handleGetSet(const protocol::param::GetSet::Request& in, proto
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assign if needed, read back
|
// Assign if needed, read back
|
||||||
if (!IParamManager::isParamValueEmpty(in.value))
|
if (!IParamManager::isValueEmpty(in.value))
|
||||||
{
|
{
|
||||||
manager_->assignParamValue(out.name, in.value);
|
manager_->assignParamValue(out.name, in.value);
|
||||||
}
|
}
|
||||||
manager_->readParamValue(out.name, out.value);
|
manager_->readParamValue(out.name, out.value);
|
||||||
|
|
||||||
// Check if the value is OK, otherwise reset the name to indicate that we have no idea what is it all about
|
// Check if the value is OK, otherwise reset the name to indicate that we have no idea what is it all about
|
||||||
if (!IParamManager::isParamValueEmpty(out.value))
|
if (!IParamManager::isValueEmpty(out.value))
|
||||||
{
|
{
|
||||||
manager_->readParamDefaultMaxMin(out.name, out.default_value, out.max_value, out.min_value);
|
manager_->readParamDefaultMaxMin(out.name, out.default_value, out.max_value, out.min_value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
|||||||
typedef std::map<std::string, double> KeyValue;
|
typedef std::map<std::string, double> KeyValue;
|
||||||
KeyValue kv;
|
KeyValue kv;
|
||||||
|
|
||||||
virtual void getParamNameByIndex(ParamIndex index, ParamName& out_name) const
|
virtual void getParamNameByIndex(Index index, Name& out_name) const
|
||||||
{
|
{
|
||||||
ParamIndex current_idx = 0;
|
Index current_idx = 0;
|
||||||
for (KeyValue::const_iterator it = kv.begin(); it != kv.end(); ++it, ++current_idx)
|
for (KeyValue::const_iterator it = kv.begin(); it != kv.end(); ++it, ++current_idx)
|
||||||
{
|
{
|
||||||
if (current_idx == index)
|
if (current_idx == index)
|
||||||
@@ -25,7 +25,7 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void assignParamValue(const ParamName& name, const ParamValue& value)
|
virtual void assignParamValue(const Name& name, const Value& value)
|
||||||
{
|
{
|
||||||
assert(!name.empty());
|
assert(!name.empty());
|
||||||
std::cout << "ASSIGN [" << name.c_str() << "]\n" << value << "\n---" << std::endl;
|
std::cout << "ASSIGN [" << name.c_str() << "]\n" << value << "\n---" << std::endl;
|
||||||
@@ -55,7 +55,7 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void readParamValue(const ParamName& name, ParamValue& out_value) const
|
virtual void readParamValue(const Name& name, Value& out_value) const
|
||||||
{
|
{
|
||||||
assert(!name.empty());
|
assert(!name.empty());
|
||||||
KeyValue::const_iterator it = kv.find(name.c_str());
|
KeyValue::const_iterator it = kv.find(name.c_str());
|
||||||
@@ -158,7 +158,7 @@ TEST(ParamServer, Basic)
|
|||||||
get_set_rq = uavcan::protocol::param::GetSet::Request();
|
get_set_rq = uavcan::protocol::param::GetSet::Request();
|
||||||
get_set_rq.index = 0;
|
get_set_rq.index = 0;
|
||||||
{
|
{
|
||||||
uavcan::protocol::param::ValueString str;
|
uavcan::protocol::param::String str;
|
||||||
str.value = "424242";
|
str.value = "424242";
|
||||||
get_set_rq.value.value_string.push_back(str);
|
get_set_rq.value.value_string.push_back(str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,11 +90,27 @@ std::string paramValueToString(const uavcan::protocol::param::Value& value)
|
|||||||
}
|
}
|
||||||
else if (!value.value_string.empty())
|
else if (!value.value_string.empty())
|
||||||
{
|
{
|
||||||
return std::string(value.value_string[0].value.c_str());
|
return std::string(value.value_string[0].value.c_str()) + " ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return "?";
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string paramValueToString(const uavcan::protocol::param::NumericValue& value)
|
||||||
|
{
|
||||||
|
if (!value.value_int.empty())
|
||||||
|
{
|
||||||
|
return std::to_string(value.value_int[0]);
|
||||||
|
}
|
||||||
|
else if (!value.value_float.empty())
|
||||||
|
{
|
||||||
|
return std::to_string(value.value_float[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user