aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--src/platforms/nuttx/module.mk5
-rw-r--r--src/platforms/nuttx/px4_nodehandle.cpp19
-rw-r--r--src/platforms/nuttx/px4_nuttx_impl.cpp5
-rw-r--r--src/platforms/px4_middleware.h9
-rw-r--r--src/platforms/px4_nodehandle.h19
-rw-r--r--src/platforms/ros/px4_ros_impl.cpp5
7 files changed, 24 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8eb81c92c..610284abe 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 1c0ad7aa4..4a2aff824 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 7930a0680..ec557e8aa 100644
--- a/src/platforms/nuttx/px4_nodehandle.cpp
+++ b/src/platforms/nuttx/px4_nodehandle.cpp
@@ -37,27 +37,8 @@
* PX4 Middleware Wrapper Nodehandle
*/
#include <px4.h>
-#include <platforms/px4_nodehandle.h>
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 22daee823..70e292320 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 462a06e97..dece72907 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 ced844fd5..eb90590e4 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 3aa976138..854986a7f 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();
-}
-
}