param.SaveErase --> param.ExecuteOpcode

This commit is contained in:
Pavel Kirienko 2015-03-18 23:49:53 +03:00
parent 62dd626025
commit ddc4b649a8
6 changed files with 54 additions and 41 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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();

View File

@ -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);

View File

@ -14,7 +14,7 @@
#include "debug.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/equipment/hardpoint/Command.hpp>
@ -185,11 +185,11 @@ const std::map<std::string,
{
"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>&)
{
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::SaveErase>();
uavcan::protocol::param::SaveErase::Request request;
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::ExecuteOpcode>();
uavcan::protocol::param::ExecuteOpcode::Request request;
request.opcode = request.OPCODE_SAVE;
std::cout << call(*client, node_id, request) << std::endl;
}
@ -198,11 +198,11 @@ const std::map<std::string,
{
"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>&)
{
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::SaveErase>();
uavcan::protocol::param::SaveErase::Request request;
auto client = node->makeBlockingServiceClient<uavcan::protocol::param::ExecuteOpcode>();
uavcan::protocol::param::ExecuteOpcode::Request request;
request.opcode = request.OPCODE_ERASE;
std::cout << call(*client, node_id, request) << std::endl;
}