mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 16:53:34 +08:00
param.SaveErase --> param.ExecuteOpcode
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
#
|
||||||
|
# Service to control the node configuration.
|
||||||
|
#
|
||||||
|
# SAVE operation instructs the remote node to save the current configuration parameters to the non-volatile
|
||||||
|
# storage. The node may require a restart in order for some changes to take effect.
|
||||||
|
#
|
||||||
|
# ERASE operation instructs the remote node to clear its configuration storage and reinitialize the parameters
|
||||||
|
# with their default values. The node may require a restart in order for some changes to take effect.
|
||||||
|
#
|
||||||
|
# Other opcodes may be added in the future (for example, an opcode for switching between multiple configurations).
|
||||||
|
#
|
||||||
|
|
||||||
|
uint8 OPCODE_SAVE = 0 # Save all parameters to non-volatile storage.
|
||||||
|
uint8 OPCODE_ERASE = 1 # Clear the non-volatile storage; some changes may take effect only after reboot.
|
||||||
|
uint8 opcode
|
||||||
|
|
||||||
|
#
|
||||||
|
# Reserved, keep zero.
|
||||||
|
#
|
||||||
|
int48 argument
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#
|
||||||
|
# Reserved, keep zero.
|
||||||
|
#
|
||||||
|
int48 argument
|
||||||
|
|
||||||
|
bool ok
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#
|
|
||||||
# Service to control non-volatile parameter storage.
|
|
||||||
#
|
|
||||||
# SAVE operation instructs the remote node to save the current configuration parameters to the non-volatile
|
|
||||||
# storage. The device may require a restart in order for some changes to take effect.
|
|
||||||
#
|
|
||||||
# ERASE operation instructs the remote node to clear its configuration storage and reinitialize the parameters
|
|
||||||
# with their default values. The device may require a restart in order for some changes to take effect.
|
|
||||||
#
|
|
||||||
|
|
||||||
uint8 OPCODE_SAVE = 0 # Save all parameters to non-volatile storage.
|
|
||||||
uint8 OPCODE_ERASE = 1 # Clear the non-volatile storage; some changes may take effect only after reboot.
|
|
||||||
uint8 opcode
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
bool ok
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#define UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED
|
#define UAVCAN_PROTOCOL_PARAM_SERVER_HPP_INCLUDED
|
||||||
|
|
||||||
#include <uavcan/protocol/param/GetSet.hpp>
|
#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/node/service_server.hpp>
|
||||||
#include <uavcan/util/method_binder.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&,
|
typedef MethodBinder<ParamServer*, void (ParamServer::*)(const protocol::param::GetSet::Request&,
|
||||||
protocol::param::GetSet::Response&)> GetSetCallback;
|
protocol::param::GetSet::Response&)> GetSetCallback;
|
||||||
|
|
||||||
typedef MethodBinder<ParamServer*, void (ParamServer::*)(const protocol::param::SaveErase::Request&,
|
typedef MethodBinder<ParamServer*,
|
||||||
protocol::param::SaveErase::Response&)> SaveEraseCallback;
|
void (ParamServer::*)(const protocol::param::ExecuteOpcode::Request&,
|
||||||
|
protocol::param::ExecuteOpcode::Response&)> ExecuteOpcodeCallback;
|
||||||
|
|
||||||
ServiceServer<protocol::param::GetSet, GetSetCallback> get_set_srv_;
|
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_;
|
IParamManager* manager_;
|
||||||
|
|
||||||
static bool isValueNonEmpty(const protocol::param::Value& value);
|
static bool isValueNonEmpty(const protocol::param::Value& value);
|
||||||
|
|
||||||
void handleGetSet(const protocol::param::GetSet::Request& request, protocol::param::GetSet::Response& response);
|
void handleGetSet(const protocol::param::GetSet::Request& request, protocol::param::GetSet::Response& response);
|
||||||
|
|
||||||
void handleSaveErase(const protocol::param::SaveErase::Request& request,
|
void handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& request,
|
||||||
protocol::param::SaveErase::Response& response);
|
protocol::param::ExecuteOpcode::Response& response);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ParamServer(INode& node)
|
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,
|
void ParamServer::handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& in,
|
||||||
protocol::param::SaveErase::Response& out)
|
protocol::param::ExecuteOpcode::Response& out)
|
||||||
{
|
{
|
||||||
UAVCAN_ASSERT(manager_ != NULL);
|
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;
|
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;
|
out.ok = manager_->eraseAllParams() >= 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UAVCAN_TRACE("ParamServer", "SaveErase: invalid opcode %i", int(in.opcode));
|
UAVCAN_TRACE("ParamServer", "ExecuteOpcode: invalid opcode %i", int(in.opcode));
|
||||||
out.ok = false;
|
out.ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ int ParamServer::start(IParamManager* manager)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = save_erase_srv_.start(SaveEraseCallback(this, &ParamServer::handleSaveErase));
|
res = save_erase_srv_.start(ExecuteOpcodeCallback(this, &ParamServer::handleExecuteOpcode));
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
get_set_srv_.stop();
|
get_set_srv_.stop();
|
||||||
|
|||||||
@@ -93,23 +93,23 @@ TEST(ParamServer, Basic)
|
|||||||
|
|
||||||
uavcan::GlobalDataTypeRegistry::instance().reset();
|
uavcan::GlobalDataTypeRegistry::instance().reset();
|
||||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::GetSet> _reg1;
|
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));
|
ASSERT_LE(0, server.start(&mgr));
|
||||||
|
|
||||||
ServiceClientWithCollector<uavcan::protocol::param::GetSet> get_set_cln(nodes.b);
|
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
|
* Save/erase
|
||||||
*/
|
*/
|
||||||
uavcan::protocol::param::SaveErase::Request save_erase_rq;
|
uavcan::protocol::param::ExecuteOpcode::Request save_erase_rq;
|
||||||
save_erase_rq.opcode = uavcan::protocol::param::SaveErase::Request::OPCODE_SAVE;
|
save_erase_rq.opcode = uavcan::protocol::param::ExecuteOpcode::Request::OPCODE_SAVE;
|
||||||
doCall(save_erase_cln, save_erase_rq, nodes);
|
doCall(save_erase_cln, save_erase_rq, nodes);
|
||||||
ASSERT_TRUE(save_erase_cln.collector.result.get());
|
ASSERT_TRUE(save_erase_cln.collector.result.get());
|
||||||
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
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);
|
doCall(save_erase_cln, save_erase_rq, nodes);
|
||||||
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
|
||||||
#include <uavcan/protocol/param/GetSet.hpp>
|
#include <uavcan/protocol/param/GetSet.hpp>
|
||||||
#include <uavcan/protocol/param/SaveErase.hpp>
|
#include <uavcan/protocol/param/ExecuteOpcode.hpp>
|
||||||
#include <uavcan/protocol/EnumerationRequest.hpp>
|
#include <uavcan/protocol/EnumerationRequest.hpp>
|
||||||
#include <uavcan/equipment/hardpoint/Command.hpp>
|
#include <uavcan/equipment/hardpoint/Command.hpp>
|
||||||
|
|
||||||
@@ -185,11 +185,11 @@ const std::map<std::string,
|
|||||||
{
|
{
|
||||||
"param_save",
|
"param_save",
|
||||||
{
|
{
|
||||||
"Calls uavcan.protocol.param.SaveErase on a remote node with OPCODE_SAVE",
|
"Calls uavcan.protocol.param.ExecuteOpcode on a remote node with OPCODE_SAVE",
|
||||||
[](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector<std::string>&)
|
[](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector<std::string>&)
|
||||||
{
|
{
|
||||||
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::SaveErase>();
|
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::ExecuteOpcode>();
|
||||||
uavcan::protocol::param::SaveErase::Request request;
|
uavcan::protocol::param::ExecuteOpcode::Request request;
|
||||||
request.opcode = request.OPCODE_SAVE;
|
request.opcode = request.OPCODE_SAVE;
|
||||||
std::cout << call(*client, node_id, request) << std::endl;
|
std::cout << call(*client, node_id, request) << std::endl;
|
||||||
}
|
}
|
||||||
@@ -198,11 +198,11 @@ const std::map<std::string,
|
|||||||
{
|
{
|
||||||
"param_erase",
|
"param_erase",
|
||||||
{
|
{
|
||||||
"Calls uavcan.protocol.param.SaveErase on a remote node with OPCODE_ERASE",
|
"Calls uavcan.protocol.param.ExecuteOpcode on a remote node with OPCODE_ERASE",
|
||||||
[](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector<std::string>&)
|
[](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector<std::string>&)
|
||||||
{
|
{
|
||||||
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::SaveErase>();
|
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::ExecuteOpcode>();
|
||||||
uavcan::protocol::param::SaveErase::Request request;
|
uavcan::protocol::param::ExecuteOpcode::Request request;
|
||||||
request.opcode = request.OPCODE_ERASE;
|
request.opcode = request.OPCODE_ERASE;
|
||||||
std::cout << call(*client, node_id, request) << std::endl;
|
std::cout << call(*client, node_id, request) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user