40
40
#include < px4_log.h>
41
41
#include < drivers/drv_hrt.h>
42
42
43
+ using namespace time_literals ;
44
+
43
45
namespace events
44
46
{
45
47
46
- struct work_s SendEvent::_work = {};
47
-
48
48
// Run it at 30 Hz.
49
- const unsigned SEND_EVENT_INTERVAL_US = 33000 ;
50
-
49
+ static constexpr uint32_t SEND_EVENT_INTERVAL_US{1_s / 30 };
51
50
52
51
int SendEvent::task_spawn (int argc, char *argv[])
53
52
{
54
- int ret = work_queue (LPWORK, &_work, (worker_t )&SendEvent::initialize_trampoline, nullptr , 0 );
55
-
56
- if (ret < 0 ) {
57
- return ret;
58
- }
59
-
60
- ret = wait_until_running ();
53
+ SendEvent *send_event = new SendEvent ();
61
54
62
- if (ret < 0 ) {
63
- return ret;
55
+ if (!send_event) {
56
+ PX4_ERR (" alloc failed" );
57
+ return PX4_ERROR;
64
58
}
65
59
60
+ _object.store (send_event);
66
61
_task_id = task_id_is_work_queue;
67
62
63
+ send_event->start ();
64
+
68
65
return 0 ;
69
66
}
70
67
71
- SendEvent::SendEvent () : ModuleParams(nullptr )
68
+ SendEvent::SendEvent () :
69
+ ModuleParams (nullptr ),
70
+ ScheduledWorkItem (px4::wq_configurations::lp_default)
72
71
{
73
72
if (_param_ev_tsk_stat_dis.get ()) {
74
- _status_display = new status::StatusDisplay (_subscriber_handler );
73
+ _status_display = new status::StatusDisplay ();
75
74
}
76
75
77
76
if (_param_ev_tsk_rc_loss.get ()) {
78
- _rc_loss_alarm = new rc_loss::RC_Loss_Alarm (_subscriber_handler );
77
+ _rc_loss_alarm = new rc_loss::RC_Loss_Alarm ();
79
78
}
80
79
}
81
80
82
81
SendEvent::~SendEvent ()
83
82
{
83
+ ScheduleClear ();
84
+
84
85
if (_status_display != nullptr ) {
85
86
delete _status_display;
86
87
}
@@ -92,49 +93,18 @@ SendEvent::~SendEvent()
92
93
93
94
int SendEvent::start ()
94
95
{
95
- if (is_running ()) {
96
- return 0 ;
97
- }
98
-
99
- // Subscribe to the topics.
100
- _subscriber_handler.subscribe ();
101
-
102
- // Kick off the cycling. We can call it directly because we're already in the work queue context.
103
- cycle ();
104
-
105
- return 0 ;
106
- }
107
-
108
- void SendEvent::initialize_trampoline (void *arg)
109
- {
110
- SendEvent *send_event = new SendEvent ();
111
-
112
- if (!send_event) {
113
- PX4_ERR (" alloc failed" );
114
- return ;
115
- }
96
+ ScheduleOnInterval (SEND_EVENT_INTERVAL_US, 10000 );
116
97
117
- send_event->start ();
118
- _object.store (send_event);
98
+ return PX4_OK;
119
99
}
120
100
121
- void SendEvent::cycle_trampoline (void *arg)
122
- {
123
- SendEvent *obj = reinterpret_cast <SendEvent *>(arg);
124
-
125
- obj->cycle ();
126
- }
127
-
128
- void SendEvent::cycle ()
101
+ void SendEvent::Run ()
129
102
{
130
103
if (should_exit ()) {
131
- _subscriber_handler.unsubscribe ();
132
104
exit_and_cleanup ();
133
105
return ;
134
106
}
135
107
136
- _subscriber_handler.check_for_updates ();
137
-
138
108
process_commands ();
139
109
140
110
if (_status_display != nullptr ) {
@@ -144,21 +114,16 @@ void SendEvent::cycle()
144
114
if (_rc_loss_alarm != nullptr ) {
145
115
_rc_loss_alarm->process ();
146
116
}
147
-
148
- work_queue (LPWORK, &_work, (worker_t )&SendEvent::cycle_trampoline, this ,
149
- USEC2TICK (SEND_EVENT_INTERVAL_US));
150
117
}
151
118
152
119
void SendEvent::process_commands ()
153
120
{
154
- if (!_subscriber_handler.vehicle_command_updated ()) {
121
+ vehicle_command_s cmd{};
122
+
123
+ if (!_vehicle_command_sub.update (&cmd)) {
155
124
return ;
156
125
}
157
126
158
- struct vehicle_command_s cmd;
159
-
160
- orb_copy (ORB_ID (vehicle_command), _subscriber_handler.get_vehicle_command_sub (), &cmd);
161
-
162
127
bool got_temperature_calibration_command = false , accel = false , baro = false , gyro = false ;
163
128
164
129
switch (cmd.command ) {
0 commit comments