mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 04:03:35 +08:00
add posix shell
squashed & rebased version, not including: - listener changes - src/firmware renaming Commits: tag_to_version.py: fix Python3 error subprocess.communicate returns bytes instead of a str which is not the same for Python3. Therefore, we need to decode the bytes. cmake: remove folder src/firmware The folder src/firmware was not intuitive. Why would the binaries for SITL be inside a src and why even inside a src/firmware folder. Also, the rootfs was put there which made it even more confusing. The CMakeLists.txt files are moved into cmake/ and get now called from the main CMakeLists.txt. qshell: support for return value Instead of just sending commands, qshell will now also wait until the command has finished on QURT and sent back a return value. This will allow all modules on the DSP side to be spawned from the Linux side meaning that we only need one config/startup file instead of two. adb_upload: create folders before pushing Previously the script failed if the folder on the destination was not already existing. This therefore makes pushing easier. posix: spawn PX4 modules in bash This adds the possibility to spawn PX4 modules out of bash. Basically, the main executable can now be started as a server/daemon or as a client. The server replaces the existing functionality of the main exe with the pxh shell, however, it also opens a pipe that clients can talk to. Clients can run or spawn PX4 modules or commands by connecting to the server over the pipe. They clients will get the stdout and return value of their commands via a client specific pipe back. This work will allow to start all modules using a bash script similar to the way it is done in NuttX where the NuttShell scripts the startup scripts and starts the modules. SITL: use new client shell in SITL This is a first step to use the new shell capabilities for SITL. The new startup bash script rcS merges (and therefore replaces) the two existing scripts rcS_gazebo_iris and rcS_jmavsim_iris. More cleanup will be necessary for the rest of the SITL startup scripts. Snapdragon: use new shell to start all modules Instead of different mainapp.config and px4.config files, we can now use a unified rcS bash script which starts all the modules based on parameters, mainly the SYS_AUTOSTART param. Snapdragon: fix the airframe description pxh: argv needs to end with a nullptr The comment was wrong that argv needs an additional 0 termination. Instead it needs a nullptr at the end. px4_posix_tasks: variable cleanup The px4_task_spawn_cmd function got a cleanup while debugging, however, no functional changes. Snapdragon: move some drivers to 4100 config These drivers are supported by the community, so they go into the 4100 config. Snapdragon: update 210qc platform px4_daemon: use doxygen comments apps.h_in: fix string printf: use .c_str() px4_daemon: \b -> \n in printf px4_daemon: handle error in generate_uuid (close the file on error) posix main: some clarifications in comment (it's the symlinks not the script aliases) cmake: remove new install command again This one was probably wrong and untested. Installing needs revisiting. POSIX: remove argument USES_TERMINAL POSIX: copy init and mixer files for SITL Instead of using non-working install commands, the mixer and startup files are now copied as part of the build in cmake. adb_upload.sh: remove leftover commented printf POSIX main: just the pointer instead of memmove POSIX main: remove chroot chroot is removed because it hasn't been used anywhere and seems untested. px4_daemon: remove client pipe when cleaning up px4_daemon: fail if the client pipe already exists The client pipe is supposed to be specific (by UUID), so the path shouldn't exist already. history: limit the number of history entries This is a protection to avoid filling the memory if we are entering a lot of commands (e.g. auto-generated). px4_daemon: add a threadsafe map and use it px4_daemon: whitespace px4_daemon: fix client parsing Sometimes the client ends up reading more than one packet in one read. The parsing is not made for this and would require a (ring)buffer for it. The solution of this commit just reads as much as needed from the pipe which avoids having to do buffering and parsing. posix: changes sitl_run.sh and main.cpp cleanup This changes the paths in sitl_run.sh quite a bit to allow the px4 binary to run in the rootfs directory which should make it convenient and very close to the NuttX variant. Also main.cpp got a big cleanup after the big rebase with some conflicts. Quite some functionality was removed but it has yet to be seen if it needs to be re-added. px4_log: cleanup log levels, now they make sense Before DEBUG and INFO log levels where inverted which didn't make much sense in my eyes. dataman: fix path for bash shell logger: fix paths for bash shell mavlink: fix paths for bash shell param: fix path for bash shell inav: fix paths for bash shell sdlog2: fix paths for bash shell ROMFS: add forgotten mixer to list SITL init: more models, more options - Support for different models using the unified startup script rcS. - Support to choose the estimator by setting the environment variable PX4_ESTIMATOR. - Support to choose the logger by setting the environment variable PX4_LOGGER. rcS: fix string comparison listener: use template file Instead of having all of the C++ code inside the Python file it is nicer to have a separate template file with the C++ headers, etc. px4_log: add PX4_INFO_RAW for raw printfs This allows to do custom formatting but is still transported over sockets to clients. topic_listener: use PX4_INFO_RAW instead of printf commander: use PX4_INFO_RAW for status listener: rewrite to classes and factory posix: fix some argument warnings generate_listener.py: by accident changed shebang listener: big refactor of the generator Hopefully this makes it easier to read and change in the future. rcS: manually take over rebase changes listener: remove leftover try listener: properly clean up topic instance rcS: take over some vehicle specific changes posix-configs: vehicle specifics to separate files posix-configs: remove leftover lines uORBDevices: new PX4_INFO_RAW instead of printf px4_log: just use printf on NuttX listener: use less binary space, strip on NuttX generate_listener.py: remove commented code cmake: fix syntax error from merge px4_daemon: fixes after rebase of apps.h/cpp fix px4_daemon: namespace missing posix: only create stub for fsync on QURT unitests: reduce dependencies of param test This makes the unit test compile and link again after the bash changes. QURT: some compile fixes after a rebase SITL: arg change for sitl_run.sh to use rcS_test This allows to use a custom startup file for testing. SITL: add the folder test_data SITL: implement shutdown command as systemcmd The shutdown command needs to be a proper systemcmd, otherwise the alias and symlink generation doesn't work and we end up calling shutdown of the host computer which is to be avoided. px4fmu_test: same IO_pass mixer as px4fmu_default px4fmu_test: use normal quad x mixer There is no good reason to use a specific test mixer, except more cmake code around it. Therefore just use the same mixer as default, and at some point px4fmu_test and px4fmu_default can get merged POSIX: cleanup, dir and symlink fixes This cleans up the logic behind the symlinking and creating directories. POSIX: correct arg order in usage info tests: fix paths for SITL tests POSIX: printf fix sitl_run.sh: try to make this run on Mac as well cmake: try to make jenkins happier Path cleanup, the bin is no longer in src/firmware POSIX: fix symlink logic SITL: prefix all exported env variables cmake: fix path for ROS tests integrationtests: fix log path launch: try to make tets with ROS working again px4_defines: fix after wrong merge deconflicting px4_defines: get paths for POSIX correct cmake: fix cmake arguments This was fine with cmake 3.6 but did not work with cmake 3.2.2 cmake: use cp instead of cmake -E copy cmake -E copy does not support copying multiple files with versions < 3.5. Therefore, just use cp for now. ROMFS: fix build error after rebase cmake: fix paths in configs launch: use `spawn_model` again cmake: various fixes after big rebase param: path fixes after rebase posix platform: fixes after rebase test_mixer: fix screwed up rebase
This commit is contained in:
@@ -38,20 +38,50 @@
|
||||
* @author Nicolas de Palezieux <ndepal@gmail.com>
|
||||
*/
|
||||
|
||||
#include "qshell.h"
|
||||
#include <px4_log.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <uORB/topics/qshell_retval.h>
|
||||
|
||||
#include "qshell.h"
|
||||
|
||||
px4::AppState QShell::appState;
|
||||
|
||||
orb_advert_t QShell::_pub_qshell_req = nullptr;
|
||||
int QShell::_sub_qshell_retval = -1;
|
||||
uint32_t QShell::_current_sequence = 0;
|
||||
|
||||
int QShell::main(std::vector<std::string> argList)
|
||||
{
|
||||
appState.setRunning(true);
|
||||
int ret = _send_cmd(argList);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("Could not send command");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _wait_for_retval();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("Could not get return value");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QShell::_send_cmd(std::vector<std::string> &argList)
|
||||
{
|
||||
// Let's use a sequence number to check if a return value belongs to the
|
||||
// command that we just sent and not a previous one that we assumed that
|
||||
// it had timed out.
|
||||
++_current_sequence;
|
||||
|
||||
struct qshell_req_s qshell_req;
|
||||
std::string cmd;
|
||||
|
||||
for (size_t i = 0; i < argList.size(); i++) {
|
||||
@@ -62,27 +92,60 @@ int QShell::main(std::vector<std::string> argList)
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.size() > m_qshell_req.MAX_STRLEN) {
|
||||
PX4_ERR("The provided command exceeds the maximum length of characters: %d > %d", (int) cmd.size(),
|
||||
(int) m_qshell_req.MAX_STRLEN);
|
||||
if (cmd.size() >= qshell_req.MAX_STRLEN) {
|
||||
PX4_ERR("Command too long: %d >= %d", (int) cmd.size(), (int) qshell_req.MAX_STRLEN);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PX4_DEBUG("Requesting %s", cmd.c_str());
|
||||
PX4_INFO("Send cmd: '%s'", cmd.c_str());
|
||||
|
||||
orb_advert_t pub_id_qshell_req = orb_advertise(ORB_ID(qshell_req), & m_qshell_req);
|
||||
qshell_req.strlen = cmd.size();
|
||||
strcpy((char *)qshell_req.cmd, cmd.c_str());
|
||||
qshell_req.sequence = _current_sequence;
|
||||
|
||||
m_qshell_req.strlen = cmd.size();
|
||||
int instance;
|
||||
orb_publish_auto(ORB_ID(qshell_req), &_pub_qshell_req, &qshell_req, &instance, ORB_PRIO_DEFAULT);
|
||||
|
||||
for (size_t i = 0; i < cmd.size(); i++) {
|
||||
m_qshell_req.string[i] = (int) cmd[i];
|
||||
}
|
||||
|
||||
if (orb_publish(ORB_ID(qshell_req), pub_id_qshell_req, &m_qshell_req) == PX4_ERROR) {
|
||||
PX4_ERR("Error publishing the qshell_req message");
|
||||
return -1;
|
||||
}
|
||||
|
||||
appState.setRunning(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QShell::_wait_for_retval()
|
||||
{
|
||||
if (_sub_qshell_retval < 0) {
|
||||
_sub_qshell_retval = orb_subscribe(ORB_ID(qshell_retval));
|
||||
|
||||
if (_sub_qshell_retval < 0) {
|
||||
PX4_ERR("could not subscribe to retval");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const hrt_abstime time_started_us = hrt_absolute_time();
|
||||
|
||||
while (hrt_elapsed_time(&time_started_us) < 3000000) {
|
||||
bool updated;
|
||||
orb_check(_sub_qshell_retval, &updated);
|
||||
|
||||
if (updated) {
|
||||
|
||||
struct qshell_retval_s retval;
|
||||
orb_copy(ORB_ID(qshell_retval), _sub_qshell_retval, &retval);
|
||||
|
||||
if (retval.sequence != _current_sequence) {
|
||||
PX4_WARN("Ignoring return value with wrong sequence");
|
||||
|
||||
} else {
|
||||
if (retval.return_value) {
|
||||
PX4_WARN("cmd returned with: %d", retval.return_value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
PX4_ERR("command timed out");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,10 @@ public:
|
||||
static px4::AppState appState; /* track requests to terminate app */
|
||||
|
||||
private:
|
||||
int _send_cmd(std::vector<std::string> &argList);
|
||||
int _wait_for_retval();
|
||||
|
||||
struct qshell_req_s m_qshell_req;
|
||||
|
||||
static orb_advert_t _pub_qshell_req;
|
||||
static int _sub_qshell_retval;
|
||||
static uint32_t _current_sequence;
|
||||
};
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <px4_time.h>
|
||||
#include <px4_posix.h>
|
||||
#include <px4_middleware.h>
|
||||
#include <px4_defines.h>
|
||||
#include <dspal_platform.h>
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -56,7 +57,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "modules/uORB/uORB.h"
|
||||
#include <uORB/topics/qshell_retval.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include "DriverFramework.hpp"
|
||||
|
||||
@@ -71,7 +72,6 @@ QShell::QShell()
|
||||
|
||||
int QShell::main()
|
||||
{
|
||||
int rc;
|
||||
appState.setRunning(true);
|
||||
int sub_qshell_req = orb_subscribe(ORB_ID(qshell_req));
|
||||
|
||||
@@ -80,61 +80,65 @@ int QShell::main()
|
||||
return -1;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
px4_pollfd_struct_t fds[1] = {};
|
||||
fds[0].fd = sub_qshell_req;
|
||||
fds[0].events = POLLIN;
|
||||
|
||||
orb_advert_t qshell_pub = nullptr;
|
||||
|
||||
while (!appState.exitRequested()) {
|
||||
bool updated = false;
|
||||
|
||||
if (orb_check(sub_qshell_req, &updated) == 0) {
|
||||
if (updated) {
|
||||
PX4_DEBUG("[%d]qshell_req status is updated... reading new value", i);
|
||||
int pret = px4_poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 1000);
|
||||
|
||||
if (orb_copy(ORB_ID(qshell_req), sub_qshell_req, &m_qshell_req) != 0) {
|
||||
PX4_ERR("[%d]Error calling orb copy for qshell_req... ", i);
|
||||
break;
|
||||
}
|
||||
if (pret > 0 && fds[0].revents & POLLIN) {
|
||||
|
||||
char current_char;
|
||||
std::string arg;
|
||||
std::vector<std::string> appargs;
|
||||
orb_copy(ORB_ID(qshell_req), sub_qshell_req, &m_qshell_req);
|
||||
|
||||
for (size_t str_idx = 0; str_idx < m_qshell_req.strlen; str_idx++) {
|
||||
current_char = m_qshell_req.string[str_idx];
|
||||
PX4_INFO("qshell gotten: %s", m_qshell_req.cmd);
|
||||
char current_char;
|
||||
std::string arg;
|
||||
std::vector<std::string> appargs;
|
||||
|
||||
if (isspace(current_char)) { // split at spaces
|
||||
if (arg.length()) {
|
||||
appargs.push_back(arg);
|
||||
arg = "";
|
||||
}
|
||||
for (unsigned str_idx = 0; str_idx < m_qshell_req.strlen; str_idx++) {
|
||||
current_char = m_qshell_req.cmd[str_idx];
|
||||
|
||||
} else {
|
||||
arg += current_char;
|
||||
if (isspace(current_char)) { // split at spaces
|
||||
if (arg.length()) {
|
||||
appargs.push_back(arg);
|
||||
arg = "";
|
||||
}
|
||||
}
|
||||
|
||||
appargs.push_back(arg); // push last argument
|
||||
|
||||
int ret = run_cmd(appargs);
|
||||
|
||||
if (ret) {
|
||||
PX4_ERR("Failed to execute command");
|
||||
} else {
|
||||
arg += current_char;
|
||||
}
|
||||
}
|
||||
|
||||
appargs.push_back(arg); // push last argument
|
||||
|
||||
struct qshell_retval_s retval;
|
||||
retval.return_value = run_cmd(appargs);
|
||||
retval.sequence = m_qshell_req.sequence;
|
||||
|
||||
if (retval.return_value) {
|
||||
PX4_ERR("Failed to execute command: %s", m_qshell_req.cmd);
|
||||
|
||||
} else {
|
||||
PX4_INFO("Ok executing command: %s", m_qshell_req.cmd);
|
||||
}
|
||||
|
||||
int instance;
|
||||
orb_publish_auto(ORB_ID(qshell_retval), &qshell_pub, &retval, &instance, ORB_PRIO_DEFAULT);
|
||||
|
||||
} else if (pret == 0) {
|
||||
// Timing out is fine.
|
||||
} else {
|
||||
PX4_ERR("[%d]Error checking the updated status for qshell_req ", i);
|
||||
break;
|
||||
// Something is wrong.
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
// sleep for 1/2 sec.
|
||||
usleep(500000);
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
appState.setRunning(false);
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QShell::run_cmd(const std::vector<std::string> &appargs)
|
||||
|
||||
@@ -246,7 +246,7 @@ static px4_sem_t g_sys_state_mutex_mission;
|
||||
static px4_sem_t g_sys_state_mutex_fence;
|
||||
|
||||
/* The data manager store file handle and file name */
|
||||
#if defined(__PX4_POSIX_EAGLE) || defined(__PX4_POSIX_EXCELSIOR)
|
||||
#ifdef __PX4_POSIX
|
||||
static const char *default_device_path = PX4_ROOTFSDIR"/dataman";
|
||||
#else
|
||||
static const char *default_device_path = PX4_ROOTFSDIR"/fs/microsd/dataman";
|
||||
|
||||
@@ -829,7 +829,12 @@ void Logger::run()
|
||||
int log_message_sub = orb_subscribe(ORB_ID(log_message));
|
||||
orb_set_interval(log_message_sub, 20);
|
||||
|
||||
|
||||
#if __PX4_POSIX
|
||||
int ntopics = add_topics_from_file(PX4_ROOTFSDIR "/etc/logging/logger_topics.txt");
|
||||
#else
|
||||
int ntopics = add_topics_from_file(PX4_ROOTFSDIR "/fs/microsd/etc/logging/logger_topics.txt");
|
||||
#endif
|
||||
|
||||
if (ntopics > 0) {
|
||||
PX4_INFO("logging %d topics from logger_topics.txt", ntopics);
|
||||
|
||||
@@ -313,7 +313,7 @@ private:
|
||||
|
||||
static constexpr size_t MAX_TOPICS_NUM = 64; /**< Maximum number of logged topics */
|
||||
static constexpr unsigned MAX_NO_LOGFILE = 999; /**< Maximum number of log files */
|
||||
#if defined(__PX4_POSIX_EAGLE) || defined(__PX4_POSIX_EXCELSIOR)
|
||||
#ifdef __PX4_POSIX
|
||||
static constexpr const char *LOG_ROOT = PX4_ROOTFSDIR"/log";
|
||||
#else
|
||||
static constexpr const char *LOG_ROOT = PX4_ROOTFSDIR"/fs/microsd/log";
|
||||
|
||||
@@ -191,7 +191,11 @@ static void write_debug_log(const char *msg, float dt, float x_est[2], float y_e
|
||||
float acc[3], float corr_gps[3][2], float w_xy_gps_p, float w_xy_gps_v, float corr_mocap[3][1], float w_mocap_p,
|
||||
float corr_vision[3][2], float w_xy_vision_p, float w_z_vision_p, float w_xy_vision_v)
|
||||
{
|
||||
#ifdef __PX4_POSIX
|
||||
FILE *f = fopen(PX4_ROOTFSDIR"/inav.log", "a");
|
||||
#else
|
||||
FILE *f = fopen(PX4_ROOTFSDIR"/fs/microsd/inav.log", "a");
|
||||
#endif
|
||||
|
||||
if (f) {
|
||||
char *s = malloc(256);
|
||||
|
||||
@@ -1059,7 +1059,7 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters)
|
||||
print_active_only = false; // print non-active if -a or some filter given
|
||||
}
|
||||
|
||||
printf("\033[2J\n"); //clear screen
|
||||
PX4_INFO_RAW("\033[2J\n"); //clear screen
|
||||
|
||||
lock();
|
||||
|
||||
@@ -1142,12 +1142,12 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters)
|
||||
start_time = current_time;
|
||||
|
||||
|
||||
printf("\033[H"); // move cursor home and clear screen
|
||||
printf(CLEAR_LINE "update: 1s, num topics: %i\n", num_topics);
|
||||
PX4_INFO_RAW("\033[H"); // move cursor home and clear screen
|
||||
PX4_INFO_RAW(CLEAR_LINE "update: 1s, num topics: %i\n", num_topics);
|
||||
#ifdef __PX4_NUTTX
|
||||
printf(CLEAR_LINE "%*-s INST #SUB #MSG #LOST #QSIZE\n", (int)max_topic_name_length - 2, "TOPIC NAME");
|
||||
PX4_INFO_RAW(CLEAR_LINE "%*-s INST #SUB #MSG #LOST #QSIZE\n", (int)max_topic_name_length - 2, "TOPIC NAME");
|
||||
#else
|
||||
printf(CLEAR_LINE "%*s INST #SUB #MSG #LOST #QSIZE\n", -(int)max_topic_name_length + 2, "TOPIC NAME");
|
||||
PX4_INFO_RAW(CLEAR_LINE "%*s INST #SUB #MSG #LOST #QSIZE\n", -(int)max_topic_name_length + 2, "TOPIC NAME");
|
||||
#endif
|
||||
cur_node = first_node;
|
||||
|
||||
@@ -1155,13 +1155,13 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters)
|
||||
|
||||
if (!print_active_only || cur_node->pub_msg_delta > 0) {
|
||||
#ifdef __PX4_NUTTX
|
||||
printf(CLEAR_LINE "%*-s %2i %4i %4i %5i %i\n", (int)max_topic_name_length,
|
||||
PX4_INFO_RAW(CLEAR_LINE "%*-s %2i %4i %4i %5i %i\n", (int)max_topic_name_length,
|
||||
#else
|
||||
printf(CLEAR_LINE "%*s %2i %4i %4i %5i %i\n", -(int)max_topic_name_length,
|
||||
PX4_INFO_RAW(CLEAR_LINE "%*s %2i %4i %4i %5i %i\n", -(int)max_topic_name_length,
|
||||
#endif
|
||||
cur_node->node->get_meta()->o_name, (int)cur_node->instance,
|
||||
(int)cur_node->node->subscriber_count(), cur_node->pub_msg_delta,
|
||||
(int)cur_node->lost_msg_delta, cur_node->node->get_queue_size());
|
||||
cur_node->node->get_meta()->o_name, (int)cur_node->instance,
|
||||
(int)cur_node->node->subscriber_count(), cur_node->pub_msg_delta,
|
||||
(int)cur_node->lost_msg_delta, cur_node->node->get_queue_size());
|
||||
}
|
||||
|
||||
cur_node = cur_node->next;
|
||||
|
||||
+113
-22
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2017 PX4 Development Team. All rights reserved.
|
||||
* Copyright (C) 2017-2018 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
|
||||
@@ -31,13 +31,12 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <px4_log.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <px4_log.h>
|
||||
#if defined(__PX4_POSIX) && !defined(__PX4_CYGWIN)
|
||||
#include <execinfo.h>
|
||||
#include <px4_daemon/server_io.h>
|
||||
#endif
|
||||
|
||||
#include <uORB/uORB.h>
|
||||
@@ -46,9 +45,9 @@
|
||||
|
||||
static orb_advert_t orb_log_message_pub = NULL;
|
||||
|
||||
__EXPORT const char *__px4_log_level_str[_PX4_LOG_LEVEL_PANIC + 1] = { "INFO", "DEBUG", "WARN", "ERROR", "PANIC" };
|
||||
__EXPORT const char *__px4_log_level_str[_PX4_LOG_LEVEL_PANIC + 1] = { "DEBUG", "INFO", "WARN", "ERROR", "PANIC" };
|
||||
__EXPORT const char *__px4_log_level_color[_PX4_LOG_LEVEL_PANIC + 1] =
|
||||
{ PX4_ANSI_COLOR_RESET, PX4_ANSI_COLOR_GREEN, PX4_ANSI_COLOR_YELLOW, PX4_ANSI_COLOR_RED, PX4_ANSI_COLOR_RED };
|
||||
{ PX4_ANSI_COLOR_GREEN, PX4_ANSI_COLOR_RESET, PX4_ANSI_COLOR_YELLOW, PX4_ANSI_COLOR_RED, PX4_ANSI_COLOR_RED };
|
||||
|
||||
|
||||
void px4_log_initialize(void)
|
||||
@@ -91,30 +90,74 @@ void px4_backtrace()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
__EXPORT void px4_log_modulename(int level, const char *moduleName, const char *fmt, ...)
|
||||
{
|
||||
PX4_LOG_COLOR_START
|
||||
printf(__px4__log_level_fmt __px4__log_level_arg(level));
|
||||
PX4_LOG_COLOR_MODULE
|
||||
printf(__px4__log_modulename_pfmt, moduleName);
|
||||
PX4_LOG_COLOR_MESSAGE
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
vprintf(fmt, argptr);
|
||||
va_end(argptr);
|
||||
PX4_LOG_COLOR_END
|
||||
printf("\n");
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
char *buffer;
|
||||
unsigned max_length;
|
||||
bool is_atty = false;
|
||||
|
||||
if (get_stdout_pipe_buffer(&buffer, &max_length, &is_atty) == 0) {
|
||||
if (level >= _PX4_LOG_LEVEL_INFO) {
|
||||
|
||||
unsigned pos = 0;
|
||||
|
||||
if (is_atty) { pos += snprintf(buffer + pos, max_length - pos, "%s", __px4_log_level_color[level]); }
|
||||
|
||||
pos += snprintf(buffer + pos, max_length - pos, __px4__log_level_fmt __px4__log_level_arg(level));
|
||||
|
||||
if (is_atty) { pos += snprintf(buffer + pos, max_length - pos, "%s", PX4_ANSI_COLOR_GRAY); }
|
||||
|
||||
pos += snprintf(buffer + pos, max_length - pos, __px4__log_modulename_pfmt, moduleName);
|
||||
va_list argptr;
|
||||
|
||||
if (is_atty) { pos += snprintf(buffer + pos, max_length - pos, "%s", __px4_log_level_color[level]); }
|
||||
|
||||
va_start(argptr, fmt);
|
||||
pos += vsnprintf(buffer + pos, max_length - pos, fmt, argptr);
|
||||
va_end(argptr);
|
||||
pos += snprintf(buffer + pos, max_length - pos, "\n");
|
||||
|
||||
if (is_atty) { pos += snprintf(buffer + pos, max_length - pos, "%s", PX4_ANSI_COLOR_RESET); }
|
||||
|
||||
// +1 for the terminating 0 char.
|
||||
send_stdout_pipe_buffer(pos + 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
#endif
|
||||
|
||||
if (level >= _PX4_LOG_LEVEL_INFO) {
|
||||
PX4_LOG_COLOR_START
|
||||
printf(__px4__log_level_fmt __px4__log_level_arg(level));
|
||||
PX4_LOG_COLOR_MODULE
|
||||
printf(__px4__log_modulename_pfmt, moduleName);
|
||||
PX4_LOG_COLOR_MESSAGE
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
vprintf(fmt, argptr);
|
||||
va_end(argptr);
|
||||
PX4_LOG_COLOR_END
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* publish an orb log message */
|
||||
if (level >= _PX4_LOG_LEVEL_WARN && orb_log_message_pub) { //only publish important messages
|
||||
|
||||
struct log_message_s log_message;
|
||||
const unsigned max_length = sizeof(log_message.text);
|
||||
const unsigned max_length_pub = sizeof(log_message.text);
|
||||
log_message.timestamp = hrt_absolute_time();
|
||||
|
||||
const uint8_t log_level_table[] = {
|
||||
6, /* _PX4_LOG_LEVEL_ALWAYS */
|
||||
7, /* _PX4_LOG_LEVEL_DEBUG */
|
||||
6, /* _PX4_LOG_LEVEL_INFO */
|
||||
4, /* _PX4_LOG_LEVEL_WARN */
|
||||
3, /* _PX4_LOG_LEVEL_ERROR */
|
||||
0 /* _PX4_LOG_LEVEL_PANIC */
|
||||
@@ -123,14 +166,62 @@ __EXPORT void px4_log_modulename(int level, const char *moduleName, const char *
|
||||
|
||||
unsigned pos = 0;
|
||||
|
||||
pos += snprintf((char *)log_message.text + pos, max_length - pos, __px4__log_modulename_pfmt, moduleName);
|
||||
va_list argptr;
|
||||
|
||||
pos += snprintf((char *)log_message.text + pos, max_length_pub - pos, __px4__log_modulename_pfmt, moduleName);
|
||||
va_start(argptr, fmt);
|
||||
pos += vsnprintf((char *)log_message.text + pos, max_length - pos, fmt, argptr);
|
||||
pos += vsnprintf((char *)log_message.text + pos, max_length_pub - pos, fmt, argptr);
|
||||
va_end(argptr);
|
||||
log_message.text[max_length - 1] = 0; //ensure 0-termination
|
||||
log_message.text[max_length_pub - 1] = 0; //ensure 0-termination
|
||||
|
||||
#if !defined(PARAM_NO_ORB)
|
||||
orb_publish(ORB_ID(log_message), orb_log_message_pub, &log_message);
|
||||
#endif /* !PARAM_NO_ORB */
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void px4_log_raw(int level, const char *fmt, ...)
|
||||
{
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
char *buffer;
|
||||
unsigned max_length;
|
||||
bool is_atty = false;
|
||||
|
||||
if (get_stdout_pipe_buffer(&buffer, &max_length, &is_atty) == 0) {
|
||||
if (level >= _PX4_LOG_LEVEL_INFO) {
|
||||
|
||||
unsigned pos = 0;
|
||||
|
||||
va_list argptr;
|
||||
|
||||
if (is_atty) { pos += snprintf(buffer + pos, max_length - pos, "%s", __px4_log_level_color[level]); }
|
||||
|
||||
va_start(argptr, fmt);
|
||||
pos += vsnprintf(buffer + pos, max_length - pos, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if (is_atty) { pos += snprintf(buffer + pos, max_length - pos, "%s", PX4_ANSI_COLOR_RESET); }
|
||||
|
||||
// +1 for the terminating 0 char.
|
||||
send_stdout_pipe_buffer(pos + 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
#endif
|
||||
|
||||
if (level >= _PX4_LOG_LEVEL_INFO) {
|
||||
PX4_LOG_COLOR_START
|
||||
PX4_LOG_COLOR_MESSAGE
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
vprintf(fmt, argptr);
|
||||
va_end(argptr);
|
||||
PX4_LOG_COLOR_END
|
||||
}
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ typedef param_t px4_param_t;
|
||||
* NuttX specific defines.
|
||||
****************************************************************************/
|
||||
|
||||
#define PX4_ROOTFSDIR ""
|
||||
#define PX4_ROOTFSDIR "."
|
||||
#define _PX4_IOC(x,y) _IOC(x,y)
|
||||
|
||||
// mode for open with O_CREAT
|
||||
@@ -173,7 +173,7 @@ using ::isfinite;
|
||||
|
||||
// QURT specific
|
||||
# include "dspal_math.h"
|
||||
# define PX4_ROOTFSDIR ""
|
||||
# define PX4_ROOTFSDIR "."
|
||||
# define PX4_TICKS_PER_SEC 1000L
|
||||
# define SIOCDEVPRIVATE 999999
|
||||
|
||||
@@ -196,7 +196,7 @@ __END_DECLS
|
||||
# elif defined(__PX4_POSIX_BEBOP)
|
||||
# define PX4_ROOTFSDIR "/data/ftp/internal_000"
|
||||
# else
|
||||
# define PX4_ROOTFSDIR "rootfs"
|
||||
# define PX4_ROOTFSDIR "."
|
||||
# endif
|
||||
|
||||
#endif // __PX4_QURT
|
||||
|
||||
+31
-8
@@ -39,8 +39,8 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#define _PX4_LOG_LEVEL_ALWAYS 0
|
||||
#define _PX4_LOG_LEVEL_DEBUG 1
|
||||
#define _PX4_LOG_LEVEL_DEBUG 0
|
||||
#define _PX4_LOG_LEVEL_INFO 1
|
||||
#define _PX4_LOG_LEVEL_WARN 2
|
||||
#define _PX4_LOG_LEVEL_ERROR 3
|
||||
#define _PX4_LOG_LEVEL_PANIC 4
|
||||
@@ -73,6 +73,7 @@ __END_DECLS
|
||||
#define PX4_ERR(...) ROS_ERROR(__VA_ARGS__)
|
||||
#define PX4_WARN(...) ROS_WARN(__VA_ARGS__)
|
||||
#define PX4_INFO(...) ROS_INFO(__VA_ARGS__)
|
||||
#define PX4_INFO_RAW(...) printf(__VA_ARGS__)
|
||||
#define PX4_DEBUG(...) ROS_DEBUG(__VA_ARGS__)
|
||||
#define PX4_BACKTRACE()
|
||||
|
||||
@@ -81,8 +82,8 @@ __END_DECLS
|
||||
/****************************************************************************
|
||||
* Messages that should never be filtered or compiled out
|
||||
****************************************************************************/
|
||||
#define PX4_LOG(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ALWAYS, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO(FMT, ...) qurt_log(_PX4_LOG_LEVEL_ALWAYS, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO(FMT, ...) qurt_log(_PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO_RAW(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
#define PX4_BACKTRACE()
|
||||
|
||||
#if defined(TRACE_BUILD)
|
||||
@@ -122,8 +123,8 @@ __END_DECLS
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) qurt_log( _PX4_LOG_LEVEL_ALWAYS, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED_COND(name, cond, FMT, ...) if( cond ) qurt_log( _PX4_LOG_LEVEL_ALWAYS, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) qurt_log( _PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED_COND(name, cond, FMT, ...) if( cond ) qurt_log( _PX4_LOG_LEVEL_INFO, __FILE__, __LINE__, "%s " FMT, name, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
@@ -141,6 +142,7 @@ __EXPORT extern const char *__px4_log_level_str[_PX4_LOG_LEVEL_PANIC + 1];
|
||||
__EXPORT extern const char *__px4_log_level_color[_PX4_LOG_LEVEL_PANIC + 1];
|
||||
__EXPORT extern void px4_backtrace(void);
|
||||
__EXPORT void px4_log_modulename(int level, const char *moduleName, const char *fmt, ...);
|
||||
__EXPORT void px4_log_raw(int level, const char *fmt, ...);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -260,6 +262,22 @@ __END_DECLS
|
||||
do { \
|
||||
px4_log_modulename(level, MODULE_NAME, fmt, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_raw:
|
||||
* Convert a message in the form:
|
||||
* PX4_INFO("val is %d", val);
|
||||
* to
|
||||
* printf("val is %d", val);
|
||||
*
|
||||
* This can be used for simple printfs with all the formatting control.
|
||||
****************************************************************************/
|
||||
#define __px4_log_raw(level, fmt, ...) \
|
||||
do { \
|
||||
px4_log_raw(level, fmt, ##__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_timestamp:
|
||||
* Convert a message in the form:
|
||||
@@ -398,8 +416,13 @@ __END_DECLS
|
||||
/****************************************************************************
|
||||
* Messages that should never be filtered or compiled out
|
||||
****************************************************************************/
|
||||
#define PX4_LOG(FMT, ...) __px4_log(_PX4_LOG_LEVEL_ALWAYS, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_ALWAYS, FMT, ##__VA_ARGS__)
|
||||
#define PX4_INFO(FMT, ...) __px4_log_modulename(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __NUTTX
|
||||
#define PX4_INFO_RAW printf
|
||||
#else
|
||||
#define PX4_INFO_RAW(FMT, ...) __px4_log_raw(_PX4_LOG_LEVEL_INFO, FMT, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if defined(TRACE_BUILD)
|
||||
/****************************************************************************
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2016 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.
|
||||
#
|
||||
############################################################################
|
||||
px4_add_module(
|
||||
MODULE systemcmds__shutdown
|
||||
MAIN shutdown
|
||||
STACK_MAIN 800
|
||||
COMPILE_FLAGS
|
||||
SRCS
|
||||
shutdown.c
|
||||
DEPENDS
|
||||
platforms__common
|
||||
)
|
||||
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
|
||||
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2016 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 shutdown.c
|
||||
* Tool similar to UNIX shutdown command.
|
||||
*/
|
||||
|
||||
#include <px4_tasks.h>
|
||||
//#include <systemlib/systemlib.h>
|
||||
|
||||
|
||||
__EXPORT int shutdown_main(int argc, char *argv[]);
|
||||
|
||||
int shutdown_main(int argc, char *argv[])
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
const bool to_bootloader = false;
|
||||
px4_systemreset(to_bootloader);
|
||||
}
|
||||
@@ -54,6 +54,12 @@
|
||||
#define FLAG_FSYNC 1
|
||||
#define FLAG_LSEEK 2
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
#define LOG_PATH PX4_ROOTFSDIR "/log/"
|
||||
#else
|
||||
#define LOG_PATH PX4_ROOTFSDIR "/fs/microsd/"
|
||||
#endif
|
||||
|
||||
/*
|
||||
return a predictable value for any file offset to allow detection of corruption
|
||||
*/
|
||||
@@ -172,7 +178,7 @@ int test_file2(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
uint16_t flags = 0;
|
||||
const char *filename = PX4_ROOTFSDIR "/fs/microsd/testfile2.dat";
|
||||
const char *filename = LOG_PATH "testfile2.dat";
|
||||
uint32_t write_chunk = 64;
|
||||
uint32_t write_size = 5 * 1024;
|
||||
|
||||
@@ -214,7 +220,7 @@ int test_file2(int argc, char *argv[])
|
||||
/* check if microSD card is mounted */
|
||||
struct stat buffer;
|
||||
|
||||
if (stat(PX4_ROOTFSDIR "/fs/microsd/", &buffer)) {
|
||||
if (stat(LOG_PATH, &buffer)) {
|
||||
fprintf(stderr, "no microSD card mounted, aborting file test");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user