Skip to content

Commit

Permalink
File Downloader demo at libcyphal_demo (#34)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
serges147 authored Feb 13, 2025
1 parent 3fca5a1 commit 287cbdf
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 42 deletions.
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
[submodule "submodules/libcyphal"]
path = submodules/libcyphal
url = https://github.com/OpenCyphal-Garage/libcyphal.git
branch = sshirokov/416_tid
10 changes: 7 additions & 3 deletions libcyphal_demo/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
namespace
{

constexpr std::size_t HeapSize = 16ULL * 1024ULL;
alignas(O1HEAP_ALIGNMENT) std::array<cetl::byte, HeapSize> s_heap_arena{};
constexpr std::size_t HeapSize = 128ULL * 1024ULL;
alignas(O1HEAP_ALIGNMENT) std::array<cetl::byte, HeapSize> s_heap_arena{}; // NOLINT

constexpr std::size_t BlockHeapSize = 128ULL * 1024ULL;
alignas(O1HEAP_ALIGNMENT) std::array<cetl::byte, BlockHeapSize> s_block_heap_arena{}; // NOLINT

} // namespace

Application::Application(const char* const root_path)
: o1_heap_mr_{s_heap_arena}
, o1_block_heap_mr_{s_block_heap_arena}
, media_block_mr_{o1_block_heap_mr_}
, storage_{root_path}
, registry_{o1_heap_mr_}
, media_block_mr_{*cetl::pmr::new_delete_resource()}
, regs_{o1_heap_mr_, registry_, media_block_mr_}
{
cetl::pmr::set_default_resource(&o1_heap_mr_);
Expand Down
2 changes: 1 addition & 1 deletion libcyphal_demo/src/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <cetl/pf17/cetlpf.hpp>
#include <libcyphal/application/registry/register.hpp>
#include <libcyphal/application/registry/registry_impl.hpp>
#include <libcyphal/platform/storage.hpp>

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -247,6 +246,7 @@ class Application final

platform::Linux::EpollSingleThreadedExecutor executor_;
platform::O1HeapMemoryResource o1_heap_mr_;
platform::O1HeapMemoryResource o1_block_heap_mr_;
platform::BlockMemoryResource media_block_mr_;
platform::storage::KeyValue storage_;
libcyphal::application::registry::Registry registry_;
Expand Down
26 changes: 17 additions & 9 deletions libcyphal_demo/src/exec_cmd_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "libcyphal/application/node.hpp"
#include "libcyphal/presentation/presentation.hpp"
#include "libcyphal/presentation/server.hpp"
#include "libcyphal/time_provider.hpp"
#include "libcyphal/transport/types.hpp"
#include "libcyphal/types.hpp"

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

return Derived{node, presentation, cetl::get<Server>(std::move(maybe_srv))};
return Derived{node, presentation, time_provider, cetl::get<Server>(std::move(maybe_srv))};
}

ExecCmdProvider(ExecCmdProvider&& other) noexcept
Expand Down Expand Up @@ -96,16 +101,19 @@ class ExecCmdProvider // NOSONAR cpp:S4963
/// The user should override the method to handle custom commands.
/// If the method returns `false`, the server will respond with a `STATUS_BAD_COMMAND` status.
///
/// @param command The command to be executed.
/// @param parameter The command parameter.
/// @param response The response to be sent back to the requester.
/// @param command The command to be executed.
/// @param parameter The command parameter.
/// @param metadata The transport RX metadata.
/// @param response The response to be sent back to the requester.
///
virtual bool onCommand(const Request::_traits_::TypeOf::command command,
const cetl::string_view parameter,
Response& response) noexcept
virtual bool onCommand(const Request::_traits_::TypeOf::command command,
const cetl::string_view parameter,
const libcyphal::transport::ServiceRxMetadata& metadata,
Response& response) noexcept
{
(void) command;
(void) parameter;
(void) metadata;
(void) response;

return false;
Expand All @@ -126,7 +134,7 @@ class ExecCmdProvider // NOSONAR cpp:S4963
server_.setOnRequestCallback([this](const auto& arg, auto continuation) {
//
Response response{alloc_};
if (!onCommand(arg.request.command, makeStringView(arg.request.parameter), response))
if (!onCommand(arg.request.command, makeStringView(arg.request.parameter), arg.metadata, response))
{
response.status = Response::STATUS_BAD_COMMAND;
}
Expand Down
Loading

0 comments on commit 287cbdf

Please sign in to comment.