Basic support for string parameters

This commit is contained in:
Pavel Kirienko
2015-03-19 00:19:40 +03:00
parent ddc4b649a8
commit 3b7669219e
4 changed files with 20 additions and 4 deletions
@@ -88,7 +88,7 @@ class UAVCAN_EXPORT ParamServer
void handleGetSet(const protocol::param::GetSet::Request& request, protocol::param::GetSet::Response& response);
void handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& request,
protocol::param::ExecuteOpcode::Response& response);
protocol::param::ExecuteOpcode::Response& response);
public:
explicit ParamServer(INode& node)
+5 -2
View File
@@ -12,7 +12,10 @@ namespace uavcan
bool ParamServer::isValueNonEmpty(const protocol::param::Value& value)
{
return !value.value_bool.empty() || !value.value_int.empty() || !value.value_float.empty();
return !value.value_bool.empty() ||
!value.value_int.empty() ||
!value.value_float.empty() ||
!value.value_string.empty();
}
void ParamServer::handleGetSet(const protocol::param::GetSet::Request& in, protocol::param::GetSet::Response& out)
@@ -50,7 +53,7 @@ void ParamServer::handleGetSet(const protocol::param::GetSet::Request& in, proto
}
void ParamServer::handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& in,
protocol::param::ExecuteOpcode::Response& out)
protocol::param::ExecuteOpcode::Response& out)
{
UAVCAN_ASSERT(manager_ != NULL);
+9 -1
View File
@@ -43,6 +43,10 @@ struct ParamServerTestManager : public uavcan::IParamManager
{
it->second = double(value.value_float[0]);
}
else if (!value.value_string.empty())
{
it->second = std::atof(value.value_string[0].value.c_str());
}
else
{
assert(0);
@@ -151,7 +155,11 @@ TEST(ParamServer, Basic)
// Set by index
get_set_rq = uavcan::protocol::param::GetSet::Request();
get_set_rq.index = 0;
get_set_rq.value.value_int.push_back(424242);
{
uavcan::protocol::param::ValueString str;
str.value = "424242";
get_set_rq.value.value_string.push_back(str);
}
doCall(get_set_cln, get_set_rq, nodes);
ASSERT_STREQ("foobar", get_set_cln.collector.result->response.name.c_str());
ASSERT_FLOAT_EQ(424242, get_set_cln.collector.result->response.value.value_float[0]);
@@ -88,6 +88,10 @@ std::string paramValueToString(const uavcan::protocol::param::Value& value)
{
return std::to_string(value.value_float[0]);
}
else if (!value.value_string.empty())
{
return std::string(value.value_string[0].value.c_str());
}
else
{
return "?";
@@ -176,6 +180,7 @@ const std::map<std::string,
else
{
request.name = args.at(0).c_str();
// TODO: add support for string parameters
request.value.value_float.push_back(std::stof(args.at(1)));
printGetSetResponse(call(*client, node_id, request));
}