Skip to content

Commit

Permalink
Use latest setXxx methods of the Get Info Provider. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 authored Nov 12, 2024
1 parent 5e42cb0 commit 365dbc7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
[submodule "submodules/libcyphal"]
path = submodules/libcyphal
url = https://github.com/OpenCyphal-Garage/libcyphal.git
branch = issue/registry
branch = sshirokov/type_name
14 changes: 8 additions & 6 deletions libcyphal_demo/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <cetl/pf17/cetlpf.hpp>
#include <o1heap.h>

#include <uavcan/node/GetInfo_1_0.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -75,23 +73,27 @@ Application::~Application()

/// Returns the 128-bit unique-ID of the local node. This value is used in `uavcan.node.GetInfo.Response`.
///
void Application::getUniqueId(uavcan::node::GetInfo::Response_1_0::_traits_::TypeOf::unique_id& out)
Application::UniqueId Application::getUniqueId()
{
const auto result = storage_.get(".unique_id", out);
UniqueId out_unique_id = {};

const auto result = storage_.get(".unique_id", out_unique_id);
if (cetl::get_if<libcyphal::platform::storage::Error>(&result) != nullptr)
{
std::random_device rd; // Seed for the random number engine
std::mt19937 gen{rd()}; // Mersenne Twister engine
std::uniform_int_distribution<std::uint8_t> dis{0, 255}; // Distribution range for bytes

// Populate the default; it is only used at the first run.
for (auto& b : out)
for (auto& b : out_unique_id)
{
b = dis(gen);
}

(void) storage_.put(".unique_id", out);
(void) storage_.put(".unique_id", out_unique_id);
}

return out_unique_id;
}

Application::Regs::Value Application::Regs::getSysInfoMem() const
Expand Down
5 changes: 2 additions & 3 deletions libcyphal_demo/src/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <libcyphal/application/registry/registry_impl.hpp>
#include <libcyphal/platform/storage.hpp>

#include <uavcan/node/GetInfo_1_0.hpp>

#include <algorithm>
#include <array>
#include <cstddef>
Expand Down Expand Up @@ -227,7 +225,8 @@ class Application final

/// Returns the 128-bit unique-ID of the local node. This value is used in `uavcan.node.GetInfo.Response`.
///
void getUniqueId(uavcan::node::GetInfo::Response_1_0::_traits_::TypeOf::unique_id& out);
using UniqueId = std::array<std::uint8_t, 16>;
UniqueId getUniqueId();

private:
// MARK: Data members:
Expand Down
15 changes: 6 additions & 9 deletions libcyphal_demo/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,12 @@ libcyphal::Expected<bool, ExitCode> run_application()
//
// The hardware version is not populated in this demo because it runs on no specific hardware.
// An embedded node would usually determine the version by querying the hardware.
auto& get_info = node.getInfoProvider().response();
get_info.software_version.major = VERSION_MAJOR;
get_info.software_version.minor = VERSION_MINOR;
get_info.software_vcs_revision_id = VCS_REVISION_ID;
//
get_info.name.resize(node_params.description.value().size());
(void) std::memmove(get_info.name.data(), node_params.description.value().data(), get_info.name.size());
//
application.getUniqueId(get_info.unique_id);
auto& get_info_prov = node.getInfoProvider();
get_info_prov //
.setName(node_params.description.value())
.setSoftwareVersion(VERSION_MAJOR, VERSION_MINOR)
.setSoftwareVcsRevisionId(VCS_REVISION_ID)
.setUniqueId(application.getUniqueId());

// 5. Bring up registry provider.
//
Expand Down
2 changes: 1 addition & 1 deletion submodules/libcyphal

0 comments on commit 365dbc7

Please sign in to comment.