diff --git a/.gitmodules b/.gitmodules index 1d38cb7..e77180b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,3 +18,4 @@ [submodule "submodules/libcyphal"] path = submodules/libcyphal url = https://github.com/OpenCyphal-Garage/libcyphal.git + branch = sshirokov/412_rpc_clients diff --git a/libcyphal_demo/src/application.cpp b/libcyphal_demo/src/application.cpp index 07c3b88..11ee83d 100644 --- a/libcyphal_demo/src/application.cpp +++ b/libcyphal_demo/src/application.cpp @@ -28,9 +28,9 @@ alignas(O1HEAP_ALIGNMENT) std::array s_heap_arena{}; } // namespace -Application::Application() +Application::Application(const char* const root_path) : o1_heap_mr_{s_heap_arena} - , storage_{"/tmp/" NODE_NAME} + , storage_{root_path} , registry_{o1_heap_mr_} , media_block_mr_{*cetl::pmr::new_delete_resource()} , regs_{o1_heap_mr_, registry_, media_block_mr_} diff --git a/libcyphal_demo/src/application.hpp b/libcyphal_demo/src/application.hpp index 33b7e94..6b0cfe4 100644 --- a/libcyphal_demo/src/application.hpp +++ b/libcyphal_demo/src/application.hpp @@ -199,7 +199,7 @@ class Application final Regs::StringParam& description; }; - Application(); + explicit Application(const char* const root_path); ~Application(); Application(const Application&) = delete; diff --git a/libcyphal_demo/src/main.cpp b/libcyphal_demo/src/main.cpp index 0d41a44..4b3149a 100644 --- a/libcyphal_demo/src/main.cpp +++ b/libcyphal_demo/src/main.cpp @@ -16,8 +16,12 @@ #include #include +#include #include +#include #include +#include +#include #include #include // execve #include @@ -100,11 +104,20 @@ enum class ExitCode : std::uint8_t }; // ExitCode -libcyphal::Expected run_application() +void PrintUniqueIdTo(const std::array& unique_id, std::ostream& os) +{ + for (const auto byte : unique_id) + { + os << std::hex << std::setw(2) << std::setfill('0') << static_cast(byte); + } +} + +libcyphal::Expected run_application(const char* const root_path) { std::cout << "\n🟢 ***************** LibCyphal demo *******************\n"; + std::cout << "Root path : '" << root_path << "'\n"; - Application application; + Application application{root_path}; auto& executor = application.executor(); auto& general_mr = application.general_memory(); auto& media_block_mr = application.media_block_memory(); @@ -130,9 +143,13 @@ libcyphal::Expected run_application() // 2. Create the presentation layer object. // + const auto unique_id = application.getUniqueId(); (void) transport_iface->setLocalNodeId(node_params.id.value()[0]); std::cout << "Node ID : " << transport_iface->getLocalNodeId().value_or(65535) << "\n"; std::cout << "Node Name : '" << node_params.description.value().c_str() << "'\n"; + std::cout << "Unique-ID : "; + PrintUniqueIdTo(unique_id, std::cout); + std::cout << "\n"; libcyphal::presentation::Presentation presentation{general_mr, executor, *transport_iface}; // 3. Create the node object with name. @@ -156,7 +173,7 @@ libcyphal::Expected run_application() .setName(node_params.description.value()) .setSoftwareVersion(VERSION_MAJOR, VERSION_MINOR) .setSoftwareVcsRevisionId(VCS_REVISION_ID) - .setUniqueId(application.getUniqueId()); + .setUniqueId(unique_id); // // Update node's health according to states of memory resources. node.heartbeatProducer().setUpdateCallback([&](const auto& arg) { @@ -213,9 +230,15 @@ libcyphal::Expected run_application() } // namespace -int main(const int, char* const argv[]) +int main(const int argc, char* const argv[]) { - const auto result = run_application(); + const char* root_path = "/tmp/" NODE_NAME; // NOLINT + if (argc > 1) + { + root_path = argv[1]; // NOLINT + } + + const auto result = run_application(root_path); if (const auto* const err = cetl::get_if(&result)) { return static_cast(*err); diff --git a/libcyphal_demo/src/platform/storage.hpp b/libcyphal_demo/src/platform/storage.hpp index 8f29d4d..1abf947 100644 --- a/libcyphal_demo/src/platform/storage.hpp +++ b/libcyphal_demo/src/platform/storage.hpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include diff --git a/submodules/libcyphal b/submodules/libcyphal index f66b8a6..21cb8a1 160000 --- a/submodules/libcyphal +++ b/submodules/libcyphal @@ -1 +1 @@ -Subproject commit f66b8a676dd6a78a79a8051e6db0c9d9e954d8a2 +Subproject commit 21cb8a1b0308229e4aa57f5c5fd81c9a7806161f