From df5d702baefae7f51161d170c911cb398f418538 Mon Sep 17 00:00:00 2001 From: Anton Babushkin Date: Sun, 16 Mar 2014 17:03:39 +0400 Subject: [PATCH 1/2] mavlink: MavlinkOrbSubscription.update() result fixed --- src/modules/mavlink/mavlink_orb_subscription.cpp | 11 +++++++---- src/modules/mavlink/mavlink_orb_subscription.h | 13 +++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/modules/mavlink/mavlink_orb_subscription.cpp b/src/modules/mavlink/mavlink_orb_subscription.cpp index 9963184683..e8f9bb75ba 100644 --- a/src/modules/mavlink/mavlink_orb_subscription.cpp +++ b/src/modules/mavlink/mavlink_orb_subscription.cpp @@ -78,12 +78,15 @@ MavlinkOrbSubscription::get_data() bool MavlinkOrbSubscription::update(const hrt_abstime t) { - if (_last_check != t) { + if (_last_check == t) { + /* already checked right now, return result of the check */ + return _updated; + + } else { _last_check = t; - bool updated; - orb_check(_fd, &updated); + orb_check(_fd, &_updated); - if (updated) { + if (_updated) { orb_copy(_topic, _fd, _data); return true; } diff --git a/src/modules/mavlink/mavlink_orb_subscription.h b/src/modules/mavlink/mavlink_orb_subscription.h index 42d47e96ed..8529721c03 100644 --- a/src/modules/mavlink/mavlink_orb_subscription.h +++ b/src/modules/mavlink/mavlink_orb_subscription.h @@ -48,7 +48,7 @@ class MavlinkOrbSubscription { public: - MavlinkOrbSubscription *next; + MavlinkOrbSubscription *next; /*< pointer to next subscription in list */ MavlinkOrbSubscription(const orb_id_t topic); ~MavlinkOrbSubscription(); @@ -66,11 +66,12 @@ public: const orb_id_t get_topic(); private: - const orb_id_t _topic; - int _fd; - bool _published; - void *_data; - hrt_abstime _last_check; + const orb_id_t _topic; /*< topic metadata */ + int _fd; /*< subscription handle */ + bool _published; /*< topic was ever published */ + void *_data; /*< pointer to data buffer */ + hrt_abstime _last_check; /*< time of last check */ + bool _updated; /*< updated on last check */ }; From 762e8f52893afee6e8ffb6a728e5bc88518829c3 Mon Sep 17 00:00:00 2001 From: Anton Babushkin Date: Sun, 16 Mar 2014 17:28:34 +0400 Subject: [PATCH 2/2] mavlink_orb_subscription: minor optimization and comment fix --- src/modules/mavlink/mavlink_orb_subscription.cpp | 4 ++++ src/modules/mavlink/mavlink_orb_subscription.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/mavlink/mavlink_orb_subscription.cpp b/src/modules/mavlink/mavlink_orb_subscription.cpp index e8f9bb75ba..4de7228324 100644 --- a/src/modules/mavlink/mavlink_orb_subscription.cpp +++ b/src/modules/mavlink/mavlink_orb_subscription.cpp @@ -98,6 +98,10 @@ MavlinkOrbSubscription::update(const hrt_abstime t) bool MavlinkOrbSubscription::is_published() { + if (_published) { + return true; + } + bool updated; orb_check(_fd, &updated); diff --git a/src/modules/mavlink/mavlink_orb_subscription.h b/src/modules/mavlink/mavlink_orb_subscription.h index 8529721c03..5c6543e813 100644 --- a/src/modules/mavlink/mavlink_orb_subscription.h +++ b/src/modules/mavlink/mavlink_orb_subscription.h @@ -59,7 +59,7 @@ public: * Check if the topic has been published. * * This call will return true if the topic was ever published. - * @param true if the topic has been published at least once. + * @return true if the topic has been published at least once. */ bool is_published(); void *get_data();