Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55a3128

Browse files
committed
qshell update orb usage
1 parent 7759a5d commit 55a3128

File tree

6 files changed

+31
-38
lines changed

6 files changed

+31
-38
lines changed

src/drivers/qshell/posix/qshell.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151

5252
px4::AppState QShell::appState;
5353

54-
orb_advert_t QShell::_pub_qshell_req = nullptr;
55-
int QShell::_sub_qshell_retval = -1;
56-
uint32_t QShell::_current_sequence = 0;
57-
5854
int QShell::main(std::vector<std::string> argList)
5955
{
6056
int ret = _send_cmd(argList);
@@ -81,7 +77,7 @@ int QShell::_send_cmd(std::vector<std::string> &argList)
8177
// it had timed out.
8278
++_current_sequence;
8379

84-
struct qshell_req_s qshell_req;
80+
qshell_req_s qshell_req{};
8581
std::string cmd;
8682

8783
for (size_t i = 0; i < argList.size(); i++) {
@@ -103,34 +99,20 @@ int QShell::_send_cmd(std::vector<std::string> &argList)
10399
strcpy((char *)qshell_req.cmd, cmd.c_str());
104100
qshell_req.request_sequence = _current_sequence;
105101

106-
int instance;
107-
orb_publish_auto(ORB_ID(qshell_req), &_pub_qshell_req, &qshell_req, &instance, ORB_PRIO_DEFAULT);
102+
qshell_req.timestamp = hrt_absolute_time();
103+
_qshell_req_pub.publish(qshell_req);
108104

109105
return 0;
110106
}
111107

112108
int QShell::_wait_for_retval()
113109
{
114-
if (_sub_qshell_retval < 0) {
115-
_sub_qshell_retval = orb_subscribe(ORB_ID(qshell_retval));
116-
117-
if (_sub_qshell_retval < 0) {
118-
PX4_ERR("could not subscribe to retval");
119-
return -1;
120-
}
121-
}
122-
123110
const hrt_abstime time_started_us = hrt_absolute_time();
124111

125112
while (hrt_elapsed_time(&time_started_us) < 3000000) {
126-
bool updated;
127-
orb_check(_sub_qshell_retval, &updated);
128-
129-
if (updated) {
130-
131-
struct qshell_retval_s retval;
132-
orb_copy(ORB_ID(qshell_retval), _sub_qshell_retval, &retval);
113+
qshell_retval_s retval;
133114

115+
if (_qshell_retval_sub.update(&retval)) {
134116
if (retval.return_sequence != _current_sequence) {
135117
PX4_WARN("Ignoring return value with wrong sequence");
136118

@@ -143,7 +125,7 @@ int QShell::_wait_for_retval()
143125
}
144126
}
145127

146-
usleep(1000);
128+
px4_usleep(1000);
147129
}
148130

149131
PX4_ERR("command timed out");

src/drivers/qshell/posix/qshell.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@
4141
#pragma once
4242

4343
#include <px4_platform_common/app.h>
44-
#include "uORB/topics/qshell_req.h"
44+
#include <uORB/Publication.hpp>
45+
#include <uORB/Subscription.hpp>
46+
#include <uORB/topics/qshell_req.h>
47+
#include <uORB/topics/qshell_retval.h>
48+
4549
#include <vector>
4650
#include <string>
4751

4852
class QShell
4953
{
5054
public:
51-
QShell() {}
52-
~QShell() {}
55+
QShell() = default;
56+
~QShell() = default;
5357

5458
int main(std::vector<std::string> argList);
5559

@@ -59,7 +63,9 @@ class QShell
5963
int _send_cmd(std::vector<std::string> &argList);
6064
int _wait_for_retval();
6165

62-
static orb_advert_t _pub_qshell_req;
63-
static int _sub_qshell_retval;
64-
static uint32_t _current_sequence;
66+
uORB::Publication<qshell_req_s> _qshell_req_pub{ORB_ID(qshell_req)};
67+
68+
uORB::Subscription _qshell_retval_sub{ORB_ID(qshell_retval)};
69+
70+
uint32_t _current_sequence{0};
6571
};

src/drivers/qshell/posix/qshell_start_posix.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static void usage()
5757
{
5858
PX4_DEBUG("usage: qshell cmd [args]");
5959
}
60+
6061
int qshell_main(int argc, char *argv[])
6162
{
6263
if (argc < 2) {

src/drivers/qshell/qurt/qshell.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ int QShell::main()
8383
fds[0].fd = sub_qshell_req;
8484
fds[0].events = POLLIN;
8585

86-
orb_advert_t qshell_pub = nullptr;
87-
8886
while (!appState.exitRequested()) {
8987

9088
int pret = px4_poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 1000);
@@ -114,7 +112,7 @@ int QShell::main()
114112

115113
appargs.push_back(arg); // push last argument
116114

117-
struct qshell_retval_s retval;
115+
qshell_retval_s retval{};
118116
retval.return_value = run_cmd(appargs);
119117
retval.return_sequence = m_qshell_req.request_sequence;
120118

@@ -125,8 +123,8 @@ int QShell::main()
125123
PX4_INFO("Ok executing command: %s", m_qshell_req.cmd);
126124
}
127125

128-
int instance;
129-
orb_publish_auto(ORB_ID(qshell_retval), &qshell_pub, &retval, &instance, ORB_PRIO_DEFAULT);
126+
retval.timestamp = hrt_absolute_time();
127+
_qshell_retval_pub.publish(retval);
130128

131129
} else if (pret == 0) {
132130
// Timing out is fine.

src/drivers/qshell/qurt/qshell.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
#include <px4_platform_common/app.h>
4444
#include <string>
4545
#include <vector>
46-
#include "uORB/topics/qshell_req.h"
46+
#include <uORB/Publication.hpp>
47+
#include <uORB/topics/qshell_retval.h>
48+
#include <uORB/topics/qshell_req.h>
49+
4750
#include "apps.h"
4851

4952
class QShell
@@ -59,7 +62,9 @@ class QShell
5962

6063
private:
6164

62-
struct qshell_req_s m_qshell_req;
63-
apps_map_type m_apps;
65+
uORB::Publication<qshell_retval_s> _qshell_retval_pub{ORB_ID(qshell_retval)};
6466

67+
qshell_req_s m_qshell_req{};
68+
69+
apps_map_type m_apps;
6570
};

src/drivers/qshell/qurt/qshell_start_qurt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static void usage()
6868
{
6969
PX4_INFO("usage: qshell {start|stop|status}");
7070
}
71+
7172
int qshell_main(int argc, char *argv[])
7273
{
7374
if (argc < 2) {

0 commit comments

Comments
 (0)