QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
HealthAndArmingCheckReport.cc
Go to the documentation of this file.
2#include "QGCMAVLink.h"
4
5
6HealthAndArmingCheckReport::HealthAndArmingCheckReport(QObject *parent)
7 : QObject(parent)
8 , _problemsForCurrentMode(new QmlObjectListModel(this))
9{
10#if 0 // to test the UI
11 _problemsForCurrentMode->append(new HealthAndArmingCheckProblem("No global position", "", "error"));
12 _problemsForCurrentMode->append(new HealthAndArmingCheckProblem("No RC", "Details", "warning"));
13 _problemsForCurrentMode->append(new HealthAndArmingCheckProblem("Accel uncalibrated", "Details <a href='www.test.com'>test</a>", "error"));
14 _problemsForCurrentMode->append(new HealthAndArmingCheckProblem("Gyro uncalibrated", "Details <a href='param://SDLOG_PROFILE'>SDLOG_PROFILE</a>", "error"));
15 _problemsForCurrentMode->append(new HealthAndArmingCheckProblem(
16 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
17 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.<br>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum", ""));
18 _supported = true;
19 emit updated();
20#endif
21}
22
27
28void HealthAndArmingCheckReport::update(uint8_t compid, const events::HealthAndArmingChecks::Results& results,
29 int flightModeGroup)
30{
31 if (compid != MAV_COMP_ID_AUTOPILOT1) {
32 // only autopilot supported atm
33 return;
34 }
35 if (flightModeGroup == -1) {
36 qWarning() << "Flight mode group not set";
37 return;
38 }
39 _supported = true;
40
41 _problemsForCurrentMode->clearAndDeleteContents();
42 _hasWarningsOrErrors = false;
43 for (const auto& check : results.checks(flightModeGroup)) {
44 QString severity = "";
45 if (events::externalLogLevel(check.log_levels) <= events::Log::Error) {
46 severity = "error";
47 _hasWarningsOrErrors = true;
48 } else if (events::externalLogLevel(check.log_levels) <= events::Log::Warning) {
49 severity = "warning";
50 _hasWarningsOrErrors = true;
51 }
52 QString description = QString::fromStdString(check.description);
53 _problemsForCurrentMode->append(new HealthAndArmingCheckProblem(QString::fromStdString(check.message),
54 description.replace("\n", "<br/>"), severity));
55 }
56
57 _canArm = results.canArm(flightModeGroup);
58 if (_missionModeGroup != -1) {
59 // TODO: use results.canRun(_missionModeGroup) while armed
60 _canStartMission = results.canArm(_missionModeGroup);
61 }
62 if (_takeoffModeGroup != -1) {
63 _canTakeoff = results.canArm(_takeoffModeGroup);
64 }
65
66 const auto& healthComponents = results.healthComponents().health_components;
67
68 // GPS state
69 const auto gpsStateIter = healthComponents.find("gps");
70 if (gpsStateIter != healthComponents.end()) {
71 const events::HealthAndArmingChecks::HealthComponent& gpsState = gpsStateIter->second;
72 if (gpsState.health.error || gpsState.arming_check.error) {
73 _gpsState = "red";
74 } else if (gpsState.health.warning || gpsState.arming_check.warning) {
75 _gpsState = "yellow";
76 } else {
77 _gpsState = "green";
78 }
79 }
80
81 emit updated();
82}
83
84void HealthAndArmingCheckReport::setModeGroups(int takeoffModeGroup, int missionModeGroup)
85{
86 _takeoffModeGroup = takeoffModeGroup;
87 _missionModeGroup = missionModeGroup;
88}
void setModeGroups(int takeoffModeGroup, int missionModeGroup)
void update(uint8_t compid, const events::HealthAndArmingChecks::Results &results, int flightModeGroup)
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
void clearAndDeleteContents() override final
Clears the list and calls deleteLater on each entry.