Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: drivers/uavcan: add locking for command line param helpers #14741

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/drivers/uavcan/uavcan_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ UavcanNode::cb_opcode(const uavcan::ServiceCallResult<uavcan::protocol::param::E
int
UavcanNode::save_params(int remote_node_id)
{
pthread_mutex_lock(&_node_mutex);

uavcan::protocol::param::ExecuteOpcode::Request opcode_req;
opcode_req.opcode = opcode_req.OPCODE_SAVE;
uavcan::ServiceClient<uavcan::protocol::param::ExecuteOpcode, ExecuteOpcodeCallback> client(_node);
Expand All @@ -204,15 +206,20 @@ UavcanNode::save_params(int remote_node_id)

if (call_res >= 0) {
while (client.hasPendingCalls()) {
pthread_mutex_unlock(&_node_mutex);
usleep(10000);
pthread_mutex_lock(&_node_mutex);
}
}

if (!_callback_success) {
std::printf("Failed to save parameters: %d\n", call_res);
pthread_mutex_unlock(&_node_mutex);
return -1;
}

pthread_mutex_unlock(&_node_mutex);

return 0;
}

Expand Down Expand Up @@ -290,6 +297,8 @@ UavcanNode::cb_setget(const uavcan::ServiceCallResult<uavcan::protocol::param::G
int
UavcanNode::get_set_param(int remote_node_id, const char *name, uavcan::protocol::param::GetSet::Request &req)
{
pthread_mutex_lock(&_node_mutex);

if (name != nullptr) {
req.name = name;
}
Expand All @@ -300,16 +309,19 @@ UavcanNode::get_set_param(int remote_node_id, const char *name, uavcan::protocol
int call_res = client.call(remote_node_id, req);

if (call_res >= 0) {

while (client.hasPendingCalls()) {
pthread_mutex_unlock(&_node_mutex);
usleep(10000);
pthread_mutex_lock(&_node_mutex);
}

if (!_callback_success) {
call_res = -1;
}
}

pthread_mutex_lock(&_node_mutex);

return call_res;
}

Expand Down