mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 10:40:35 +08:00
Improvements to SITL to make paths more flexible. (#5181)
This commit is contained in:
@@ -10,7 +10,7 @@ add_executable(firmware_nuttx
|
||||
builtin_commands.c)
|
||||
|
||||
|
||||
set(nuttx_export_dir ${CMAKE_BINARY_DIR}/${BOARD}/NuttX/nuttx-export)
|
||||
set(nuttx_export_dir ${PX4_BINARY_DIR}/${BOARD}/NuttX/nuttx-export)
|
||||
|
||||
set(link_libs
|
||||
romfs apps nuttx m gcc
|
||||
@@ -20,7 +20,7 @@ if(NOT ${BOARD} STREQUAL "sim")
|
||||
list(APPEND link_libs nosys)
|
||||
set(main_link_flags
|
||||
"-T${nuttx_export_dir}/build/ld.script"
|
||||
"-Wl,-Map=${CMAKE_BINARY_DIR}/${BOARD}/main.map"
|
||||
"-Wl,-Map=${PX4_BINARY_DIR}/${BOARD}/main.map"
|
||||
)
|
||||
px4_join(OUT main_link_flags LIST ${main_link_flags} GLUE " ")
|
||||
set_target_properties(firmware_nuttx PROPERTIES LINK_FLAGS ${main_link_flags})
|
||||
@@ -43,12 +43,12 @@ add_custom_target(check_weak
|
||||
if(NOT ${BOARD} STREQUAL "sim")
|
||||
|
||||
if (config_io_board)
|
||||
set(extras "${CMAKE_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}.bin")
|
||||
set(extras "${PX4_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}.bin")
|
||||
endif()
|
||||
|
||||
set(romfs_dir "ROMFS/px4fmu_common")
|
||||
if (${BOARD} STREQUAL "tap-v1")
|
||||
set(romfs_dir "ROMFS/tap_common")
|
||||
set(romfs_dir "ROMFS/tap_common")
|
||||
endif()
|
||||
if (${BOARD} STREQUAL "px4fmu-v2" AND ${LABEL} STREQUAL "test")
|
||||
set(romfs_dir "ROMFS/px4fmu_test")
|
||||
@@ -68,8 +68,8 @@ if(NOT ${BOARD} STREQUAL "sim")
|
||||
px4_nuttx_add_firmware(OUT ${fw_file}
|
||||
BOARD ${BOARD}
|
||||
EXE ${CMAKE_CURRENT_BINARY_DIR}/firmware_nuttx
|
||||
PARAM_XML ${CMAKE_BINARY_DIR}/parameters.xml
|
||||
AIRFRAMES_XML ${CMAKE_BINARY_DIR}/airframes.xml
|
||||
PARAM_XML ${PX4_BINARY_DIR}/parameters.xml
|
||||
AIRFRAMES_XML ${PX4_BINARY_DIR}/airframes.xml
|
||||
)
|
||||
|
||||
configure_file(gdbinit.in .gdbinit)
|
||||
@@ -94,21 +94,21 @@ if(NOT ${BOARD} STREQUAL "sim")
|
||||
|
||||
add_custom_target(debug_io
|
||||
COMMAND ${GDB}
|
||||
${CMAKE_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}
|
||||
${PX4_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}
|
||||
DEPENDS firmware_nuttx
|
||||
${CMAKE_CURRENT_BINARY_DIR}/.gdbinit
|
||||
)
|
||||
|
||||
add_custom_target(debug_io_tui
|
||||
COMMAND ${GDBTUI}
|
||||
${CMAKE_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}
|
||||
${PX4_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}
|
||||
DEPENDS firmware_nuttx
|
||||
${CMAKE_CURRENT_BINARY_DIR}/.gdbinit
|
||||
)
|
||||
|
||||
add_custom_target(debug_io_ddd
|
||||
COMMAND ${DDD} --debugger ${GDB}
|
||||
${CMAKE_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}
|
||||
${PX4_BINARY_DIR}/src/modules/px4iofirmware/${config_io_board}
|
||||
DEPENDS firmware_nuttx
|
||||
${CMAKE_CURRENT_BINARY_DIR}/.gdbinit
|
||||
)
|
||||
|
||||
@@ -4,4 +4,4 @@ attach 1
|
||||
monitor vector_catch disable hard
|
||||
set mem inaccessible-by-default off
|
||||
set print pretty
|
||||
source ${CMAKE_SOURCE_DIR}/Debug/PX4
|
||||
source ${PX4_SOURCE_DIR}/Debug/PX4
|
||||
|
||||
@@ -18,7 +18,7 @@ if ("${BOARD}" STREQUAL "eagle" OR ("${BOARD}" STREQUAL "excelsior"))
|
||||
APPS_DEST "/home/linaro"
|
||||
SOURCES
|
||||
px4muorb_stub.c
|
||||
${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
${PX4_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
apps.h
|
||||
LINK_LIBS
|
||||
-Wl,--start-group
|
||||
@@ -33,14 +33,14 @@ if ("${BOARD}" STREQUAL "eagle" OR ("${BOARD}" STREQUAL "excelsior"))
|
||||
OS ${OS}
|
||||
BOARD ${BOARD}
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/px4
|
||||
${CMAKE_SOURCE_DIR}/posix-configs/eagle/flight/mainapp.config
|
||||
${PX4_SOURCE_DIR}/posix-configs/eagle/flight/mainapp.config
|
||||
DEPENDS px4
|
||||
DEST /home/linaro)
|
||||
|
||||
elseif ("${BOARD}" STREQUAL "rpi")
|
||||
|
||||
add_executable(px4
|
||||
${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
${PX4_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
apps.h
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ elseif ("${BOARD}" STREQUAL "rpi")
|
||||
OS ${OS}
|
||||
BOARD ${BOARD}
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/px4
|
||||
${CMAKE_SOURCE_DIR}/posix-configs/rpi/px4.config
|
||||
${PX4_SOURCE_DIR}/posix-configs/rpi/px4.config
|
||||
DEPENDS px4
|
||||
DEST /home/pi)
|
||||
|
||||
@@ -67,7 +67,7 @@ elseif ("${BOARD}" STREQUAL "bebop")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
|
||||
|
||||
add_executable(px4
|
||||
${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
${PX4_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
apps.h
|
||||
)
|
||||
|
||||
@@ -91,14 +91,14 @@ elseif ("${BOARD}" STREQUAL "bebop")
|
||||
OS ${OS}
|
||||
BOARD ${BOARD}
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/px4
|
||||
${CMAKE_SOURCE_DIR}/posix-configs/bebop/px4.config
|
||||
${PX4_SOURCE_DIR}/posix-configs/bebop/px4.config
|
||||
DEPENDS px4
|
||||
DEST /usr/bin)
|
||||
|
||||
else()
|
||||
|
||||
add_executable(px4
|
||||
${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
${PX4_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||
apps.h
|
||||
)
|
||||
if (NOT APPLE)
|
||||
@@ -118,17 +118,43 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#=============================================================================
|
||||
# sitl run targets
|
||||
#
|
||||
|
||||
set(SITL_WORKING_DIR ${PX4_BINARY_DIR}/tmp)
|
||||
file(MAKE_DIRECTORY ${SITL_WORKING_DIR})
|
||||
|
||||
add_custom_target(run_config
|
||||
COMMAND Tools/sitl_run.sh "${config_sitl_rcS}" "${config_sitl_debugger}"
|
||||
"${config_sitl_viewer}" "${config_sitl_model}" "${CMAKE_BINARY_DIR}"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND Tools/sitl_run.sh
|
||||
"$<TARGET_FILE:px4>"
|
||||
"${config_sitl_rcS}"
|
||||
"${config_sitl_debugger}"
|
||||
"${config_sitl_viewer}"
|
||||
"${config_sitl_model}"
|
||||
"${PX4_SOURCE_DIR}"
|
||||
"${PX4_BINARY_DIR}"
|
||||
WORKING_DIRECTORY ${SITL_WORKING_DIR}
|
||||
USES_TERMINAL
|
||||
)
|
||||
add_dependencies(run_config px4)
|
||||
|
||||
foreach(viewer none jmavsim gazebo replay)
|
||||
foreach(debugger none gdb lldb ddd valgrind)
|
||||
foreach(model none iris iris_opt_flow tailsitter standard_vtol plane solo typhoon_h480)
|
||||
# project to build sitl_gazebo if necessary
|
||||
ExternalProject_Add(sitl_gazebo
|
||||
SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/sitl_gazebo
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
BINARY_DIR ${PX4_BINARY_DIR}/build_gazebo
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
set_target_properties(sitl_gazebo PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
||||
|
||||
# create targets for each viewer/model/debugger combination
|
||||
set(viewers none jmavsim gazebo replay)
|
||||
set(debuggers none gdb lldb ddd valgrind)
|
||||
set(models none iris iris_opt_flow tailsitter standard_vtol plane solo typhoon_h480)
|
||||
foreach(viewer ${viewers})
|
||||
foreach(debugger ${debuggers})
|
||||
foreach(model ${models})
|
||||
if (debugger STREQUAL "none")
|
||||
if (model STREQUAL "none")
|
||||
set(_targ_name "${viewer}")
|
||||
@@ -143,13 +169,20 @@ foreach(viewer none jmavsim gazebo replay)
|
||||
endif()
|
||||
endif()
|
||||
add_custom_target(${_targ_name}
|
||||
COMMAND Tools/sitl_run.sh "${config_sitl_rcS}"
|
||||
"${debugger}"
|
||||
"${viewer}" "${model}" "${CMAKE_BINARY_DIR}"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${PX4_SOURCE_DIR}/Tools/sitl_run.sh
|
||||
$<TARGET_FILE:px4>
|
||||
${config_sitl_rcS}
|
||||
${debugger}
|
||||
${viewer}
|
||||
${model}
|
||||
${PX4_SOURCE_DIR}
|
||||
${PX4_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${SITL_WORKING_DIR}
|
||||
USES_TERMINAL
|
||||
)
|
||||
add_dependencies(${_targ_name} px4)
|
||||
if (viewer STREQUAL "gazebo")
|
||||
add_dependencies(${_targ_name} sitl_gazebo)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endforeach()
|
||||
@@ -158,8 +191,25 @@ endforeach()
|
||||
# install
|
||||
#
|
||||
|
||||
install(TARGETS px4 DESTINATION bin)
|
||||
install(TARGETS px4 DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/ROMFS DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/posix-configs DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
|
||||
|
||||
#=============================================================================
|
||||
# tests
|
||||
#
|
||||
|
||||
add_test(NAME rcS_tests
|
||||
COMMAND ${PX4_SOURCE_DIR}/Tools/sitl_run.sh
|
||||
$<TARGET_FILE:px4>
|
||||
posix-configs/SITL/init/rcS_tests
|
||||
none
|
||||
none
|
||||
none
|
||||
${PX4_SOURCE_DIR}
|
||||
${PX4_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${SITL_WORKING_DIR})
|
||||
set_tests_properties(rcS_tests PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "All tests passed")
|
||||
|
||||
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PX4_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
include(fastrpc)
|
||||
include(qurt_lib)
|
||||
|
||||
@@ -7,7 +7,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-prototypes")
|
||||
|
||||
px4_qurt_generate_builtin_commands(
|
||||
OUT ${CMAKE_BINARY_DIR}/apps.h
|
||||
OUT ${PX4_BINARY_DIR}/apps.h
|
||||
MODULE_LIST ${module_libraries})
|
||||
|
||||
FASTRPC_STUB_GEN(px4muorb.idl)
|
||||
@@ -20,8 +20,8 @@ if ("${QURT_ENABLE_STUBS}" STREQUAL "1")
|
||||
${FASTRPC_DSP_INCLUDES}
|
||||
)
|
||||
add_executable(px4
|
||||
${CMAKE_BINARY_DIR}/src/firmware/qurt/px4muorb_skel.c
|
||||
${CMAKE_BINARY_DIR}/apps.h)
|
||||
${PX4_BINARY_DIR}/src/firmware/qurt/px4muorb_skel.c
|
||||
${PX4_BINARY_DIR}/apps.h)
|
||||
|
||||
target_link_libraries(px4
|
||||
-Wl,--start-group
|
||||
@@ -40,7 +40,7 @@ else()
|
||||
QURT_LIB(LIB_NAME px4
|
||||
IDL_NAME px4muorb
|
||||
SOURCES
|
||||
${CMAKE_BINARY_DIR}/apps.h
|
||||
${PX4_BINARY_DIR}/apps.h
|
||||
LINK_LIBS
|
||||
${module_libraries}
|
||||
${target_libraries}
|
||||
@@ -54,7 +54,7 @@ else()
|
||||
BOARD ${BOARD}
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/libpx4.so
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libpx4muorb_skel.so
|
||||
${CMAKE_SOURCE_DIR}/posix-configs/eagle/flight/px4.config
|
||||
${PX4_SOURCE_DIR}/posix-configs/eagle/flight/px4.config
|
||||
DEPENDS px4 px4muorb_skel
|
||||
DEST /usr/share/data/adsp)
|
||||
endif()
|
||||
|
||||
@@ -40,4 +40,5 @@ px4_add_module(
|
||||
DEPENDS
|
||||
platforms__common
|
||||
)
|
||||
|
||||
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#if !defined(CONFIG_ARCH_BOARD_SITL)
|
||||
#define TEST_DATA_PATH "/fs/microsd"
|
||||
#else
|
||||
#define TEST_DATA_PATH "../../../../src/lib/rc/rc_tests/test_data/"
|
||||
#define TEST_DATA_PATH "./src/lib/rc/rc_tests/test_data/"
|
||||
#endif
|
||||
|
||||
extern "C" __EXPORT int rc_tests_main(int argc, char *argv[]);
|
||||
@@ -51,8 +51,8 @@ bool RCTest::dsmTest(void)
|
||||
FILE *fp;
|
||||
fp = fopen(filepath, "rt");
|
||||
|
||||
warnx("loading data from: %s", filepath);
|
||||
ut_test(fp != nullptr);
|
||||
//warnx("loading data from: %s", filepath);
|
||||
|
||||
float f;
|
||||
unsigned x;
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PX4_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
include(hexagon_sdk)
|
||||
|
||||
include_directories(${CMAKE_BINARY_DIR}/src/firmware/posix)
|
||||
include_directories(${PX4_BINARY_DIR}/src/firmware/posix)
|
||||
include_directories(${HEXAGON_SDK_INCLUDES})
|
||||
|
||||
px4_add_module(
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
px4_generate_parameters_source(OUT param_files
|
||||
XML ${CMAKE_BINARY_DIR}/parameters.xml
|
||||
SCOPE ${CMAKE_SOURCE_DIR}/cmake/configs/${OS}_${BOARD}_${LABEL}.cmake
|
||||
XML ${PX4_BINARY_DIR}/parameters.xml
|
||||
SCOPE ${PX4_SOURCE_DIR}/cmake/configs/${OS}_${BOARD}_${LABEL}.cmake
|
||||
DEPS xml_gen
|
||||
)
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ px4_join(OUT CMAKE_CXX_FLAGS LIST "${cxx_flags}" GLUE " ")
|
||||
|
||||
include_directories(
|
||||
${include_dirs}
|
||||
${CMAKE_BINARY_DIR}/src/modules/systemlib/mixer
|
||||
${PX4_BINARY_DIR}/src/modules/systemlib/mixer
|
||||
.
|
||||
)
|
||||
link_directories(${link_dirs})
|
||||
@@ -117,10 +117,10 @@ add_dependencies(${fw_io_name}
|
||||
mixer_gen
|
||||
)
|
||||
|
||||
set(nuttx_export_dir ${CMAKE_BINARY_DIR}/${config_io_board}/NuttX/nuttx-export)
|
||||
set(nuttx_export_dir ${PX4_BINARY_DIR}/${config_io_board}/NuttX/nuttx-export)
|
||||
set(main_link_flags
|
||||
"-T${nuttx_export_dir}/build/ld.script"
|
||||
"-Wl,-Map=${CMAKE_BINARY_DIR}/${config_io_board}/main.map"
|
||||
"-Wl,-Map=${PX4_BINARY_DIR}/${config_io_board}/main.map"
|
||||
)
|
||||
px4_join(OUT main_link_flags LIST ${main_link_flags} GLUE " ")
|
||||
set_target_properties(${fw_io_name} PROPERTIES LINK_FLAGS ${main_link_flags})
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
############################################################################
|
||||
|
||||
# for generated files
|
||||
include_directories(${CMAKE_BINARY_DIR}/src/modules/param)
|
||||
include_directories(${PX4_BINARY_DIR}/src/modules/param)
|
||||
|
||||
set(SRCS
|
||||
perf_counter.c
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
/**
|
||||
* A UAVCAN Server Sub node.
|
||||
*/
|
||||
class UavcanServers
|
||||
class __EXPORT UavcanServers
|
||||
{
|
||||
static constexpr unsigned NumIfaces = 1; // UAVCAN_STM32_NUM_IFACES
|
||||
|
||||
|
||||
+200
-27
@@ -50,6 +50,7 @@
|
||||
#include "px4_middleware.h"
|
||||
#include "DriverFramework.hpp"
|
||||
#include <termios.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
@@ -62,6 +63,12 @@ typedef int (*px4_main_t)(int argc, char *argv[]);
|
||||
|
||||
#define CMD_BUFF_SIZE 100
|
||||
|
||||
#ifdef PATH_MAX
|
||||
const unsigned path_max_len = PATH_MAX;
|
||||
#else
|
||||
const unsigned path_max_len = 1024;
|
||||
#endif
|
||||
|
||||
static bool _ExitFlag = false;
|
||||
|
||||
static struct termios orig_term;
|
||||
@@ -85,6 +92,96 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool fileExists(const string &name)
|
||||
{
|
||||
struct stat buffer;
|
||||
return (stat(name.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
static inline bool dirExists(const string &path)
|
||||
{
|
||||
struct stat info;
|
||||
|
||||
if (stat(path.c_str(), &info) != 0) {
|
||||
return false;
|
||||
|
||||
} else if (info.st_mode & S_IFDIR) {
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void touch(const string &name)
|
||||
{
|
||||
fstream fs;
|
||||
fs.open(name, ios::out);
|
||||
fs.close();
|
||||
}
|
||||
|
||||
static int mkpath(const char *path, mode_t mode);
|
||||
|
||||
static int do_mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
struct stat st;
|
||||
int status = 0;
|
||||
|
||||
if (stat(path, &st) != 0) {
|
||||
/* Directory does not exist. EEXIST for race condition */
|
||||
if (mkdir(path, mode) != 0 && errno != EEXIST) {
|
||||
status = -1;
|
||||
}
|
||||
|
||||
} else if (!S_ISDIR(st.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
status = -1;
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/**
|
||||
** mkpath - ensure all directories in path exist
|
||||
** Algorithm takes the pessimistic view and works top-down to ensure
|
||||
** each directory in path exists, rather than optimistically creating
|
||||
** the last element and working backwards.
|
||||
*/
|
||||
static int mkpath(const char *path, mode_t mode)
|
||||
{
|
||||
char *pp;
|
||||
char *sp;
|
||||
int status;
|
||||
char *copypath = strdup(path);
|
||||
|
||||
status = 0;
|
||||
pp = copypath;
|
||||
|
||||
while (status == 0 && (sp = strchr(pp, '/')) != 0) {
|
||||
if (sp != pp) {
|
||||
/* Neither root nor double slash in path */
|
||||
*sp = '\0';
|
||||
status = do_mkdir(copypath, mode);
|
||||
*sp = '/';
|
||||
}
|
||||
|
||||
pp = sp + 1;
|
||||
}
|
||||
|
||||
if (status == 0) {
|
||||
status = do_mkdir(path, mode);
|
||||
}
|
||||
|
||||
free(copypath);
|
||||
return (status);
|
||||
}
|
||||
|
||||
static string pwd()
|
||||
{
|
||||
char temp[path_max_len];
|
||||
return (getcwd(temp, path_max_len) ? string(temp) : string(""));
|
||||
}
|
||||
|
||||
static void print_prompt()
|
||||
{
|
||||
cout.flush();
|
||||
@@ -134,12 +231,13 @@ static void run_cmd(const vector<string> &appargs, bool exit_on_fail, bool silen
|
||||
static void usage()
|
||||
{
|
||||
|
||||
cout << "./px4 [-d] [startup_config] -h" << std::endl;
|
||||
cout << "./px4 [-d] data_directory startup_config [-h]" << endl;
|
||||
cout << " -d - Optional flag to run the app in daemon mode and does not listen for user input." <<
|
||||
std::endl;
|
||||
cout << " This is needed if px4 is intended to be run as a upstart job on linux" << std::endl;
|
||||
cout << "<startup_config> - config file for starting/stopping px4 modules" << std::endl;
|
||||
cout << " -h - help/usage information" << std::endl;
|
||||
endl;
|
||||
cout << " This is needed if px4 is intended to be run as a upstart job on linux" << endl;
|
||||
cout << "<data_directory> - directory where romfs and posix-configs are located" << endl;
|
||||
cout << "<startup_config> - config file for starting/stopping px4 modules" << endl;
|
||||
cout << " -h - help/usage information" << endl;
|
||||
}
|
||||
|
||||
static void process_line(string &line, bool exit_on_fail)
|
||||
@@ -202,52 +300,131 @@ int main(int argc, char **argv)
|
||||
set_cpu_scaling();
|
||||
|
||||
int index = 1;
|
||||
char *commands_file = nullptr;
|
||||
string commands_file = "";
|
||||
int positional_arg_count = 0;
|
||||
string data_path = "";
|
||||
string node_name = "";
|
||||
|
||||
// parse arguments
|
||||
while (index < argc) {
|
||||
//cout << "arg: " << index << " : " << argv[index] << endl;
|
||||
|
||||
if (argv[index][0] == '-') {
|
||||
// the arg starts with -
|
||||
if (strcmp(argv[index], "-d") == 0) {
|
||||
if (strncmp(argv[index], "-d", 2) == 0) {
|
||||
daemon_mode = true;
|
||||
|
||||
} else if (strcmp(argv[index], "-h") == 0) {
|
||||
} else if (strncmp(argv[index], "-h", 2) == 0) {
|
||||
usage();
|
||||
return 0;
|
||||
|
||||
} else if (strcmp(argv[index], "-c") == 0) {
|
||||
} else if (strncmp(argv[index], "-c", 2) == 0) {
|
||||
chroot_on = true;
|
||||
|
||||
} else {
|
||||
PX4_WARN("Unknown/unhandled parameter: %s", argv[index]);
|
||||
PX4_ERR("Unknown/unhandled parameter: %s", argv[index]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else if (!strncmp(argv[index], "__", 2)) {
|
||||
//cout << "ros argument" << endl;
|
||||
|
||||
// ros arguments
|
||||
if (!strncmp(argv[index], "__name:=", 8)) {
|
||||
string name_arg = argv[index];
|
||||
node_name = name_arg.substr(8);
|
||||
cout << "node name: " << node_name << endl;
|
||||
}
|
||||
|
||||
} else {
|
||||
// this is an argument that does not have '-' prefix; treat it like a file name
|
||||
ifstream infile(argv[index]);
|
||||
//cout << "positional argument" << endl;
|
||||
|
||||
if (infile.good()) {
|
||||
infile.close();
|
||||
positional_arg_count += 1;
|
||||
|
||||
if (positional_arg_count == 1) {
|
||||
data_path = argv[index];
|
||||
cout << "data path: " << data_path << endl;
|
||||
|
||||
} else if (positional_arg_count == 2) {
|
||||
commands_file = argv[index];
|
||||
|
||||
} else {
|
||||
PX4_WARN("Error opening file: %s", argv[index]);
|
||||
return -1;
|
||||
cout << "commands file: " << commands_file << endl;
|
||||
}
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
if (positional_arg_count != 2) {
|
||||
PX4_ERR("Error expected 2 position arguments, got %d", positional_arg_count);
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (commands_file.size() < 1) {
|
||||
PX4_ERR("Error commands file not specified");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!fileExists(commands_file)) {
|
||||
PX4_ERR("Error opening commands file, does not exist: %s", commands_file.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// create sym-links
|
||||
vector<string> path_sym_links;
|
||||
path_sym_links.push_back("ROMFS");
|
||||
path_sym_links.push_back("posix-configs");
|
||||
path_sym_links.push_back("src");
|
||||
|
||||
for (int i = 0; i < path_sym_links.size(); i++) {
|
||||
string path_sym_link = path_sym_links[i];
|
||||
//cout << "path sym link: " << path_sym_link << endl;
|
||||
string src_path = data_path + "/" + path_sym_link;
|
||||
string dest_path = pwd() + "/" + path_sym_link;
|
||||
|
||||
PX4_DEBUG("Creating symlink %s -> %s", src_path.c_str(), dest_path.c_str());
|
||||
|
||||
if (dirExists(path_sym_link)) { continue; }
|
||||
|
||||
// create sym-links
|
||||
int ret = symlink(src_path.c_str(), dest_path.c_str());
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("Error creating symlink %s -> %s",
|
||||
src_path.c_str(), dest_path.c_str());
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
PX4_DEBUG("Successfully created symlink %s -> %s",
|
||||
src_path.c_str(), dest_path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// setup rootfs
|
||||
const string eeprom_path = "./rootfs/eeprom/";
|
||||
const string microsd_path = "./rootfs/fs/microsd/";
|
||||
|
||||
if (!fileExists(eeprom_path + "parameters")) {
|
||||
cout << "creating new parameters file" << endl;
|
||||
mkpath(eeprom_path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
touch(eeprom_path + "parameters");
|
||||
}
|
||||
|
||||
if (!fileExists(microsd_path + "dataman")) {
|
||||
cout << "creating new dataman file" << endl;
|
||||
mkpath(microsd_path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
touch(microsd_path + "dataman");
|
||||
}
|
||||
|
||||
// initialize
|
||||
DriverFramework::Framework::initialize();
|
||||
px4::init_once();
|
||||
|
||||
px4::init(argc, argv, "px4");
|
||||
|
||||
// if commandfile is present, process the commands from the file
|
||||
if (commands_file != nullptr) {
|
||||
ifstream infile(commands_file);
|
||||
if (commands_file.size() != 0) {
|
||||
ifstream infile(commands_file.c_str());
|
||||
|
||||
if (infile.is_open()) {
|
||||
for (string line; getline(infile, line, '\n');) {
|
||||
@@ -261,7 +438,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
} else {
|
||||
PX4_WARN("Error opening file: %s", commands_file);
|
||||
PX4_ERR("Error opening commands file: %s", commands_file.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,12 +447,6 @@ int main(int argc, char **argv)
|
||||
// this is not an attempt to secure the environment,
|
||||
// rather, to replicate a deployed file system.
|
||||
|
||||
#ifdef PATH_MAX
|
||||
const unsigned path_max_len = PATH_MAX;
|
||||
#else
|
||||
const unsigned path_max_len = 1024;
|
||||
#endif
|
||||
|
||||
char pwd_path[path_max_len];
|
||||
const char *folderpath = "/rootfs/";
|
||||
|
||||
@@ -419,3 +590,5 @@ int main(int argc, char **argv)
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* vim: set noet fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
############################################################################
|
||||
|
||||
if("${CONFIG_SHMEM}" STREQUAL "1")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PX4_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
include(hexagon_sdk)
|
||||
|
||||
include_directories(${CMAKE_BINARY_DIR}/src/firmware/posix)
|
||||
include_directories(${PX4_BINARY_DIR}/src/firmware/posix)
|
||||
include_directories(${HEXAGON_SDK_INCLUDES})
|
||||
list(APPEND SHMEM_SRCS
|
||||
shmem_posix.c
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PX4_SOURCE_DIR}/cmake/cmake_hexagon")
|
||||
include(hexagon_sdk)
|
||||
|
||||
include_directories(${HEXAGON_8074_INCLUDES})
|
||||
|
||||
@@ -90,7 +90,7 @@ int test_mixer(int argc, char *argv[])
|
||||
#if !defined(CONFIG_ARCH_BOARD_SITL)
|
||||
const char *filename = "/etc/mixers/IO_pass.mix";
|
||||
#else
|
||||
const char *filename = "../../../../ROMFS/px4fmu_test/mixers/IO_pass.mix";
|
||||
const char *filename = "ROMFS/px4fmu_test/mixers/IO_pass.mix";
|
||||
#endif
|
||||
|
||||
//PX4_INFO("loading: %s", filename);
|
||||
@@ -400,7 +400,7 @@ int test_mixer(int argc, char *argv[])
|
||||
#if !defined(CONFIG_ARCH_BOARD_SITL)
|
||||
filename = "/etc/mixers/quad_test.mix";
|
||||
#else
|
||||
filename = "../../../../ROMFS/px4fmu_test/mixers/quad_test.mix";
|
||||
filename = "ROMFS/px4fmu_test/mixers/quad_test.mix";
|
||||
#endif
|
||||
|
||||
load_mixer_file(filename, &buf[0], sizeof(buf));
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
############################################################################
|
||||
|
||||
add_custom_command(OUTPUT topic_listener.cpp
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/generate_listener.py ${CMAKE_SOURCE_DIR} > topic_listener.cpp
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/generate_listener.py ${PX4_SOURCE_DIR} > topic_listener.cpp
|
||||
DEPENDS msg_gen
|
||||
)
|
||||
|
||||
add_custom_target(generate_topic_listener
|
||||
DEPENDS
|
||||
topic_listener.cpp
|
||||
${CMAKE_SOURCE_DIR}/Tools/generate_listener.py)
|
||||
${PX4_SOURCE_DIR}/Tools/generate_listener.py)
|
||||
|
||||
px4_add_module(
|
||||
MODULE systemcmds__topic_listener
|
||||
|
||||
Reference in New Issue
Block a user