forked from Archive/PX4-Autopilot
uORB: Update code style
This commit is contained in:
parent
af1fe6ab9b
commit
c19c8a35b2
|
@ -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<SubscriptionNode *> * list=nullptr) :
|
||||
unsigned interval = 0,
|
||||
List<SubscriptionNode *> *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<SubscriptionNode *> * list=nullptr);
|
||||
unsigned interval = 0,
|
||||
List<SubscriptionNode *> *list = nullptr);
|
||||
/**
|
||||
* Deconstructor
|
||||
*/
|
||||
|
@ -190,7 +195,8 @@ public:
|
|||
/**
|
||||
* Create an update function that uses the embedded struct.
|
||||
*/
|
||||
void update() {
|
||||
void update()
|
||||
{
|
||||
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)
|
||||
{
|
||||
unsigned group_count = 0;
|
||||
|
||||
while (!uORB::Manager::get_instance()->orb_exists(meta, group_count++)) {};
|
||||
|
||||
return group_count;
|
||||
|
|
|
@ -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<struct orb_test_medium>(ORB_ID(orb_test_medium), true);
|
||||
|
||||
} else if (argc > 2 && !strcmp(argv[2], "large")) {
|
||||
return t.latency_test<struct orb_test_large>(ORB_ID(orb_test_large), true);
|
||||
|
||||
} else {
|
||||
return t.latency_test<struct orb_test>(ORB_ID(orb_test), true);
|
||||
}
|
||||
}
|
||||
|
||||
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||
if (argc > 2 && !strcmp(argv[2], "medium")) {
|
||||
return t.latency_test<struct orb_test_medium>(ORB_ID(orb_test_medium), true);
|
||||
} else if (argc > 2 && !strcmp(argv[2], "large")) {
|
||||
return t.latency_test<struct orb_test_large>(ORB_ID(orb_test_large), true);
|
||||
} else {
|
||||
return t.latency_test<struct orb_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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue