mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 19:03:33 +08:00
param.SaveErase --> param.ExecuteOpcode
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#define UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED
|
||||
|
||||
#include <uavcan/protocol/param/GetSet.hpp>
|
||||
#include <uavcan/protocol/param/SaveErase.hpp>
|
||||
#include <uavcan/protocol/param/ExecuteOpcode.hpp>
|
||||
#include <uavcan/node/service_server.hpp>
|
||||
#include <uavcan/util/method_binder.hpp>
|
||||
|
||||
@@ -75,19 +75,20 @@ class UAVCAN_EXPORT ParamServer
|
||||
typedef MethodBinder<ParamServer*, void (ParamServer::*)(const protocol::param::GetSet::Request&,
|
||||
protocol::param::GetSet::Response&)> GetSetCallback;
|
||||
|
||||
typedef MethodBinder<ParamServer*, void (ParamServer::*)(const protocol::param::SaveErase::Request&,
|
||||
protocol::param::SaveErase::Response&)> SaveEraseCallback;
|
||||
typedef MethodBinder<ParamServer*,
|
||||
void (ParamServer::*)(const protocol::param::ExecuteOpcode::Request&,
|
||||
protocol::param::ExecuteOpcode::Response&)> ExecuteOpcodeCallback;
|
||||
|
||||
ServiceServer<protocol::param::GetSet, GetSetCallback> get_set_srv_;
|
||||
ServiceServer<protocol::param::SaveErase, SaveEraseCallback> save_erase_srv_;
|
||||
ServiceServer<protocol::param::ExecuteOpcode, ExecuteOpcodeCallback> save_erase_srv_;
|
||||
IParamManager* manager_;
|
||||
|
||||
static bool isValueNonEmpty(const protocol::param::Value& value);
|
||||
|
||||
void handleGetSet(const protocol::param::GetSet::Request& request, protocol::param::GetSet::Response& response);
|
||||
|
||||
void handleSaveErase(const protocol::param::SaveErase::Request& request,
|
||||
protocol::param::SaveErase::Response& response);
|
||||
void handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& request,
|
||||
protocol::param::ExecuteOpcode::Response& response);
|
||||
|
||||
public:
|
||||
explicit ParamServer(INode& node)
|
||||
|
||||
@@ -49,22 +49,22 @@ void ParamServer::handleGetSet(const protocol::param::GetSet::Request& in, proto
|
||||
}
|
||||
}
|
||||
|
||||
void ParamServer::handleSaveErase(const protocol::param::SaveErase::Request& in,
|
||||
protocol::param::SaveErase::Response& out)
|
||||
void ParamServer::handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& in,
|
||||
protocol::param::ExecuteOpcode::Response& out)
|
||||
{
|
||||
UAVCAN_ASSERT(manager_ != NULL);
|
||||
|
||||
if (in.opcode == protocol::param::SaveErase::Request::OPCODE_SAVE)
|
||||
if (in.opcode == protocol::param::ExecuteOpcode::Request::OPCODE_SAVE)
|
||||
{
|
||||
out.ok = manager_->saveAllParams() >= 0;
|
||||
}
|
||||
else if (in.opcode == protocol::param::SaveErase::Request::OPCODE_ERASE)
|
||||
else if (in.opcode == protocol::param::ExecuteOpcode::Request::OPCODE_ERASE)
|
||||
{
|
||||
out.ok = manager_->eraseAllParams() >= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
UAVCAN_TRACE("ParamServer", "SaveErase: invalid opcode %i", int(in.opcode));
|
||||
UAVCAN_TRACE("ParamServer", "ExecuteOpcode: invalid opcode %i", int(in.opcode));
|
||||
out.ok = false;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ int ParamServer::start(IParamManager* manager)
|
||||
return res;
|
||||
}
|
||||
|
||||
res = save_erase_srv_.start(SaveEraseCallback(this, &ParamServer::handleSaveErase));
|
||||
res = save_erase_srv_.start(ExecuteOpcodeCallback(this, &ParamServer::handleExecuteOpcode));
|
||||
if (res < 0)
|
||||
{
|
||||
get_set_srv_.stop();
|
||||
|
||||
@@ -93,23 +93,23 @@ TEST(ParamServer, Basic)
|
||||
|
||||
uavcan::GlobalDataTypeRegistry::instance().reset();
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::GetSet> _reg1;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::SaveErase> _reg2;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::ExecuteOpcode> _reg2;
|
||||
|
||||
ASSERT_LE(0, server.start(&mgr));
|
||||
|
||||
ServiceClientWithCollector<uavcan::protocol::param::GetSet> get_set_cln(nodes.b);
|
||||
ServiceClientWithCollector<uavcan::protocol::param::SaveErase> save_erase_cln(nodes.b);
|
||||
ServiceClientWithCollector<uavcan::protocol::param::ExecuteOpcode> save_erase_cln(nodes.b);
|
||||
|
||||
/*
|
||||
* Save/erase
|
||||
*/
|
||||
uavcan::protocol::param::SaveErase::Request save_erase_rq;
|
||||
save_erase_rq.opcode = uavcan::protocol::param::SaveErase::Request::OPCODE_SAVE;
|
||||
uavcan::protocol::param::ExecuteOpcode::Request save_erase_rq;
|
||||
save_erase_rq.opcode = uavcan::protocol::param::ExecuteOpcode::Request::OPCODE_SAVE;
|
||||
doCall(save_erase_cln, save_erase_rq, nodes);
|
||||
ASSERT_TRUE(save_erase_cln.collector.result.get());
|
||||
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
||||
|
||||
save_erase_rq.opcode = uavcan::protocol::param::SaveErase::Request::OPCODE_ERASE;
|
||||
save_erase_rq.opcode = uavcan::protocol::param::ExecuteOpcode::Request::OPCODE_ERASE;
|
||||
doCall(save_erase_cln, save_erase_rq, nodes);
|
||||
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user