Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

info: expose new UUID (uid2) #629

Merged
merged 7 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions integration_tests/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ TEST_F(SitlTest, Info)
LogWarn() << "Product request result: " << Info::result_str(product_result.first);
}

std::pair<Info::Result, Info::Identification> identification_result =
info->get_identification();

EXPECT_EQ(identification_result.first, Info::Result::SUCCESS);

if (identification_result.first == Info::Result::SUCCESS) {
std::cout << "Hardware UUID: " << identification_result.second.hardware_uuid;
for (unsigned j = 0; j < sizeof(identification_result.second.hardware_uuid); ++j) {
std::cout << std::hex << std::setfill('0') << std::setw(2)
<< int(identification_result.second.hardware_uuid[j]);
}
std::cout << std::endl;
} else {
LogWarn() << "Identification request result: "
<< Info::result_str(identification_result.first);
}

std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
Expand Down
11 changes: 9 additions & 2 deletions plugins/info/include/plugins/info/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,22 @@ class Info : public PluginBase {
char product_name[32]; /**< @brief Name of product. */
};

/**
* @brief Type containing identification.
*/
struct Identification {
uint8_t hardware_uuid[18]; /**< @brief UUID of hardware. */
};

/**
* @brief Gets the UUID of the system.
*
* If possible this will be a unique identifier provided by hardware.
*
* @return a pair containing the result of the request and if successful,
* the UUID of the system.
* the identification information of the system.
*/
std::pair<Result, uint64_t> uuid() const;
std::pair<Result, Identification> get_identification() const;

/**
* @brief Get system version information.
Expand Down
4 changes: 2 additions & 2 deletions plugins/info/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Info::Info(System &system) : PluginBase(), _impl{new InfoImpl(system)} {}

Info::~Info() {}

std::pair<Info::Result, uint64_t> Info::uuid() const
std::pair<Info::Result, Info::Identification> Info::get_identification() const
{
return _impl->get_uuid();
return _impl->get_identification();
}

std::pair<Info::Result, Info::Version> Info::get_version() const
Expand Down
28 changes: 25 additions & 3 deletions plugins/info/info_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <functional>
#include <cstring>
#include "info_impl.h"
#include "system.h"
#include "global_include.h"
Expand Down Expand Up @@ -116,9 +117,28 @@ void InfoImpl::process_autopilot_version(const mavlink_message_t &message)
const char *product_name = product_id_str(autopilot_version.product_id);
STRNCPY(_product.product_name, product_name, sizeof(_product.product_name) - 1);

if (is_array_zero(autopilot_version.uid2, sizeof(autopilot_version.uid2))) {
std::memcpy(_identification.hardware_uuid,
reinterpret_cast<uint8_t *>(&autopilot_version.uid),
sizeof(autopilot_version.uid));
} else {
std::memcpy(
_identification.hardware_uuid, autopilot_version.uid2, sizeof(autopilot_version.uid2));
}

_information_received = true;
}

bool InfoImpl::is_array_zero(const uint8_t *arr, size_t len)
{
for (size_t i = 0; i < len; ++i) {
if (arr[i] != 0) {
return false;
}
}
return true;
}

void InfoImpl::translate_binary_to_str(uint8_t *binary,
unsigned binary_len,
char *str,
Expand All @@ -131,10 +151,12 @@ void InfoImpl::translate_binary_to_str(uint8_t *binary,
}
}

std::pair<Info::Result, uint64_t> InfoImpl::get_uuid() const
std::pair<Info::Result, Info::Identification> InfoImpl::get_identification() const
{
// TODO: this should be processed in this plugin
return std::make_pair<>(Info::Result::SUCCESS, _parent->get_uuid());
std::lock_guard<std::mutex> lock(_mutex);
return std::make_pair<>((_information_received ? Info::Result::SUCCESS :
Info::Result::INFORMATION_NOT_RECEIVED_YET),
_identification);
}

std::pair<Info::Result, Info::Version> InfoImpl::get_version() const
Expand Down
5 changes: 4 additions & 1 deletion plugins/info/info_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InfoImpl : public PluginImplBase {
void enable() override;
void disable() override;

std::pair<Info::Result, uint64_t> get_uuid() const;
std::pair<Info::Result, Info::Identification> get_identification() const;
std::pair<Info::Result, Info::Version> get_version() const;
std::pair<Info::Result, Info::Product> get_product() const;

Expand All @@ -34,6 +34,7 @@ class InfoImpl : public PluginImplBase {

Info::Version _version{};
Info::Product _product{};
Info::Identification _identification{};
bool _information_received{false};

void *_call_every_cookie{nullptr};
Expand All @@ -43,6 +44,8 @@ class InfoImpl : public PluginImplBase {

static void
translate_binary_to_str(uint8_t *binary, unsigned binary_len, char *str, unsigned str_len);

static bool is_array_zero(const uint8_t *arr, size_t len);
};

} // namespace dronecode_sdk