mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 15:43:35 +08:00
qshell update orb usage
This commit is contained in:
@@ -51,10 +51,6 @@
|
||||
|
||||
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)
|
||||
{
|
||||
int ret = _send_cmd(argList);
|
||||
@@ -81,7 +77,7 @@ int QShell::_send_cmd(std::vector<std::string> &argList)
|
||||
// it had timed out.
|
||||
++_current_sequence;
|
||||
|
||||
struct qshell_req_s qshell_req;
|
||||
qshell_req_s qshell_req{};
|
||||
std::string cmd;
|
||||
|
||||
for (size_t i = 0; i < argList.size(); i++) {
|
||||
@@ -103,34 +99,20 @@ int QShell::_send_cmd(std::vector<std::string> &argList)
|
||||
strcpy((char *)qshell_req.cmd, cmd.c_str());
|
||||
qshell_req.request_sequence = _current_sequence;
|
||||
|
||||
int instance;
|
||||
orb_publish_auto(ORB_ID(qshell_req), &_pub_qshell_req, &qshell_req, &instance, ORB_PRIO_DEFAULT);
|
||||
qshell_req.timestamp = hrt_absolute_time();
|
||||
_qshell_req_pub.publish(qshell_req);
|
||||
|
||||
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);
|
||||
qshell_retval_s retval;
|
||||
|
||||
if (_qshell_retval_sub.update(&retval)) {
|
||||
if (retval.return_sequence != _current_sequence) {
|
||||
PX4_WARN("Ignoring return value with wrong sequence");
|
||||
|
||||
@@ -143,7 +125,7 @@ int QShell::_wait_for_retval()
|
||||
}
|
||||
}
|
||||
|
||||
usleep(1000);
|
||||
px4_usleep(1000);
|
||||
}
|
||||
|
||||
PX4_ERR("command timed out");
|
||||
|
||||
@@ -41,15 +41,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/app.h>
|
||||
#include "uORB/topics/qshell_req.h"
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/qshell_req.h>
|
||||
#include <uORB/topics/qshell_retval.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class QShell
|
||||
{
|
||||
public:
|
||||
QShell() {}
|
||||
~QShell() {}
|
||||
QShell() = default;
|
||||
~QShell() = default;
|
||||
|
||||
int main(std::vector<std::string> argList);
|
||||
|
||||
@@ -59,7 +63,9 @@ private:
|
||||
int _send_cmd(std::vector<std::string> &argList);
|
||||
int _wait_for_retval();
|
||||
|
||||
static orb_advert_t _pub_qshell_req;
|
||||
static int _sub_qshell_retval;
|
||||
static uint32_t _current_sequence;
|
||||
uORB::Publication<qshell_req_s> _qshell_req_pub{ORB_ID(qshell_req)};
|
||||
|
||||
uORB::Subscription _qshell_retval_sub{ORB_ID(qshell_retval)};
|
||||
|
||||
uint32_t _current_sequence{0};
|
||||
};
|
||||
|
||||
@@ -57,6 +57,7 @@ static void usage()
|
||||
{
|
||||
PX4_DEBUG("usage: qshell cmd [args]");
|
||||
}
|
||||
|
||||
int qshell_main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
|
||||
Reference in New Issue
Block a user