PX4 Firmware
PX4 Autopilot Software http://px4.io
subscriber_handler.cpp
Go to the documentation of this file.
1
2
#include "
subscriber_handler.h
"
3
4
#include <px4_platform_common/log.h>
5
6
namespace
events
7
{
8
9
void
SubscriberHandler::subscribe
()
10
{
11
if
(
_battery_status_sub
< 0) {
12
_battery_status_sub
=
orb_subscribe
(
ORB_ID
(
battery_status
));
13
}
14
15
if
(
_cpuload_sub
< 0) {
16
_cpuload_sub
=
orb_subscribe
(
ORB_ID
(
cpuload
));
17
}
18
19
if
(
_vehicle_command_sub
< 0) {
20
_vehicle_command_sub
=
orb_subscribe
(
ORB_ID
(vehicle_command));
21
}
22
23
if
(
_vehicle_status_sub
< 0) {
24
_vehicle_status_sub
=
orb_subscribe
(
ORB_ID
(vehicle_status));
25
}
26
27
if
(
_vehicle_status_flags_sub
< 0) {
28
_vehicle_status_flags_sub
=
orb_subscribe
(
ORB_ID
(vehicle_status_flags));
29
}
30
31
}
32
33
void
SubscriberHandler::unsubscribe
()
34
{
35
if
(
_battery_status_sub
>= 0) {
36
orb_unsubscribe
(
_battery_status_sub
);
37
_battery_status_sub
= -1;
38
}
39
40
if
(
_cpuload_sub
>= 0) {
41
orb_unsubscribe
(
_cpuload_sub
);
42
_cpuload_sub
= -1;
43
}
44
45
if
(
_vehicle_command_sub
>= 0) {
46
orb_unsubscribe
(
_vehicle_command_sub
);
47
_vehicle_command_sub
= -1;
48
}
49
50
if
(
_vehicle_status_sub
>= 0) {
51
orb_unsubscribe
(
_vehicle_status_sub
);
52
_vehicle_status_sub
= -1;
53
}
54
55
if
(
_vehicle_status_flags_sub
>= 0) {
56
orb_unsubscribe
(
_vehicle_status_flags_sub
);
57
_vehicle_status_flags_sub
= -1;
58
}
59
60
}
61
62
void
SubscriberHandler::check_for_updates
()
63
{
64
bool
updated;
65
_update_bitfield
= 0;
66
orb_check
(
_vehicle_command_sub
, &updated);
67
68
if
(updated) {
69
_update_bitfield
|= (uint32_t)
StatusMask::VehicleCommand
;
70
}
71
72
updated =
false
;
73
orb_check
(
_vehicle_status_sub
, &updated);
74
75
if
(updated) {
76
_update_bitfield
|= (uint32_t)
StatusMask::VehicleStatus
;
77
}
78
79
updated =
false
;
80
orb_check
(
_vehicle_status_flags_sub
, &updated);
81
82
if
(updated) {
83
_update_bitfield
|= (uint32_t)
StatusMask::VehicleStatusFlags
;
84
}
85
86
updated =
false
;
87
orb_check
(
_battery_status_sub
, &updated);
88
89
if
(updated) {
90
_update_bitfield
|= (uint32_t)
StatusMask::BatteryStatus
;
91
}
92
93
updated =
false
;
94
orb_check
(
_cpuload_sub
, &updated);
95
96
if
(updated) {
97
_update_bitfield
|= (uint32_t)
StatusMask::CpuLoad
;
98
}
99
100
}
101
102
}
/* namespace events */
events::SubscriberHandler::StatusMask::BatteryStatus
events::SubscriberHandler::StatusMask::VehicleStatusFlags
events::SubscriberHandler::_battery_status_sub
int _battery_status_sub
Definition:
subscriber_handler.h:48
events::SubscriberHandler::subscribe
void subscribe()
Definition:
subscriber_handler.cpp:9
events::SubscriberHandler::unsubscribe
void unsubscribe()
Definition:
subscriber_handler.cpp:33
orb_subscribe
int orb_subscribe(const struct orb_metadata *meta)
Definition:
uORB.cpp:75
events::SubscriberHandler::_vehicle_command_sub
int _vehicle_command_sub
Definition:
subscriber_handler.h:50
ORB_ID
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition:
uORB.h:87
events::SubscriberHandler::StatusMask::VehicleCommand
events::SubscriberHandler::_vehicle_status_sub
int _vehicle_status_sub
Definition:
subscriber_handler.h:51
orb_unsubscribe
int orb_unsubscribe(int handle)
Definition:
uORB.cpp:85
events::SubscriberHandler::StatusMask::VehicleStatus
events::SubscriberHandler::_update_bitfield
uint32_t _update_bitfield
Definition:
subscriber_handler.h:54
events::SubscriberHandler::_vehicle_status_flags_sub
int _vehicle_status_flags_sub
Definition:
subscriber_handler.h:52
events::SubscriberHandler::StatusMask::CpuLoad
battery_status
Definition:
parameters.cpp:46
events
Definition:
rc_loss_alarm.cpp:50
orb_check
int orb_check(int handle, bool *updated)
Definition:
uORB.cpp:95
events::SubscriberHandler::check_for_updates
void check_for_updates()
Definition:
subscriber_handler.cpp:62
cpuload
static struct cpuload_s cpuload
Definition:
Commander.cpp:151
events::SubscriberHandler::_cpuload_sub
int _cpuload_sub
Definition:
subscriber_handler.h:49
subscriber_handler.h
src
modules
events
subscriber_handler.cpp
Generated by
1.8.13