From 21f403e12b1c800c3e4bd901c363a886736f6466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 6 Apr 2016 10:02:21 +0200 Subject: [PATCH] gps: make sure the gps module compiles for POSIX & add it to the posix_sitl_default cmake - Note that the simulator still uses gpssim by default - now the gps module can be used in the SITL. this makes it possible to test the real gps HW under POSIX additional steps needed to use it: - in the rcS_jmavsim_iris, make sure to start the gps instead of gpssim: gps start -d /dev/ttyACM0 -s - disable the mavlink serial connection in simulator_mavlink.cpp, openUart(PIXHAWK_DEVICE, 115200); - this also fixes a memory leak in the gps module --- cmake/configs/posix_sitl_default.cmake | 1 + src/drivers/gps/gps.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmake/configs/posix_sitl_default.cmake b/cmake/configs/posix_sitl_default.cmake index 2ccdb33daa..344674aef7 100644 --- a/cmake/configs/posix_sitl_default.cmake +++ b/cmake/configs/posix_sitl_default.cmake @@ -11,6 +11,7 @@ set(config_module_list platforms/posix/work_queue platforms/posix/drivers/adcsim platforms/posix/drivers/gpssim + drivers/gps platforms/posix/drivers/tonealrmsim platforms/posix/drivers/accelsim platforms/posix/drivers/airspeedsim diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index 6ceb12c490..94d1269519 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -37,8 +37,10 @@ */ #ifndef __PX4_QURT +#ifdef __PX4_NUTTX #include #include +#endif #include #endif @@ -190,7 +192,7 @@ GPS::GPS(const char *uart_path, bool fake_gps, bool enable_sat_info) : /* create satellite info data object if requested */ if (enable_sat_info) { - _Sat_Info = new(GPS_Sat_Info); + _Sat_Info = new GPS_Sat_Info(); _p_report_sat_info = &_Sat_Info->_data; memset(_p_report_sat_info, 0, sizeof(*_p_report_sat_info)); } @@ -212,6 +214,8 @@ GPS::~GPS() px4_task_delete(_task); } + if (_Sat_Info) delete (_Sat_Info); + g_dev = nullptr; } @@ -245,13 +249,11 @@ GPS::task_main() _serial_fd = ::open(_port, O_RDWR); if (_serial_fd < 0) { - while (true) { - PX4_WARN("failed to open serial port: %s err: %d", _port, errno); - } + PX4_ERR("GPS: failed to open serial port: %s err: %d", _port, errno); /* tell the dtor that we are exiting, set error code */ _task = -1; - exit(1); + px4_task_exit(1); } #ifndef __PX4_QURT @@ -617,12 +619,11 @@ void info() { if (g_dev == nullptr) { - errx(1, "not running"); + PX4_ERR("GPS Not running"); + return; } g_dev->print_info(); - - return; } } // namespace