Skip to content

Commit 3fca5a1

Browse files
committed
added support for 'COMMAND_BEGIN_SOFTWARE_UPDATE'
1 parent 494299a commit 3fca5a1

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
[submodule "submodules/libcyphal"]
1919
path = submodules/libcyphal
2020
url = https://github.com/OpenCyphal-Garage/libcyphal.git
21+
branch = sshirokov/416_tid

libcyphal_demo/src/exec_cmd_provider.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef COMMAND_PROVIDER_HPP_INCLUDED
88
#define COMMAND_PROVIDER_HPP_INCLUDED
99

10+
#include "libcyphal/application/node.hpp"
1011
#include "libcyphal/presentation/presentation.hpp"
1112
#include "libcyphal/presentation/server.hpp"
1213
#include "libcyphal/types.hpp"
@@ -28,9 +29,10 @@
2829
template <typename Derived>
2930
class ExecCmdProvider // NOSONAR cpp:S4963
3031
{
32+
public:
3133
using Service = uavcan::node::ExecuteCommand_1_3;
34+
using Server = libcyphal::presentation::ServiceServer<Service>;
3235

33-
public:
3436
/// Defines the response type for the ExecuteCommand provider.
3537
///
3638
using Response = Service::Response;
@@ -48,10 +50,11 @@ class ExecCmdProvider // NOSONAR cpp:S4963
4850

4951
/// Factory method to create a ExecuteCommand instance.
5052
///
53+
/// @param node The application layer node instance. In use to access heartbeat producer.
5154
/// @param presentation The presentation layer instance. In use to create 'ExecuteCommand' service server.
5255
/// @return The ExecuteCommand provider instance or a failure.
5356
///
54-
static auto make(libcyphal::presentation::Presentation& presentation)
57+
static auto make(libcyphal::application::Node& node, libcyphal::presentation::Presentation& presentation)
5558
-> libcyphal::Expected<Derived, libcyphal::presentation::Presentation::MakeFailure>
5659
{
5760
auto maybe_srv = presentation.makeServer<Service>();
@@ -60,7 +63,7 @@ class ExecCmdProvider // NOSONAR cpp:S4963
6063
return std::move(*failure);
6164
}
6265

63-
return Derived{presentation, cetl::get<Server>(std::move(maybe_srv))};
66+
return Derived{node, presentation, cetl::get<Server>(std::move(maybe_srv))};
6467
}
6568

6669
ExecCmdProvider(ExecCmdProvider&& other) noexcept
@@ -108,9 +111,7 @@ class ExecCmdProvider // NOSONAR cpp:S4963
108111
return false;
109112
}
110113

111-
private:
112-
using Server = libcyphal::presentation::ServiceServer<Service>;
113-
114+
protected:
114115
ExecCmdProvider(const libcyphal::presentation::Presentation& presentation, Server&& server)
115116
: alloc_{&presentation.memory()}
116117
, server_{std::move(server)}
@@ -119,6 +120,7 @@ class ExecCmdProvider // NOSONAR cpp:S4963
119120
setupOnRequestCallback();
120121
}
121122

123+
private:
122124
void setupOnRequestCallback()
123125
{
124126
server_.setOnRequestCallback([this](const auto& arg, auto continuation) {

libcyphal_demo/src/main.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
#include <libcyphal/transport/transport.hpp>
1616
#include <libcyphal/types.hpp>
1717

18+
#include <uavcan/node/Health_1_0.hpp>
19+
#include <uavcan/node/Mode_1_0.hpp>
20+
1821
#include <algorithm>
1922
#include <array>
20-
#include <chrono>
2123
#include <cstdint>
2224
#include <cstring>
23-
#include <ios>
2425
#include <iomanip>
26+
#include <ios>
2527
#include <iostream>
2628
#include <unistd.h> // execve
2729
#include <utility>
@@ -36,7 +38,13 @@ namespace
3638
class AppExecCmdProvider final : public ExecCmdProvider<AppExecCmdProvider>
3739
{
3840
public:
39-
using ExecCmdProvider::ExecCmdProvider;
41+
AppExecCmdProvider(libcyphal::application::Node& node,
42+
const libcyphal::presentation::Presentation& presentation,
43+
Server&& server)
44+
: ExecCmdProvider{presentation, std::move(server)}
45+
, node_{node}
46+
{
47+
}
4048

4149
bool should_break() const noexcept
4250
{
@@ -80,14 +88,21 @@ class AppExecCmdProvider final : public ExecCmdProvider<AppExecCmdProvider>
8088
restart_required_ = true;
8189
break;
8290

91+
case Request::COMMAND_BEGIN_SOFTWARE_UPDATE:
92+
//
93+
std::cout << "🚧 COMMAND_BEGIN_SOFTWARE_UPDATE (file='" << parameter << "')\n";
94+
node_.heartbeatProducer().message().mode.value = uavcan::node::Mode_1_0::SOFTWARE_UPDATE;
95+
break;
96+
8397
default:
8498
return ExecCmdProvider::onCommand(command, parameter, response);
8599
}
86100
return true;
87101
}
88102

89-
bool should_power_off_{false};
90-
bool restart_required_{false};
103+
libcyphal::application::Node& node_;
104+
bool should_power_off_{false};
105+
bool restart_required_{false};
91106

92107
}; // AppExecCmdProvider
93108

@@ -196,8 +211,8 @@ libcyphal::Expected<bool, ExitCode> run_application(const char* const root_path)
196211

197212
// 6. Bring up the command execution provider.
198213
//
199-
auto maybe_exec_cmd_provider = AppExecCmdProvider::make(presentation);
200-
if (const auto* failure = cetl::get_if<libcyphal::application::Node::MakeFailure>(&maybe_node))
214+
auto maybe_exec_cmd_provider = AppExecCmdProvider::make(node, presentation);
215+
if (const auto* failure = cetl::get_if<libcyphal::application::Node::MakeFailure>(&maybe_exec_cmd_provider))
201216
{
202217
std::cerr << "❌ Failed to create exec cmd provider.\n";
203218
return ExitCode::ExecCmdProviderCreationFailure;

0 commit comments

Comments
 (0)