From 6ac641956a5d226215e7ee514a57b3ca74a5591d Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 18 Mar 2016 14:28:24 +0100 Subject: [PATCH] added posix and qurt apps to enable remote execution of shell commands on qurt side from posix shell commands are sent via muOrb to qurt, where they are executed and printed (i.e. visibile on mini-dm) --- cmake/configs/posix_eagle_default.cmake | 2 +- cmake/configs/qurt_eagle_default.cmake | 1 + msg/qshell_req.msg | 4 + posix-configs/eagle/flight/px4-flight.config | 1 + src/drivers/qshell/posix/CMakeLists.txt | 43 +++++ src/drivers/qshell/posix/module.mk | 46 +++++ src/drivers/qshell/posix/qshell.cpp | 88 +++++++++ src/drivers/qshell/posix/qshell.h | 62 ++++++ .../qshell/posix/qshell_start_posix.cpp | 76 ++++++++ src/drivers/qshell/qurt/CMakeLists.txt | 43 +++++ src/drivers/qshell/qurt/module.mk | 46 +++++ src/drivers/qshell/qurt/qshell.cpp | 177 ++++++++++++++++++ src/drivers/qshell/qurt/qshell.h | 66 +++++++ src/drivers/qshell/qurt/qshell_main.cpp | 58 ++++++ src/drivers/qshell/qurt/qshell_start_qurt.cpp | 116 ++++++++++++ src/modules/uORB/objects_common.cpp | 3 + 16 files changed, 831 insertions(+), 1 deletion(-) create mode 100644 msg/qshell_req.msg create mode 100644 src/drivers/qshell/posix/CMakeLists.txt create mode 100644 src/drivers/qshell/posix/module.mk create mode 100644 src/drivers/qshell/posix/qshell.cpp create mode 100644 src/drivers/qshell/posix/qshell.h create mode 100644 src/drivers/qshell/posix/qshell_start_posix.cpp create mode 100644 src/drivers/qshell/qurt/CMakeLists.txt create mode 100644 src/drivers/qshell/qurt/module.mk create mode 100644 src/drivers/qshell/qurt/qshell.cpp create mode 100644 src/drivers/qshell/qurt/qshell.h create mode 100644 src/drivers/qshell/qurt/qshell_main.cpp create mode 100644 src/drivers/qshell/qurt/qshell_start_qurt.cpp diff --git a/cmake/configs/posix_eagle_default.cmake b/cmake/configs/posix_eagle_default.cmake index 0969de4161..01f60b3133 100644 --- a/cmake/configs/posix_eagle_default.cmake +++ b/cmake/configs/posix_eagle_default.cmake @@ -12,6 +12,7 @@ set(config_module_list drivers/rgbled drivers/led drivers/boards/sitl + drivers/qshell/posix systemcmds/param systemcmds/mixer @@ -52,4 +53,3 @@ set(config_module_list platforms/posix/px4_layer platforms/posix/work_queue ) - diff --git a/cmake/configs/qurt_eagle_default.cmake b/cmake/configs/qurt_eagle_default.cmake index 9ea7da8924..85008b1cf1 100644 --- a/cmake/configs/qurt_eagle_default.cmake +++ b/cmake/configs/qurt_eagle_default.cmake @@ -59,6 +59,7 @@ set(config_module_list # drivers/gps drivers/uart_esc + drivers/qshell/qurt # # Libraries diff --git a/msg/qshell_req.msg b/msg/qshell_req.msg new file mode 100644 index 0000000000..bad96a1cec --- /dev/null +++ b/msg/qshell_req.msg @@ -0,0 +1,4 @@ +uint64 timestamp # Microseconds since system boot +int32[100] string +uint64 MAX_STRLEN = 100 +uint64 strlen diff --git a/posix-configs/eagle/flight/px4-flight.config b/posix-configs/eagle/flight/px4-flight.config index a5673f4252..695f5bf5b9 100644 --- a/posix-configs/eagle/flight/px4-flight.config +++ b/posix-configs/eagle/flight/px4-flight.config @@ -1,4 +1,5 @@ uorb start +qshell start gps start -d /dev/tty-4 sleep 1 df_mpu9250_wrapper start diff --git a/src/drivers/qshell/posix/CMakeLists.txt b/src/drivers/qshell/posix/CMakeLists.txt new file mode 100644 index 0000000000..9bdf0a3320 --- /dev/null +++ b/src/drivers/qshell/posix/CMakeLists.txt @@ -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 drivers__qshell__posix + MAIN qshell + SRCS + #qshell_main.cpp + qshell_start_posix.cpp + qshell.cpp + DEPENDS + platforms__common + ) +# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/drivers/qshell/posix/module.mk b/src/drivers/qshell/posix/module.mk new file mode 100644 index 0000000000..33a313576d --- /dev/null +++ b/src/drivers/qshell/posix/module.mk @@ -0,0 +1,46 @@ +############################################################################ +# +# 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. +# +############################################################################ + +# +# Send shell commands to qurt +# + +MODULE_COMMAND = qshell + +SRCS = \ + qshell_start_qurt.cpp \ + qshell.cpp + +INCLUDE_DIRS += $(PX4_BASE)/src/modules/uORB \ + $(PX4_BASE)/src/platforms \ + $(PX4_BASE)/src/modules diff --git a/src/drivers/qshell/posix/qshell.cpp b/src/drivers/qshell/posix/qshell.cpp new file mode 100644 index 0000000000..61de1bcf17 --- /dev/null +++ b/src/drivers/qshell/posix/qshell.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** + * + * 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 qshell.cpp + * Send shell commands to qurt + * + * @author Nicolas de Palezieux + */ + +#include "qshell.h" +#include +#include +#include +#include +#include +#include + +px4::AppState QShell::appState; + +int QShell::main(std::vector argList) +{ + appState.setRunning(true); + + std::string cmd; + + for (int i = 0; i < argList.size(); i++) { + cmd += argList[i]; + + if (i < argList.size() - 1) { + cmd += " "; + } + } + + 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); + return -1; + } + + PX4_DEBUG("Requesting %s", cmd.c_str()); + + orb_advert_t pub_id_qshell_req = orb_advertise(ORB_ID(qshell_req), & m_qshell_req); + + m_qshell_req.strlen = cmd.size(); + + for (int 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; +} diff --git a/src/drivers/qshell/posix/qshell.h b/src/drivers/qshell/posix/qshell.h new file mode 100644 index 0000000000..9edb1e5f79 --- /dev/null +++ b/src/drivers/qshell/posix/qshell.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * + * 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 qshell.h + * Send shell commands to qurt + * + * @author Nicolas de Palezieux + */ + +#pragma once + +#include +#include "uORB/topics/qshell_req.h" +#include +#include + +class QShell +{ +public: + QShell() {}; + ~QShell() {}; + + int main(std::vector argList); + + static px4::AppState appState; /* track requests to terminate app */ + +private: + + struct qshell_req_s m_qshell_req; + +}; diff --git a/src/drivers/qshell/posix/qshell_start_posix.cpp b/src/drivers/qshell/posix/qshell_start_posix.cpp new file mode 100644 index 0000000000..d14fb26fe2 --- /dev/null +++ b/src/drivers/qshell/posix/qshell_start_posix.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** + * + * 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 qshell_start_posix.cpp + * Send shell commands to qurt + * + * @author Nicolas de Palezieux + */ + +#include "qshell.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//using namespace px4; + +extern "C" __EXPORT int qshell_main(int argc, char *argv[]); + +static void usage() +{ + PX4_DEBUG("usage: qshell cmd [args]"); +} +int qshell_main(int argc, char *argv[]) +{ + if (argc < 2) { + usage(); + return 1; + } + + std::vector argList; + + for (int i = 1; i < argc; i++) { + argList.push_back(argv[i]); + } + + + QShell qshell; + return qshell.main(argList); +} diff --git a/src/drivers/qshell/qurt/CMakeLists.txt b/src/drivers/qshell/qurt/CMakeLists.txt new file mode 100644 index 0000000000..51244e4f4b --- /dev/null +++ b/src/drivers/qshell/qurt/CMakeLists.txt @@ -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 drivers__qshell__qurt + MAIN qshell + SRCS + qshell_main.cpp + qshell_start_qurt.cpp + qshell.cpp + DEPENDS + platforms__common + ) +# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/drivers/qshell/qurt/module.mk b/src/drivers/qshell/qurt/module.mk new file mode 100644 index 0000000000..97473d9554 --- /dev/null +++ b/src/drivers/qshell/qurt/module.mk @@ -0,0 +1,46 @@ +############################################################################ +# +# 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. +# +############################################################################ + +# +# Listener for shell commands from posix +# + +MODULE_COMMAND = qshell + +SRCS = \ + qshell_start_qurt.cpp \ + qshell.cpp + +INCLUDE_DIRS += $(PX4_BASE)/src/modules/uORB \ + $(PX4_BASE)/src/platforms \ + $(PX4_BASE)/src/modules diff --git a/src/drivers/qshell/qurt/qshell.cpp b/src/drivers/qshell/qurt/qshell.cpp new file mode 100644 index 0000000000..5be2495450 --- /dev/null +++ b/src/drivers/qshell/qurt/qshell.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** + * + * 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 qshell.cpp + * Listener for shell commands from posix + * + * @author Nicolas de Palezieux + */ + +#include "qshell.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "modules/uORB/uORB.h" +#include +#include "DriverFramework.hpp" + +extern void init_app_map(std::map &apps); + +using std::map; +using std::string; + +px4::AppState QShell::appState; + +QShell::QShell() +{ + init_app_map(apps); +} + +int QShell::main() +{ + int rc; + appState.setRunning(true); + int sub_qshell_req = orb_subscribe(ORB_ID(qshell_req)); + + if (sub_qshell_req == PX4_ERROR) { + PX4_ERR("Error subscribing to qshell_req topic"); + return -1; + } + + int i = 0; + + 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); + + 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; + } + + char current_char; + std::string arg; + std::vector appargs; + + for (int str_idx = 0; str_idx < m_qshell_req.strlen; str_idx++) { + current_char = m_qshell_req.string[str_idx]; + + if (isspace(current_char)) { // split at spaces + if (arg.length()) { + appargs.push_back(arg); + arg = ""; + } + + } else { + arg += current_char; + } + } + + appargs.push_back(arg); // push last argument + + int ret = run_cmd(appargs); + + if (ret) { + PX4_ERR("Failed to execute command"); + } + } + + } else { + PX4_ERR("[%d]Error checking the updated status for qshell_req ", i); + break; + } + + // sleep for 1/2 sec. + usleep(500000); + + ++i; + } + + return 0; + appState.setRunning(false); + return rc; +} + +int QShell::run_cmd(const std::vector &appargs) +{ + // command is appargs[0] + std::string command = appargs[0]; + + //replaces app.find with iterator code to avoid null pointer exception + for (map::iterator it = apps.begin(); it != apps.end(); ++it) { + if (it->first == command) { + const char *arg[2 + 1]; + + unsigned int i = 0; + + while (i < appargs.size() && appargs[i].c_str()[0] != '\0') { + arg[i] = (char *)appargs[i].c_str(); + PX4_DEBUG(" arg%d = '%s'\n", i, arg[i]); + ++i; + } + + arg[i] = (char *)0; + + //PX4_DEBUG_PRINTF(i); + if (apps[command] == NULL) { + PX4_ERR("Null function !!\n"); + + } else { + return apps[command](i, (char **)arg); + } + + } + } + + PX4_ERR("Command %s not found", command.c_str()); + return 1; +} diff --git a/src/drivers/qshell/qurt/qshell.h b/src/drivers/qshell/qurt/qshell.h new file mode 100644 index 0000000000..24ddc9c867 --- /dev/null +++ b/src/drivers/qshell/qurt/qshell.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * + * 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 qshell.h + * Listener for shell commands from posix + * + * @author Nicolas de Palezieux + */ + +#pragma once + +#include +#include +#include +#include +#include +#include "uORB/topics/qshell_req.h" + +class QShell +{ +public: + QShell(); + ~QShell() {}; + + int main(); + int run_cmd(const std::vector &appargs); + + static px4::AppState appState; /* track requests to terminate app */ + +private: + + struct qshell_req_s m_qshell_req; + std::map apps; + +}; diff --git a/src/drivers/qshell/qurt/qshell_main.cpp b/src/drivers/qshell/qurt/qshell_main.cpp new file mode 100644 index 0000000000..95da6bbbb7 --- /dev/null +++ b/src/drivers/qshell/qurt/qshell_main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** + * + * 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 qshell_main.cpp + * Listener for shell commands from posix + * + * @author Nicolas de Palezieux + */ + +#include +#include +#include +#include "qshell.h" + +extern "C" __EXPORT int qshell_entry(int argc, char **argv); + +int qshell_entry(int argc, char **argv) +{ + px4::init(argc, argv, "qshell"); + + PX4_DEBUG("qshell"); + QShell qshell; + qshell.main(); + + PX4_DEBUG("goodbye"); + return 0; +} diff --git a/src/drivers/qshell/qurt/qshell_start_qurt.cpp b/src/drivers/qshell/qurt/qshell_start_qurt.cpp new file mode 100644 index 0000000000..b769147817 --- /dev/null +++ b/src/drivers/qshell/qurt/qshell_start_qurt.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** + * + * 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 qshell_start_qurt.cpp + * Listener for shell commands from posix + * + * @author Nicolas de Palezieux + */ + +#include "qshell.h" +#include +#include +#include +#include +#include +#include + +static int daemon_task; /* Handle of deamon task / thread */ + +//using namespace px4; + +extern "C" __EXPORT int qshell_main(int argc, char *argv[]); + +int qshell_entry(int argc, char **argv) +{ + //px4::init(argc, argv, "qshell"); + + PX4_INFO("qshell entry....."); + QShell qshell; + qshell.main(); + + PX4_INFO("goodbye"); + return 0; +} + +static void usage() +{ + PX4_DEBUG("usage: qshell {start|stop|status}"); +} +int qshell_main(int argc, char *argv[]) +{ + if (argc < 2) { + usage(); + return 1; + } + + if (!strcmp(argv[1], "start")) { + + if (QShell::appState.isRunning()) { + PX4_DEBUG("already running"); + /* this is not an error */ + return 0; + } + + PX4_INFO("before starting the qshell_entry task"); + + daemon_task = px4_task_spawn_cmd("qshell", + SCHED_DEFAULT, + SCHED_PRIORITY_MAX - 5, + 8192, + qshell_entry, + (char *const *)argv); + + return 0; + } + + if (!strcmp(argv[1], "stop")) { + QShell::appState.requestExit(); + return 0; + } + + if (!strcmp(argv[1], "status")) { + if (QShell::appState.isRunning()) { + PX4_DEBUG("is running"); + + } else { + PX4_DEBUG("not started"); + } + + return 0; + } + + usage(); + return 1; +} diff --git a/src/modules/uORB/objects_common.cpp b/src/modules/uORB/objects_common.cpp index a0d30ccded..5f05123f7e 100644 --- a/src/modules/uORB/objects_common.cpp +++ b/src/modules/uORB/objects_common.cpp @@ -279,3 +279,6 @@ ORB_DEFINE(ekf2_innovations, struct ekf2_innovations_s); #include "topics/ekf2_replay.h" ORB_DEFINE(ekf2_replay, struct ekf2_replay_s); + +#include "topics/qshell_req.h" +ORB_DEFINE(qshell_req, struct qshell_req_s);