mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 05:23:33 +08:00
uORB: Update code style
This commit is contained in:
@@ -67,7 +67,8 @@ public:
|
|||||||
SubscriptionBase(const struct orb_metadata *meta,
|
SubscriptionBase(const struct orb_metadata *meta,
|
||||||
unsigned interval = 0) :
|
unsigned interval = 0) :
|
||||||
_meta(meta),
|
_meta(meta),
|
||||||
_handle() {
|
_handle()
|
||||||
|
{
|
||||||
setHandle(orb_subscribe(getMeta()));
|
setHandle(orb_subscribe(getMeta()));
|
||||||
orb_set_interval(getHandle(), interval);
|
orb_set_interval(getHandle(), interval);
|
||||||
}
|
}
|
||||||
@@ -75,7 +76,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Check if there is a new update.
|
* Check if there is a new update.
|
||||||
* */
|
* */
|
||||||
bool updated() {
|
bool updated()
|
||||||
|
{
|
||||||
bool isUpdated = false;
|
bool isUpdated = false;
|
||||||
orb_check(_handle, &isUpdated);
|
orb_check(_handle, &isUpdated);
|
||||||
return isUpdated;
|
return isUpdated;
|
||||||
@@ -85,7 +87,8 @@ public:
|
|||||||
* Update the struct
|
* Update the struct
|
||||||
* @param data The uORB message struct we are updating.
|
* @param data The uORB message struct we are updating.
|
||||||
*/
|
*/
|
||||||
void update(void * data) {
|
void update(void *data)
|
||||||
|
{
|
||||||
if (updated()) {
|
if (updated()) {
|
||||||
orb_copy(_meta, _handle, data);
|
orb_copy(_meta, _handle, data);
|
||||||
}
|
}
|
||||||
@@ -94,7 +97,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Deconstructor
|
* Deconstructor
|
||||||
*/
|
*/
|
||||||
virtual ~SubscriptionBase() {
|
virtual ~SubscriptionBase()
|
||||||
|
{
|
||||||
orb_unsubscribe(_handle);
|
orb_unsubscribe(_handle);
|
||||||
}
|
}
|
||||||
// accessors
|
// accessors
|
||||||
@@ -142,8 +146,9 @@ public:
|
|||||||
unsigned interval = 0,
|
unsigned interval = 0,
|
||||||
List<SubscriptionNode *> *list = nullptr) :
|
List<SubscriptionNode *> *list = nullptr) :
|
||||||
SubscriptionBase(meta, interval),
|
SubscriptionBase(meta, interval),
|
||||||
_interval(interval) {
|
_interval(interval)
|
||||||
if (list != nullptr) list->add(this);
|
{
|
||||||
|
if (list != nullptr) { list->add(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,7 +195,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Create an update function that uses the embedded struct.
|
* Create an update function that uses the embedded struct.
|
||||||
*/
|
*/
|
||||||
void update() {
|
void update()
|
||||||
|
{
|
||||||
SubscriptionBase::update(getDataVoidPtr());
|
SubscriptionBase::update(getDataVoidPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ int orb_exists(const struct orb_metadata *meta, int instance)
|
|||||||
int orb_group_count(const struct orb_metadata *meta)
|
int orb_group_count(const struct orb_metadata *meta)
|
||||||
{
|
{
|
||||||
unsigned group_count = 0;
|
unsigned group_count = 0;
|
||||||
|
|
||||||
while (!uORB::Manager::get_instance()->orb_exists(meta, group_count++)) {};
|
while (!uORB::Manager::get_instance()->orb_exists(meta, group_count++)) {};
|
||||||
|
|
||||||
return group_count;
|
return group_count;
|
||||||
|
|||||||
@@ -89,11 +89,11 @@ uorb_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __PX4_QURT
|
#ifndef __PX4_QURT
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test the driver/device.
|
* Test the driver/device.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "test"))
|
if (!strcmp(argv[1], "test")) {
|
||||||
{
|
|
||||||
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||||
return t.test();
|
return t.test();
|
||||||
}
|
}
|
||||||
@@ -104,21 +104,24 @@ uorb_main(int argc, char *argv[])
|
|||||||
if (!strcmp(argv[1], "latency_test")) {
|
if (!strcmp(argv[1], "latency_test")) {
|
||||||
|
|
||||||
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||||
|
|
||||||
if (argc > 2 && !strcmp(argv[2], "medium")) {
|
if (argc > 2 && !strcmp(argv[2], "medium")) {
|
||||||
return t.latency_test<struct orb_test_medium>(ORB_ID(orb_test_medium), true);
|
return t.latency_test<struct orb_test_medium>(ORB_ID(orb_test_medium), true);
|
||||||
|
|
||||||
} else if (argc > 2 && !strcmp(argv[2], "large")) {
|
} else if (argc > 2 && !strcmp(argv[2], "large")) {
|
||||||
return t.latency_test<struct orb_test_large>(ORB_ID(orb_test_large), true);
|
return t.latency_test<struct orb_test_large>(ORB_ID(orb_test_large), true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return t.latency_test<struct orb_test>(ORB_ID(orb_test), true);
|
return t.latency_test<struct orb_test>(ORB_ID(orb_test), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print driver information.
|
* Print driver information.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "status"))
|
if (!strcmp(argv[1], "status")) {
|
||||||
{
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,9 @@ int uORB::Utils::node_mkpath(char *buf, Flavor f,
|
|||||||
len = snprintf(buf, orb_maxpath, "/%s/%s%d", (f == PUBSUB) ? "obj" : "param",
|
len = snprintf(buf, orb_maxpath, "/%s/%s%d", (f == PUBSUB) ? "obj" : "param",
|
||||||
orbMsgName, index);
|
orbMsgName, index);
|
||||||
|
|
||||||
if (len >= orb_maxpath)
|
if (len >= orb_maxpath) {
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user