QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SysStatusSensorInfo.cc
Go to the documentation of this file.
3#include "QGCMAVLink.h"
4
5QGC_LOGGING_CATEGORY(SysStatusSensorInfoLog, "MAVLink.SysStatusSensorInfo")
6
8 : QObject(parent)
9{
10 // qCDebug(SysStatusSensorInfoLog) << Q_FUNC_INFO << this;
11}
12
13SysStatusSensorInfo::~SysStatusSensorInfo()
14{
15 // qCDebug(SysStatusSensorInfoLog) << Q_FUNC_INFO << this;
16}
17
18void SysStatusSensorInfo::update(const mavlink_sys_status_t &sysStatus)
19{
20 bool dirty = false;
21
22 // Walk the bits
23 for (int bitPosition = 0; bitPosition < 32; bitPosition++) {
24 const MAV_SYS_STATUS_SENSOR sensorBitMask = static_cast<MAV_SYS_STATUS_SENSOR>(1 << bitPosition);
25 if (sysStatus.onboard_control_sensors_present & sensorBitMask) {
26 if (_sensorInfoMap.contains(sensorBitMask)) {
27 SensorInfo &sensorInfo = _sensorInfoMap[sensorBitMask];
28
29 const bool newEnabled = sysStatus.onboard_control_sensors_enabled & sensorBitMask;
30 if (sensorInfo.enabled != newEnabled) {
31 dirty = true;
32 sensorInfo.enabled = newEnabled;
33 }
34
35 const bool newHealthy = sysStatus.onboard_control_sensors_health & sensorBitMask;
36 if (sensorInfo.healthy != newHealthy) {
37 dirty = true;
38 sensorInfo.healthy = newHealthy;
39 }
40 } else {
41 dirty = true;
42 const SensorInfo sensorInfo = { !!(sysStatus.onboard_control_sensors_enabled & sensorBitMask), !!(sysStatus.onboard_control_sensors_health & sensorBitMask) };
43 _sensorInfoMap[sensorBitMask] = sensorInfo;
44 }
45 } else if (_sensorInfoMap.contains(sensorBitMask)) {
46 dirty = true;
47 (void) _sensorInfoMap.remove(sensorBitMask);
48 }
49 }
50
51 if (dirty) {
52 emit sensorInfoChanged();
53 }
54}
55
56QStringList SysStatusSensorInfo::sensorNames() const
57{
58 QStringList rgNames;
59
60 // List ordering is unhealthy, healthy, disabled
61 for (std::pair<MAV_SYS_STATUS_SENSOR, const SensorInfo&> sensorInfo : _sensorInfoMap.asKeyValueRange()) {
62 if (sensorInfo.second.enabled && !sensorInfo.second.healthy) {
63 rgNames.append(QGCMAVLink::mavSysStatusSensorToString(sensorInfo.first));
64 }
65 }
66
67 for (std::pair<MAV_SYS_STATUS_SENSOR, const SensorInfo&> sensorInfo : _sensorInfoMap.asKeyValueRange()) {
68 if (sensorInfo.second.enabled && sensorInfo.second.healthy) {
69 rgNames.append(QGCMAVLink::mavSysStatusSensorToString(sensorInfo.first));
70 }
71 }
72
73 for (std::pair<MAV_SYS_STATUS_SENSOR, const SensorInfo&> sensorInfo : _sensorInfoMap.asKeyValueRange()) {
74 if (!sensorInfo.second.enabled) {
75 rgNames.append(QGCMAVLink::mavSysStatusSensorToString(sensorInfo.first));
76 }
77 }
78
79 return rgNames;
80}
81
82QStringList SysStatusSensorInfo::sensorStatus() const
83{
84 QStringList rgStatus;
85
86 // List ordering is unhealthy, healthy, disabled
87 for (const SensorInfo &sensorInfo : _sensorInfoMap.values()) {
88 if (sensorInfo.enabled && !sensorInfo.healthy) {
89 rgStatus.append(tr("Error"));
90 }
91 }
92
93 for (const SensorInfo &sensorInfo : _sensorInfoMap.values()) {
94 if (sensorInfo.enabled && sensorInfo.healthy) {
95 rgStatus.append(tr("Normal"));
96 }
97 }
98
99 for (const SensorInfo &sensorInfo : _sensorInfoMap.values()) {
100 if (!sensorInfo.enabled) {
101 rgStatus.append(tr("Disabled"));
102 }
103 }
104
105 return rgStatus;
106}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Class which represents sensor info from the SYS_STATUS mavlink message.