diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eb81c92ca..610284abee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,9 +102,6 @@ include_directories( ## Declare a cpp library add_library(px4 src/platforms/ros/px4_ros_impl.cpp - src/platforms/ros/px4_publisher.cpp - src/platforms/ros/px4_subscriber.cpp - src/platforms/ros/px4_nodehandle.cpp ) target_link_libraries(px4 diff --git a/src/platforms/nuttx/module.mk b/src/platforms/nuttx/module.mk index 1c0ad7aa45..4a2aff8249 100644 --- a/src/platforms/nuttx/module.mk +++ b/src/platforms/nuttx/module.mk @@ -35,9 +35,6 @@ # NuttX / uORB adapter library # -SRCS = px4_nuttx_impl.cpp \ - px4_publisher.cpp \ - px4_subscriber.cpp \ - px4_nodehandle.cpp +SRCS = px4_nuttx_impl.cpp MAXOPTIMIZATION = -Os diff --git a/src/platforms/nuttx/px4_nodehandle.cpp b/src/platforms/nuttx/px4_nodehandle.cpp index 7930a06807..ec557e8aa9 100644 --- a/src/platforms/nuttx/px4_nodehandle.cpp +++ b/src/platforms/nuttx/px4_nodehandle.cpp @@ -37,27 +37,8 @@ * PX4 Middleware Wrapper Nodehandle */ #include -#include namespace px4 { -bool task_should_exit = false; - - -void NodeHandle::spinOnce() { - /* Loop through subscriptions, call callback for updated subscriptions */ - uORB::SubscriptionNode *sub = _subs.getHead(); - int count = 0; - - while (sub != nullptr) { - if (count++ > kMaxSubscriptions) { - PX4_WARN("exceeded max subscriptions"); - break; - } - - sub->update(); - sub = sub->getSibling(); - } -} } diff --git a/src/platforms/nuttx/px4_nuttx_impl.cpp b/src/platforms/nuttx/px4_nuttx_impl.cpp index 22daee8234..70e2923208 100644 --- a/src/platforms/nuttx/px4_nuttx_impl.cpp +++ b/src/platforms/nuttx/px4_nuttx_impl.cpp @@ -54,9 +54,4 @@ uint64_t get_time_micros() return hrt_absolute_time(); } -bool ok() -{ - return !task_should_exit; -} - } diff --git a/src/platforms/px4_middleware.h b/src/platforms/px4_middleware.h index 462a06e97a..dece729070 100644 --- a/src/platforms/px4_middleware.h +++ b/src/platforms/px4_middleware.h @@ -49,7 +49,12 @@ __EXPORT void init(int argc, char *argv[], const char *process_name); __EXPORT uint64_t get_time_micros(); -__EXPORT bool ok(); +#if defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) +bool ok() { return ros::ok(); } +#else +extern bool task_should_exit; +bool ok() { return !task_should_exit; } +#endif class Rate { @@ -64,6 +69,4 @@ private: }; -extern bool task_should_exit; - } // namespace px4 diff --git a/src/platforms/px4_nodehandle.h b/src/platforms/px4_nodehandle.h index ced844fd5f..eb90590e41 100644 --- a/src/platforms/px4_nodehandle.h +++ b/src/platforms/px4_nodehandle.h @@ -41,6 +41,7 @@ /* includes for all platforms */ #include "px4_subscriber.h" #include "px4_publisher.h" +#include "px4_middleware.h" #if defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) /* includes when building for ros */ @@ -126,10 +127,24 @@ public: return pub; } - void spinOnce(); + void spinOnce() { + /* Loop through subscriptions, call callback for updated subscriptions */ + uORB::SubscriptionNode *sub = _subs.getHead(); + int count = 0; + + while (sub != nullptr) { + if (count++ > kMaxSubscriptions) { + PX4_WARN("exceeded max subscriptions"); + break; + } + + sub->update(); + sub = sub->getSibling(); + } + } void spin() { - while (true) { //XXX check for termination + while (ok()) { const int timeout_ms = 100; /* Only continue in the loop if the nodehandle has subscriptions */ if (_sub_min_interval == nullptr) { diff --git a/src/platforms/ros/px4_ros_impl.cpp b/src/platforms/ros/px4_ros_impl.cpp index 3aa9761380..854986a7f3 100644 --- a/src/platforms/ros/px4_ros_impl.cpp +++ b/src/platforms/ros/px4_ros_impl.cpp @@ -53,9 +53,4 @@ uint64_t get_time_micros() return time.sec * 1e6 + time.nsec / 1000; } -bool ok() -{ - return ros::ok(); -} - }