From 528ca931af9795e98676e97743c35fe18ab6901d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 12 Aug 2016 17:59:17 +0200 Subject: [PATCH] logger: only add data message to the log if orb_copy succeeds, when adding a new instance --- src/modules/logger/logger.cpp | 9 ++++++--- src/modules/uORB/uORBManager.hpp | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index 3d28988d98..dfc7f2b426 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -441,7 +441,7 @@ bool Logger::copy_if_updated_multi(LoggerSubscription &sub, int multi_instance, if (OK == orb_exists(sub.metadata, multi_instance)) { handle = orb_subscribe_multi(sub.metadata, multi_instance); - //PX4_INFO("subscribed to instance %d of topic %s", multi_instance, topic->o_name); + //PX4_INFO("subscribed to instance %d of topic %s", multi_instance, sub.metadata->o_name); /* copy first data */ if (handle >= 0) { @@ -454,8 +454,11 @@ bool Logger::copy_if_updated_multi(LoggerSubscription &sub, int multi_instance, orb_set_interval(handle, interval); } - orb_copy(sub.metadata, handle, buffer); - updated = true; + /* It can happen that orb_exists returns true, even if there is no publisher (but another subscriber). + * We catch this here, because orb_copy will fail in this case. */ + if (orb_copy(sub.metadata, handle, buffer) == PX4_OK) { + updated = true; + } } } diff --git a/src/modules/uORB/uORBManager.hpp b/src/modules/uORB/uORBManager.hpp index f64231747d..6c7c6245f3 100644 --- a/src/modules/uORB/uORBManager.hpp +++ b/src/modules/uORB/uORBManager.hpp @@ -295,7 +295,8 @@ public: int orb_stat(int handle, uint64_t *time) ; /** - * Check if a topic has already been created. + * Check if a topic has already been created (a publisher or a subscriber exists with + * the given instance). * * @param meta ORB topic metadata. * @param instance ORB instance