Skip to content

Commit 287cbdf

Browse files
authored
File Downloader demo at libcyphal_demo (#34)
- Added File downloader (cyphal `file::GetInfo` and `file::Read` RPC client) - does a file downloading upon receiving the `COMMAND_BEGIN_SOFTWARE_UPDATE` command. - Increased memory and # of buffers to accommodate bigger messages, redundant interfaces, as well as expected memory spike in case of a redundant interface failures.
1 parent 3fca5a1 commit 287cbdf

12 files changed

+447
-42
lines changed

.gitmodules

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@
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/application.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323
namespace
2424
{
2525

26-
constexpr std::size_t HeapSize = 16ULL * 1024ULL;
27-
alignas(O1HEAP_ALIGNMENT) std::array<cetl::byte, HeapSize> s_heap_arena{};
26+
constexpr std::size_t HeapSize = 128ULL * 1024ULL;
27+
alignas(O1HEAP_ALIGNMENT) std::array<cetl::byte, HeapSize> s_heap_arena{}; // NOLINT
28+
29+
constexpr std::size_t BlockHeapSize = 128ULL * 1024ULL;
30+
alignas(O1HEAP_ALIGNMENT) std::array<cetl::byte, BlockHeapSize> s_block_heap_arena{}; // NOLINT
2831

2932
} // namespace
3033

3134
Application::Application(const char* const root_path)
3235
: o1_heap_mr_{s_heap_arena}
36+
, o1_block_heap_mr_{s_block_heap_arena}
37+
, media_block_mr_{o1_block_heap_mr_}
3338
, storage_{root_path}
3439
, registry_{o1_heap_mr_}
35-
, media_block_mr_{*cetl::pmr::new_delete_resource()}
3640
, regs_{o1_heap_mr_, registry_, media_block_mr_}
3741
{
3842
cetl::pmr::set_default_resource(&o1_heap_mr_);

libcyphal_demo/src/application.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <cetl/pf17/cetlpf.hpp>
1717
#include <libcyphal/application/registry/register.hpp>
1818
#include <libcyphal/application/registry/registry_impl.hpp>
19-
#include <libcyphal/platform/storage.hpp>
2019

2120
#include <algorithm>
2221
#include <array>
@@ -247,6 +246,7 @@ class Application final
247246

248247
platform::Linux::EpollSingleThreadedExecutor executor_;
249248
platform::O1HeapMemoryResource o1_heap_mr_;
249+
platform::O1HeapMemoryResource o1_block_heap_mr_;
250250
platform::BlockMemoryResource media_block_mr_;
251251
platform::storage::KeyValue storage_;
252252
libcyphal::application::registry::Registry registry_;

libcyphal_demo/src/exec_cmd_provider.hpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "libcyphal/application/node.hpp"
1111
#include "libcyphal/presentation/presentation.hpp"
1212
#include "libcyphal/presentation/server.hpp"
13+
#include "libcyphal/time_provider.hpp"
14+
#include "libcyphal/transport/types.hpp"
1315
#include "libcyphal/types.hpp"
1416

1517
#include <cetl/pf17/cetlpf.hpp>
@@ -52,9 +54,12 @@ class ExecCmdProvider // NOSONAR cpp:S4963
5254
///
5355
/// @param node The application layer node instance. In use to access heartbeat producer.
5456
/// @param presentation The presentation layer instance. In use to create 'ExecuteCommand' service server.
57+
/// @param time_provider The time provider - in use to calculate RPC call deadlines.
5558
/// @return The ExecuteCommand provider instance or a failure.
5659
///
57-
static auto make(libcyphal::application::Node& node, libcyphal::presentation::Presentation& presentation)
60+
static auto make(libcyphal::application::Node& node,
61+
libcyphal::presentation::Presentation& presentation,
62+
libcyphal::ITimeProvider& time_provider)
5863
-> libcyphal::Expected<Derived, libcyphal::presentation::Presentation::MakeFailure>
5964
{
6065
auto maybe_srv = presentation.makeServer<Service>();
@@ -63,7 +68,7 @@ class ExecCmdProvider // NOSONAR cpp:S4963
6368
return std::move(*failure);
6469
}
6570

66-
return Derived{node, presentation, cetl::get<Server>(std::move(maybe_srv))};
71+
return Derived{node, presentation, time_provider, cetl::get<Server>(std::move(maybe_srv))};
6772
}
6873

6974
ExecCmdProvider(ExecCmdProvider&& other) noexcept
@@ -96,16 +101,19 @@ class ExecCmdProvider // NOSONAR cpp:S4963
96101
/// The user should override the method to handle custom commands.
97102
/// If the method returns `false`, the server will respond with a `STATUS_BAD_COMMAND` status.
98103
///
99-
/// @param command The command to be executed.
100-
/// @param parameter The command parameter.
101-
/// @param response The response to be sent back to the requester.
104+
/// @param command The command to be executed.
105+
/// @param parameter The command parameter.
106+
/// @param metadata The transport RX metadata.
107+
/// @param response The response to be sent back to the requester.
102108
///
103-
virtual bool onCommand(const Request::_traits_::TypeOf::command command,
104-
const cetl::string_view parameter,
105-
Response& response) noexcept
109+
virtual bool onCommand(const Request::_traits_::TypeOf::command command,
110+
const cetl::string_view parameter,
111+
const libcyphal::transport::ServiceRxMetadata& metadata,
112+
Response& response) noexcept
106113
{
107114
(void) command;
108115
(void) parameter;
116+
(void) metadata;
109117
(void) response;
110118

111119
return false;
@@ -126,7 +134,7 @@ class ExecCmdProvider // NOSONAR cpp:S4963
126134
server_.setOnRequestCallback([this](const auto& arg, auto continuation) {
127135
//
128136
Response response{alloc_};
129-
if (!onCommand(arg.request.command, makeStringView(arg.request.parameter), response))
137+
if (!onCommand(arg.request.command, makeStringView(arg.request.parameter), arg.metadata, response))
130138
{
131139
response.status = Response::STATUS_BAD_COMMAND;
132140
}

0 commit comments

Comments
 (0)