Skip to content

Commit 365dbc7

Browse files
authored
Use latest setXxx methods of the Get Info Provider. (#29)
1 parent 5e42cb0 commit 365dbc7

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
[submodule "submodules/libcyphal"]
1717
path = submodules/libcyphal
1818
url = https://github.com/OpenCyphal-Garage/libcyphal.git
19-
branch = issue/registry
19+
branch = sshirokov/type_name

libcyphal_demo/src/application.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <cetl/pf17/cetlpf.hpp>
1313
#include <o1heap.h>
1414

15-
#include <uavcan/node/GetInfo_1_0.hpp>
16-
1715
#include <array>
1816
#include <cstddef>
1917
#include <cstdint>
@@ -75,23 +73,27 @@ Application::~Application()
7573

7674
/// Returns the 128-bit unique-ID of the local node. This value is used in `uavcan.node.GetInfo.Response`.
7775
///
78-
void Application::getUniqueId(uavcan::node::GetInfo::Response_1_0::_traits_::TypeOf::unique_id& out)
76+
Application::UniqueId Application::getUniqueId()
7977
{
80-
const auto result = storage_.get(".unique_id", out);
78+
UniqueId out_unique_id = {};
79+
80+
const auto result = storage_.get(".unique_id", out_unique_id);
8181
if (cetl::get_if<libcyphal::platform::storage::Error>(&result) != nullptr)
8282
{
8383
std::random_device rd; // Seed for the random number engine
8484
std::mt19937 gen{rd()}; // Mersenne Twister engine
8585
std::uniform_int_distribution<std::uint8_t> dis{0, 255}; // Distribution range for bytes
8686

8787
// Populate the default; it is only used at the first run.
88-
for (auto& b : out)
88+
for (auto& b : out_unique_id)
8989
{
9090
b = dis(gen);
9191
}
9292

93-
(void) storage_.put(".unique_id", out);
93+
(void) storage_.put(".unique_id", out_unique_id);
9494
}
95+
96+
return out_unique_id;
9597
}
9698

9799
Application::Regs::Value Application::Regs::getSysInfoMem() const

libcyphal_demo/src/application.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <libcyphal/application/registry/registry_impl.hpp>
1818
#include <libcyphal/platform/storage.hpp>
1919

20-
#include <uavcan/node/GetInfo_1_0.hpp>
21-
2220
#include <algorithm>
2321
#include <array>
2422
#include <cstddef>
@@ -227,7 +225,8 @@ class Application final
227225

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

232231
private:
233232
// MARK: Data members:

libcyphal_demo/src/main.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,12 @@ libcyphal::Expected<bool, ExitCode> run_application()
150150
//
151151
// The hardware version is not populated in this demo because it runs on no specific hardware.
152152
// An embedded node would usually determine the version by querying the hardware.
153-
auto& get_info = node.getInfoProvider().response();
154-
get_info.software_version.major = VERSION_MAJOR;
155-
get_info.software_version.minor = VERSION_MINOR;
156-
get_info.software_vcs_revision_id = VCS_REVISION_ID;
157-
//
158-
get_info.name.resize(node_params.description.value().size());
159-
(void) std::memmove(get_info.name.data(), node_params.description.value().data(), get_info.name.size());
160-
//
161-
application.getUniqueId(get_info.unique_id);
153+
auto& get_info_prov = node.getInfoProvider();
154+
get_info_prov //
155+
.setName(node_params.description.value())
156+
.setSoftwareVersion(VERSION_MAJOR, VERSION_MINOR)
157+
.setSoftwareVcsRevisionId(VCS_REVISION_ID)
158+
.setUniqueId(application.getUniqueId());
162159

163160
// 5. Bring up registry provider.
164161
//

0 commit comments

Comments
 (0)