From acf91002787220ca4ae3d1caae7af087d68b871b Mon Sep 17 00:00:00 2001 From: Angel Date: Tue, 22 Jan 2019 11:17:31 +0100 Subject: [PATCH 01/10] Close replay log file after replay is finished, then exit. Need to implement exit method and add -q parameter --- src/modules/replay/replay_main.cpp | 4 +++- src/platforms/common/shutdown.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/replay/replay_main.cpp b/src/modules/replay/replay_main.cpp index b76fe1a01d27..4e4faff1c4e1 100644 --- a/src/modules/replay/replay_main.cpp +++ b/src/modules/replay/replay_main.cpp @@ -845,7 +845,9 @@ void Replay::run() PX4_INFO("Replay done (published %u msgs, %.3lf s)", nr_published_messages, (double)hrt_elapsed_time(&_replay_start_time) / 1.e6); - //TODO: should we close the log file & exit (optionally, by adding a parameter -q) ? + //TODO: add parameter -q? + replay_file.close(); + px4_request_shutdown(false, false); } onExitMainLoop(); diff --git a/src/platforms/common/shutdown.cpp b/src/platforms/common/shutdown.cpp index 870406265715..b4a8abec676a 100644 --- a/src/platforms/common/shutdown.cpp +++ b/src/platforms/common/shutdown.cpp @@ -205,6 +205,7 @@ void shutdown_worker(void *arg) int px4_shutdown_request(bool reboot, bool to_bootloader) { // fail immediately if the board does not support the requested method + //TODO: add method of shutting down for SITL and replay #if defined BOARD_HAS_NO_RESET if (reboot) { return -EINVAL; From fdc323d320250654973607f6b856171f65393655 Mon Sep 17 00:00:00 2001 From: Angel Date: Tue, 22 Jan 2019 11:39:47 +0100 Subject: [PATCH 02/10] missing shutdown header, fixed name of function call --- src/modules/replay/replay_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/replay/replay_main.cpp b/src/modules/replay/replay_main.cpp index 4e4faff1c4e1..4f959637ba1e 100644 --- a/src/modules/replay/replay_main.cpp +++ b/src/modules/replay/replay_main.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -847,7 +848,7 @@ void Replay::run() //TODO: add parameter -q? replay_file.close(); - px4_request_shutdown(false, false); + px4_shutdown_request(false, false); } onExitMainLoop(); From 94318ab55cdd5eb82c06d975cc0936e9a4ea815a Mon Sep 17 00:00:00 2001 From: Angel Date: Tue, 22 Jan 2019 14:28:27 +0100 Subject: [PATCH 03/10] Added shutdown method for SITL --- src/platforms/common/shutdown.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/platforms/common/shutdown.cpp b/src/platforms/common/shutdown.cpp index b4a8abec676a..a8256c7e6c01 100644 --- a/src/platforms/common/shutdown.cpp +++ b/src/platforms/common/shutdown.cpp @@ -191,7 +191,11 @@ void shutdown_worker(void *arg) } else { PX4_WARN("Shutdown NOW. Good Bye."); +#if defined __PX4_POSIX + px4_systemreset(shutdown_args & SHUTDOWN_ARG_TO_BOOTLOADER); +#else board_shutdown(); +#endif } pthread_mutex_unlock(&shutdown_mutex); // must NEVER come here @@ -205,7 +209,7 @@ void shutdown_worker(void *arg) int px4_shutdown_request(bool reboot, bool to_bootloader) { // fail immediately if the board does not support the requested method - //TODO: add method of shutting down for SITL and replay +#ifndef __PX4_POSIX #if defined BOARD_HAS_NO_RESET if (reboot) { return -EINVAL; @@ -218,6 +222,7 @@ int px4_shutdown_request(bool reboot, bool to_bootloader) return -EINVAL; } +#endif #endif if (shutdown_args & SHUTDOWN_ARG_IN_PROGRESS) { From a75c8811847860cc42fdc164dda7df47aec041a7 Mon Sep 17 00:00:00 2001 From: Angel Date: Tue, 22 Jan 2019 16:18:24 +0100 Subject: [PATCH 04/10] format --- src/platforms/common/shutdown.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platforms/common/shutdown.cpp b/src/platforms/common/shutdown.cpp index a8256c7e6c01..02857f0ce6ec 100644 --- a/src/platforms/common/shutdown.cpp +++ b/src/platforms/common/shutdown.cpp @@ -211,6 +211,7 @@ int px4_shutdown_request(bool reboot, bool to_bootloader) // fail immediately if the board does not support the requested method #ifndef __PX4_POSIX #if defined BOARD_HAS_NO_RESET + if (reboot) { return -EINVAL; } From e8c98ae2cc034cfdac7bcdc4e542534267fb2b04 Mon Sep 17 00:00:00 2001 From: Angel Date: Mon, 19 Aug 2019 11:47:45 +0200 Subject: [PATCH 05/10] Added shutdowm function for silt. Doesn't work, need to fix? --- boards/px4/sitl/src/CMakeLists.txt | 1 + boards/px4/sitl/src/sitl_board_shutdown.c | 49 +++++++++++++++++++++++ src/platforms/common/shutdown.cpp | 6 --- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 boards/px4/sitl/src/sitl_board_shutdown.c diff --git a/boards/px4/sitl/src/CMakeLists.txt b/boards/px4/sitl/src/CMakeLists.txt index 68f78c4ad7c6..ddbd1092858d 100644 --- a/boards/px4/sitl/src/CMakeLists.txt +++ b/boards/px4/sitl/src/CMakeLists.txt @@ -34,4 +34,5 @@ px4_add_library(drivers_board ${PX4_SOURCE_DIR}/src/drivers/boards/common/board_identity.c # TODO: this is horrible and should be fixed sitl_led.c + sitl_board_shutdown.c ) diff --git a/boards/px4/sitl/src/sitl_board_shutdown.c b/boards/px4/sitl/src/sitl_board_shutdown.c new file mode 100644 index 000000000000..6592f9b8a2d1 --- /dev/null +++ b/boards/px4/sitl/src/sitl_board_shutdown.c @@ -0,0 +1,49 @@ +/**************************************************************************** + * + * Copyright (c) 2013 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file sitl_board_shutdown.c + * + * sitl board shutdown backend. + */ + +#include + +__BEGIN_DECLS +extern int board_shutdown(void) noreturn_function; +__END_DECLS + +__EXPORT int board_shutdown() +{ + px4_systemreset(false); +} diff --git a/src/platforms/common/shutdown.cpp b/src/platforms/common/shutdown.cpp index 02857f0ce6ec..6d8b30107360 100644 --- a/src/platforms/common/shutdown.cpp +++ b/src/platforms/common/shutdown.cpp @@ -191,11 +191,7 @@ void shutdown_worker(void *arg) } else { PX4_WARN("Shutdown NOW. Good Bye."); -#if defined __PX4_POSIX - px4_systemreset(shutdown_args & SHUTDOWN_ARG_TO_BOOTLOADER); -#else board_shutdown(); -#endif } pthread_mutex_unlock(&shutdown_mutex); // must NEVER come here @@ -209,7 +205,6 @@ void shutdown_worker(void *arg) int px4_shutdown_request(bool reboot, bool to_bootloader) { // fail immediately if the board does not support the requested method -#ifndef __PX4_POSIX #if defined BOARD_HAS_NO_RESET if (reboot) { @@ -223,7 +218,6 @@ int px4_shutdown_request(bool reboot, bool to_bootloader) return -EINVAL; } -#endif #endif if (shutdown_args & SHUTDOWN_ARG_IN_PROGRESS) { From 3474c8d5dfe416ecb3891eb5ea0093034e92b1ae Mon Sep 17 00:00:00 2001 From: Angel Date: Mon, 19 Aug 2019 13:32:39 +0200 Subject: [PATCH 06/10] Removed empty line --- src/platforms/common/shutdown.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platforms/common/shutdown.cpp b/src/platforms/common/shutdown.cpp index 6d8b30107360..870406265715 100644 --- a/src/platforms/common/shutdown.cpp +++ b/src/platforms/common/shutdown.cpp @@ -206,7 +206,6 @@ int px4_shutdown_request(bool reboot, bool to_bootloader) { // fail immediately if the board does not support the requested method #if defined BOARD_HAS_NO_RESET - if (reboot) { return -EINVAL; } From 0f78b79635ebcbb5cafa5e5cad3857f1e6231c06 Mon Sep 17 00:00:00 2001 From: Angel Date: Mon, 19 Aug 2019 14:09:04 +0200 Subject: [PATCH 07/10] Changed defines. Now SITL has BOARD_HAS_POWER_CONTROL defined --- boards/px4/sitl/src/board_config.h | 2 +- boards/px4/sitl/src/sitl_board_shutdown.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/boards/px4/sitl/src/board_config.h b/boards/px4/sitl/src/board_config.h index ab201f26b238..376d867694a7 100644 --- a/boards/px4/sitl/src/board_config.h +++ b/boards/px4/sitl/src/board_config.h @@ -44,7 +44,7 @@ #define BOARD_BATTERY1_V_DIV (10.177939394f) #define BOARD_BATTERY1_A_PER_V (15.391030303f) -#define BOARD_HAS_NO_RESET +#define BOARD_HAS_POWER_CONTROL #define BOARD_HAS_NO_BOOTLOADER #define PX4_I2C_BUS_EXPANSION 1 diff --git a/boards/px4/sitl/src/sitl_board_shutdown.c b/boards/px4/sitl/src/sitl_board_shutdown.c index 6592f9b8a2d1..11a9850ff15f 100644 --- a/boards/px4/sitl/src/sitl_board_shutdown.c +++ b/boards/px4/sitl/src/sitl_board_shutdown.c @@ -38,9 +38,11 @@ */ #include +#include __BEGIN_DECLS extern int board_shutdown(void) noreturn_function; +static inline int board_register_power_state_notification_cb(power_button_state_notification_t cb) { return 0; } __END_DECLS __EXPORT int board_shutdown() From bdef13e7b73dbd6d2cc28579132764ef0f057df7 Mon Sep 17 00:00:00 2001 From: Angel Date: Tue, 20 Aug 2019 17:07:28 +0200 Subject: [PATCH 08/10] Added fix --- boards/px4/sitl/src/sitl_board_shutdown.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/boards/px4/sitl/src/sitl_board_shutdown.c b/boards/px4/sitl/src/sitl_board_shutdown.c index 11a9850ff15f..9ca9326a5365 100644 --- a/boards/px4/sitl/src/sitl_board_shutdown.c +++ b/boards/px4/sitl/src/sitl_board_shutdown.c @@ -38,14 +38,15 @@ */ #include -#include +#include -__BEGIN_DECLS -extern int board_shutdown(void) noreturn_function; -static inline int board_register_power_state_notification_cb(power_button_state_notification_t cb) { return 0; } -__END_DECLS +int board_register_power_state_notification_cb(power_button_state_notification_t cb) +{ + return 0; +} -__EXPORT int board_shutdown() +int board_shutdown() { px4_systemreset(false); + return 0; } From 5f09a079a3cd62c731ef3d1c2c05b5f683c37386 Mon Sep 17 00:00:00 2001 From: Angel Date: Wed, 21 Aug 2019 10:59:10 +0200 Subject: [PATCH 09/10] Added fixes for MAC compilation --- boards/px4/sitl/src/CMakeLists.txt | 2 ++ src/modules/simulator/ledsim/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/boards/px4/sitl/src/CMakeLists.txt b/boards/px4/sitl/src/CMakeLists.txt index fa201136aef9..0c925b02c734 100644 --- a/boards/px4/sitl/src/CMakeLists.txt +++ b/boards/px4/sitl/src/CMakeLists.txt @@ -36,3 +36,5 @@ add_library(drivers_board sitl_led.c sitl_board_shutdown.c ) + +add_dependencies(drivers_board prebuild_targets) diff --git a/src/modules/simulator/ledsim/CMakeLists.txt b/src/modules/simulator/ledsim/CMakeLists.txt index c8f9cbc012ed..b8d3ce64e019 100644 --- a/src/modules/simulator/ledsim/CMakeLists.txt +++ b/src/modules/simulator/ledsim/CMakeLists.txt @@ -32,4 +32,4 @@ ############################################################################ px4_add_library(drivers__ledsim led.cpp) -target_link_libraries(drivers__ledsim PRIVATE drivers__led drivers_board) +target_link_libraries(drivers__ledsim PRIVATE drivers__led) From a9bde7175a0e904ce9d8ce42153bc592b0467396 Mon Sep 17 00:00:00 2001 From: Angel Date: Tue, 27 Aug 2019 16:33:07 +0200 Subject: [PATCH 10/10] Review feedback --- boards/px4/sitl/src/CMakeLists.txt | 1 - platforms/posix/src/px4_layer/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/boards/px4/sitl/src/CMakeLists.txt b/boards/px4/sitl/src/CMakeLists.txt index 0c925b02c734..d3156ed0dcdf 100644 --- a/boards/px4/sitl/src/CMakeLists.txt +++ b/boards/px4/sitl/src/CMakeLists.txt @@ -37,4 +37,3 @@ add_library(drivers_board sitl_board_shutdown.c ) -add_dependencies(drivers_board prebuild_targets) diff --git a/platforms/posix/src/px4_layer/CMakeLists.txt b/platforms/posix/src/px4_layer/CMakeLists.txt index ffa06384614d..a7024ce972e2 100644 --- a/platforms/posix/src/px4_layer/CMakeLists.txt +++ b/platforms/posix/src/px4_layer/CMakeLists.txt @@ -56,7 +56,7 @@ add_library(px4_layer target_compile_definitions(px4_layer PRIVATE MODULE_NAME="px4") target_compile_options(px4_layer PRIVATE -Wno-cast-align) # TODO: fix and enable target_link_libraries(px4_layer PRIVATE work_queue px4_work_queue) -target_link_libraries(px4_layer PRIVATE px4_daemon) +target_link_libraries(px4_layer PRIVATE px4_daemon drivers_board) if(ENABLE_LOCKSTEP_SCHEDULER) target_link_libraries(px4_layer PRIVATE lockstep_scheduler)