Skip to content

Commit

Permalink
info: add vendor and product ID and name
Browse files Browse the repository at this point in the history
This adds the vendor and product ID and name back.
  • Loading branch information
julianoes committed Oct 17, 2017
1 parent b2cffb4 commit f96c303
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
6 changes: 6 additions & 0 deletions integration_tests/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ TEST_F(SitlTest, Info)
// FIXME: This is currently 0.
//EXPECT_NE(version.os_sw_major, 0);


Info::Product product = dc.device().info().get_product();

std::cout << "Vendor: " << product.vendor_name << std::endl;
std::cout << "Product: " << product.product_name << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
Expand Down
5 changes: 5 additions & 0 deletions plugins/info/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ Info::Version Info::get_version() const
return _impl->get_version();
}

Info::Product Info::get_product() const
{
return _impl->get_product();
}

} // namespace dronecore
19 changes: 17 additions & 2 deletions plugins/info/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ class Info
int os_sw_minor; /**< @brief Operating system software minor version. */
int os_sw_patch; /**< @brief Operating system software patch version. */
char os_sw_git_hash[GIT_HASH_STR_LEN];/**< @brief Operating system software git hash as string. */
uint16_t vendor_id; /**< @brief ID of board vendor. */
uint16_t product_id; /**< @brief ID of product. */
};

/**
* @brief Type containing device product information.
*/
struct Product {
int vendor_id; /**< @brief ID of board vendor. */
char vendor_name[32]; /**< @brief Name of vendor. */
int product_id; /**< @brief ID of product. */
char product_name[32]; /**< @brief Name of product. */
};

/**
Expand All @@ -71,6 +79,13 @@ class Info
*/
Version get_version() const;

/**
* @brief Get device product information.
*
* @return The product object for the device.
*/
Product get_product() const;

// Non-copyable
/**
* @brief Copy Constructor (object is not copyable).
Expand Down
47 changes: 46 additions & 1 deletion plugins/info/info_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void InfoImpl::process_autopilot_version(const mavlink_message_t &message)

mavlink_msg_autopilot_version_decode(&message, &autopilot_version);

Info::Version version = {};
Info::Version version {};

version.flight_sw_major = (autopilot_version.flight_sw_version >> (8 * 3)) & 0xFF;
version.flight_sw_minor = (autopilot_version.flight_sw_version >> (8 * 2)) & 0xFF;
Expand Down Expand Up @@ -92,6 +92,18 @@ void InfoImpl::process_autopilot_version(const mavlink_message_t &message)
Info::GIT_HASH_STR_LEN);

set_version(version);

Info::Product product {};

product.vendor_id = autopilot_version.vendor_id;
const char *vendor_name = vendor_id_str(autopilot_version.vendor_id);
STRNCPY(product.vendor_name, vendor_name, sizeof(product.vendor_name));

product.product_id = autopilot_version.product_id;
const char *product_name = product_id_str(autopilot_version.product_id);
STRNCPY(product.product_name, product_name, sizeof(product.product_name));

set_product(product);
}

void InfoImpl::translate_binary_to_str(uint8_t *binary, unsigned binary_len,
Expand Down Expand Up @@ -131,11 +143,44 @@ Info::Version InfoImpl::get_version() const
return _version;
}

Info::Product InfoImpl::get_product() const
{
std::lock_guard<std::mutex> lock(_product_mutex);
return _product;
}

void InfoImpl::set_version(Info::Version version)
{
std::lock_guard<std::mutex> lock(_version_mutex);
_version = version;
}

void InfoImpl::set_product(Info::Product product)
{
std::lock_guard<std::mutex> lock(_product_mutex);
_product = product;
}

const char *InfoImpl::vendor_id_str(uint16_t vendor_id)
{
switch (vendor_id) {
case 0x26ac:
return "Yuneec";
default:
return "undefined";
}
}

const char *InfoImpl::product_id_str(uint16_t product_id)
{
switch (product_id) {
case 0x0010:
return "H520";
default:
return "undefined";
}
}



} // namespace dronecore
8 changes: 8 additions & 0 deletions plugins/info/info_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ class InfoImpl : public PluginImplBase
uint64_t get_uuid() const;
bool is_complete() const;
Info::Version get_version() const;
Info::Product get_product() const;

void init() override;
void deinit() override;

private:
void set_version(Info::Version version);
void set_product(Info::Product product);

void process_heartbeat(const mavlink_message_t &message);
void process_autopilot_version(const mavlink_message_t &message);

mutable std::mutex _version_mutex;
Info::Version _version = {};

mutable std::mutex _product_mutex;
Info::Product _product = {};

static const char *vendor_id_str(uint16_t vendor_id);
static const char *product_id_str(uint16_t product_id);

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

0 comments on commit f96c303

Please sign in to comment.