From b855d76f281d02ed69644c04fb0f88dffd22864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 25 Apr 2016 13:08:21 +0200 Subject: [PATCH] fix gps: subscribe to topics in the gps thread instead of the shell thread NuttX does not inherit file descriptors when creating new tasks. --- src/drivers/gps/gps.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index 32e383be08..7b62630e33 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -244,7 +244,7 @@ GPS::GPS(const char *uart_path, bool fake_gps, bool enable_sat_info) : } for (int i = 0; i < _orb_inject_data_fd_count; ++i) { - _orb_inject_data_fd[i] = orb_subscribe_multi(ORB_ID(gps_inject_data), i); + _orb_inject_data_fd[i] = -1; } } @@ -253,10 +253,6 @@ GPS::~GPS() /* tell the task we want it to go away */ _task_should_exit = true; - for (size_t i = 0; i < _orb_inject_data_fd_count; ++i) { - orb_unsubscribe(_orb_inject_data_fd[i]); - } - /* spin waiting for the task to stop */ for (unsigned i = 0; (i < 10) && (_task != -1); i++) { /* give it another 100ms */ @@ -538,6 +534,10 @@ GPS::task_main() fcntl(_serial_fd, F_SETFL, flags | O_NONBLOCK); #endif + for (int i = 0; i < _orb_inject_data_fd_count; ++i) { + _orb_inject_data_fd[i] = orb_subscribe_multi(ORB_ID(gps_inject_data), i); + } + uint64_t last_rate_measurement = hrt_absolute_time(); unsigned last_rate_count = 0; @@ -733,6 +733,11 @@ GPS::task_main() PX4_WARN("exiting"); + for (size_t i = 0; i < _orb_inject_data_fd_count; ++i) { + orb_unsubscribe(_orb_inject_data_fd[i]); + _orb_inject_data_fd[i] = -1; + } + ::close(_serial_fd); /* tell the dtor that we are exiting */