From c19c8a35b259a98cf360ed6c6bb7c1d635df19bf Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 19 Oct 2015 13:51:18 +0200 Subject: [PATCH] uORB: Update code style --- src/modules/uORB/Subscription.hpp | 34 +++++---- src/modules/uORB/uORB.cpp | 1 + src/modules/uORB/uORBMain.cpp | 123 +++++++++++++++--------------- src/modules/uORB/uORBUtils.cpp | 49 ++++++------ src/modules/uORB/uORBUtils.hpp | 24 +++--- 5 files changed, 121 insertions(+), 110 deletions(-) diff --git a/src/modules/uORB/Subscription.hpp b/src/modules/uORB/Subscription.hpp index 31842ed715..49fc9918a1 100644 --- a/src/modules/uORB/Subscription.hpp +++ b/src/modules/uORB/Subscription.hpp @@ -65,9 +65,10 @@ public: * between updates */ SubscriptionBase(const struct orb_metadata *meta, - unsigned interval=0) : + unsigned interval = 0) : _meta(meta), - _handle() { + _handle() + { setHandle(orb_subscribe(getMeta())); orb_set_interval(getHandle(), interval); } @@ -75,7 +76,8 @@ public: /** * Check if there is a new update. * */ - bool updated() { + bool updated() + { bool isUpdated = false; orb_check(_handle, &isUpdated); return isUpdated; @@ -85,7 +87,8 @@ public: * Update the struct * @param data The uORB message struct we are updating. */ - void update(void * data) { + void update(void *data) + { if (updated()) { orb_copy(_meta, _handle, data); } @@ -94,7 +97,8 @@ public: /** * Deconstructor */ - virtual ~SubscriptionBase() { + virtual ~SubscriptionBase() + { orb_unsubscribe(_handle); } // accessors @@ -108,9 +112,9 @@ protected: int _handle; private: // forbid copy - SubscriptionBase(const SubscriptionBase& other); + SubscriptionBase(const SubscriptionBase &other); // forbid assignment - SubscriptionBase& operator = (const SubscriptionBase &); + SubscriptionBase &operator = (const SubscriptionBase &); }; /** @@ -139,11 +143,12 @@ public: * that this should be appended to. */ SubscriptionNode(const struct orb_metadata *meta, - unsigned interval=0, - List * list=nullptr) : + unsigned interval = 0, + List *list = nullptr) : SubscriptionBase(meta, interval), - _interval(interval) { - if (list != nullptr) list->add(this); + _interval(interval) + { + if (list != nullptr) { list->add(this); } } /** @@ -179,8 +184,8 @@ public: * list during construction */ Subscription(const struct orb_metadata *meta, - unsigned interval=0, - List * list=nullptr); + unsigned interval = 0, + List *list = nullptr); /** * Deconstructor */ @@ -190,7 +195,8 @@ public: /** * Create an update function that uses the embedded struct. */ - void update() { + void update() + { SubscriptionBase::update(getDataVoidPtr()); } diff --git a/src/modules/uORB/uORB.cpp b/src/modules/uORB/uORB.cpp index 5a13a864c1..6d6f084d24 100644 --- a/src/modules/uORB/uORB.cpp +++ b/src/modules/uORB/uORB.cpp @@ -269,6 +269,7 @@ int orb_exists(const struct orb_metadata *meta, int instance) int orb_group_count(const struct orb_metadata *meta) { unsigned group_count = 0; + while (!uORB::Manager::get_instance()->orb_exists(meta, group_count++)) {}; return group_count; diff --git a/src/modules/uORB/uORBMain.cpp b/src/modules/uORB/uORBMain.cpp index 8b2930eaef..360b95a724 100644 --- a/src/modules/uORB/uORBMain.cpp +++ b/src/modules/uORB/uORBMain.cpp @@ -45,83 +45,86 @@ extern "C" { __EXPORT int uorb_main(int argc, char *argv[]); } static uORB::DeviceMaster *g_dev = nullptr; static void usage() { - warnx("Usage: uorb 'start', 'test', 'latency_test' or 'status'"); + warnx("Usage: uorb 'start', 'test', 'latency_test' or 'status'"); } int uorb_main(int argc, char *argv[]) { - if (argc < 2) { - usage(); - return -EINVAL; - } + if (argc < 2) { + usage(); + return -EINVAL; + } - /* - * Start/load the driver. - * - * XXX it would be nice to have a wrapper for this... - */ - if (!strcmp(argv[1], "start")) { + /* + * Start/load the driver. + * + * XXX it would be nice to have a wrapper for this... + */ + if (!strcmp(argv[1], "start")) { - if (g_dev != nullptr) { - warnx("already loaded"); - /* user wanted to start uorb, its already running, no error */ - return 0; - } + if (g_dev != nullptr) { + warnx("already loaded"); + /* user wanted to start uorb, its already running, no error */ + return 0; + } - /* create the driver */ - g_dev = new uORB::DeviceMaster(uORB::PUBSUB); + /* create the driver */ + g_dev = new uORB::DeviceMaster(uORB::PUBSUB); - if (g_dev == nullptr) { - warnx("driver alloc failed"); - return -ENOMEM; - } + if (g_dev == nullptr) { + warnx("driver alloc failed"); + return -ENOMEM; + } - if (OK != g_dev->init()) { - warnx("driver init failed"); - delete g_dev; - g_dev = nullptr; - return -EIO; - } + if (OK != g_dev->init()) { + warnx("driver init failed"); + delete g_dev; + g_dev = nullptr; + return -EIO; + } - return OK; - } + return OK; + } #ifndef __PX4_QURT - /* - * Test the driver/device. - */ - if (!strcmp(argv[1], "test")) - { - uORBTest::UnitTest &t = uORBTest::UnitTest::instance(); - return t.test(); - } - /* - * Test the latency. - */ - if (!strcmp(argv[1], "latency_test")) { + /* + * Test the driver/device. + */ + if (!strcmp(argv[1], "test")) { + uORBTest::UnitTest &t = uORBTest::UnitTest::instance(); + return t.test(); + } + + /* + * Test the latency. + */ + if (!strcmp(argv[1], "latency_test")) { + + uORBTest::UnitTest &t = uORBTest::UnitTest::instance(); + + if (argc > 2 && !strcmp(argv[2], "medium")) { + return t.latency_test(ORB_ID(orb_test_medium), true); + + } else if (argc > 2 && !strcmp(argv[2], "large")) { + return t.latency_test(ORB_ID(orb_test_large), true); + + } else { + return t.latency_test(ORB_ID(orb_test), true); + } + } - uORBTest::UnitTest &t = uORBTest::UnitTest::instance(); - if (argc > 2 && !strcmp(argv[2], "medium")) { - return t.latency_test(ORB_ID(orb_test_medium), true); - } else if (argc > 2 && !strcmp(argv[2], "large")) { - return t.latency_test(ORB_ID(orb_test_large), true); - } else { - return t.latency_test(ORB_ID(orb_test), true); - } - } #endif - /* - * Print driver information. - */ - if (!strcmp(argv[1], "status")) - { - return OK; - } + /* + * Print driver information. + */ + if (!strcmp(argv[1], "status")) { + return OK; + } - usage(); - return -EINVAL; + usage(); + return -EINVAL; } diff --git a/src/modules/uORB/uORBUtils.cpp b/src/modules/uORB/uORBUtils.cpp index a18fa1453a..4b4e76c170 100644 --- a/src/modules/uORB/uORBUtils.cpp +++ b/src/modules/uORB/uORBUtils.cpp @@ -37,45 +37,46 @@ int uORB::Utils::node_mkpath ( - char *buf, - Flavor f, - const struct orb_metadata *meta, - int *instance + char *buf, + Flavor f, + const struct orb_metadata *meta, + int *instance ) { - unsigned len; + unsigned len; - unsigned index = 0; + unsigned index = 0; - if (instance != nullptr) { - index = *instance; - } + if (instance != nullptr) { + index = *instance; + } - len = snprintf(buf, orb_maxpath, "/%s/%s%d", - (f == PUBSUB) ? "obj" : "param", - meta->o_name, index); + len = snprintf(buf, orb_maxpath, "/%s/%s%d", + (f == PUBSUB) ? "obj" : "param", + meta->o_name, index); - if (len >= orb_maxpath) { - return -ENAMETOOLONG; - } + if (len >= orb_maxpath) { + return -ENAMETOOLONG; + } - return OK; + return OK; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- int uORB::Utils::node_mkpath(char *buf, Flavor f, - const char *orbMsgName ) + const char *orbMsgName) { - unsigned len; + unsigned len; - unsigned index = 0; + unsigned index = 0; - len = snprintf(buf, orb_maxpath, "/%s/%s%d", (f == PUBSUB) ? "obj" : "param", - orbMsgName, index ); + len = snprintf(buf, orb_maxpath, "/%s/%s%d", (f == PUBSUB) ? "obj" : "param", + orbMsgName, index); - if (len >= orb_maxpath) - return -ENAMETOOLONG; + if (len >= orb_maxpath) { + return -ENAMETOOLONG; + } - return OK; + return OK; } diff --git a/src/modules/uORB/uORBUtils.hpp b/src/modules/uORB/uORBUtils.hpp index 522d255b26..4593f1a95e 100644 --- a/src/modules/uORB/uORBUtils.hpp +++ b/src/modules/uORB/uORBUtils.hpp @@ -38,24 +38,24 @@ namespace uORB { - class Utils; +class Utils; } class uORB::Utils { public: - static int node_mkpath - ( - char *buf, - Flavor f, - const struct orb_metadata *meta, - int *instance = nullptr - ); + static int node_mkpath + ( + char *buf, + Flavor f, + const struct orb_metadata *meta, + int *instance = nullptr + ); - /** - * same as above except this generators the path based on the string. - */ - static int node_mkpath(char *buf, Flavor f, const char *orbMsgName); + /** + * same as above except this generators the path based on the string. + */ + static int node_mkpath(char *buf, Flavor f, const char *orbMsgName); };