mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-29 10:10:35 +08:00
extensive orb_advert_t fixes
The calls to orb_advertise were being mishandled throughout the code. There were ::close() calls on memory pointers, there were checks against < 0 when it is a pointer to a object and values larger than 0x7ffffffff are valid. Some places orb_advert_t variables were being initialized as 0 other places as -1. The orb_advert_t type was changed to uintptr_t so the pointer value would not be wrapped as a negative number. This was causing a failure on ARM. Tests for < 0 were changed to == 0 since a null pointer is the valid representation for error, or uninitialized. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
committed by
Lorenz Meier
parent
9a67303416
commit
a734fc96d1
@@ -135,7 +135,7 @@ __BEGIN_DECLS
|
||||
* a file-descriptor-based handle would not otherwise be in scope for the
|
||||
* publisher.
|
||||
*/
|
||||
typedef intptr_t orb_advert_t;
|
||||
typedef uintptr_t orb_advert_t;
|
||||
|
||||
/**
|
||||
* Advertise as the publisher of a topic.
|
||||
|
||||
@@ -89,18 +89,18 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
/* open the node as an advertiser */
|
||||
fd = node_open(PUBSUB, meta, data, true, instance, priority);
|
||||
if (fd == ERROR)
|
||||
return ERROR;
|
||||
return 0;
|
||||
|
||||
/* get the advertiser handle and close the node */
|
||||
result = ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser);
|
||||
close(fd);
|
||||
if (result == ERROR)
|
||||
return ERROR;
|
||||
return 0;
|
||||
|
||||
/* the advertiser must perform an initial publish to initialise the object */
|
||||
result = orb_publish(meta, advertiser, data);
|
||||
if (result == ERROR)
|
||||
return ERROR;
|
||||
return 0;
|
||||
|
||||
return advertiser;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
fd = node_open(PUBSUB, meta, data, true, instance, priority);
|
||||
if (fd == ERROR) {
|
||||
warnx("node_open as advertiser failed.");
|
||||
return ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get the advertiser handle and close the node */
|
||||
@@ -102,14 +102,14 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
px4_close(fd);
|
||||
if (result == ERROR) {
|
||||
warnx("px4_ioctl ORBIOCGADVERTISER failed. fd = %d", fd);
|
||||
return ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the advertiser must perform an initial publish to initialise the object */
|
||||
result = orb_publish(meta, advertiser, data);
|
||||
if (result == ERROR) {
|
||||
warnx("orb_publish failed");
|
||||
return ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return advertiser;
|
||||
|
||||
@@ -137,16 +137,17 @@ int uORBTest::UnitTest::pubsublatency_main(void)
|
||||
int uORBTest::UnitTest::test()
|
||||
{
|
||||
struct orb_test t, u;
|
||||
int pfd, sfd;
|
||||
int sfd;
|
||||
orb_advert_t ptopic;
|
||||
bool updated;
|
||||
|
||||
t.val = 0;
|
||||
pfd = orb_advertise(ORB_ID(orb_test), &t);
|
||||
ptopic = orb_advertise(ORB_ID(orb_test), &t);
|
||||
|
||||
if (pfd < 0)
|
||||
if (ptopic == 0)
|
||||
return test_fail("advertise failed: %d", errno);
|
||||
|
||||
test_note("publish handle 0x%08x", pfd);
|
||||
test_note("publish handle 0x%08x", ptopic);
|
||||
sfd = orb_subscribe(ORB_ID(orb_test));
|
||||
|
||||
if (sfd < 0)
|
||||
@@ -170,7 +171,7 @@ int uORBTest::UnitTest::test()
|
||||
t.val = 2;
|
||||
test_note("try publish");
|
||||
|
||||
if (PX4_OK != orb_publish(ORB_ID(orb_test), pfd, &t))
|
||||
if (PX4_OK != orb_publish(ORB_ID(orb_test), ptopic, &t))
|
||||
return test_fail("publish failed");
|
||||
|
||||
if (PX4_OK != orb_check(sfd, &updated))
|
||||
@@ -186,7 +187,6 @@ int uORBTest::UnitTest::test()
|
||||
return test_fail("copy(2) mismatch: %d expected %d", u.val, t.val);
|
||||
|
||||
orb_unsubscribe(sfd);
|
||||
close(pfd);
|
||||
|
||||
/* this routine tests the multi-topic support */
|
||||
test_note("try multi-topic support");
|
||||
@@ -197,7 +197,7 @@ int uORBTest::UnitTest::test()
|
||||
test_note("advertised");
|
||||
|
||||
int instance1;
|
||||
int pfd1 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance1, ORB_PRIO_MIN);
|
||||
orb_advert_t pfd1 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance1, ORB_PRIO_MIN);
|
||||
|
||||
if (instance0 != 0)
|
||||
return test_fail("mult. id0: %d", instance0);
|
||||
|
||||
@@ -98,7 +98,7 @@ int uORBTest::UnitTest::latency_test(orb_id_t T, bool print)
|
||||
t.val = 308;
|
||||
t.time = hrt_absolute_time();
|
||||
|
||||
int pfd0 = orb_advertise(T, &t);
|
||||
orb_advert_t pfd0 = orb_advertise(T, &t);
|
||||
|
||||
char * const args[1] = { NULL };
|
||||
|
||||
@@ -128,8 +128,6 @@ int uORBTest::UnitTest::latency_test(orb_id_t T, bool print)
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
px4_close(pfd0);
|
||||
|
||||
if (pubsub_task < 0) {
|
||||
return test_fail("failed launching task");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user