QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FactPanelController.cc
Go to the documentation of this file.
2#include "AutoPilotPlugin.h"
4#include "ParameterManager.h"
5#include "QGCApplication.h"
7#include "Vehicle.h"
8
9#include <QtQml/QQmlEngine>
10
11QGC_LOGGING_CATEGORY(FactPanelControllerLog, "FactSystem.FactPanelController")
12
14 : QObject(parent)
15 , _vehicle(MultiVehicleManager::instance()->activeVehicle())
16{
17 // qCDebug(FactPanelControllerLog) << Q_FUNC_INFO << this;
18
19 if (!_vehicle) {
21 }
22
23 _missingParametersTimer.setInterval(500);
24 _missingParametersTimer.setSingleShot(true);
25 (void) connect(&_missingParametersTimer, &QTimer::timeout, this, &FactPanelController::_checkForMissingParameters);
26}
27
29{
30 // qCDebug(FactPanelControllerLog) << Q_FUNC_INFO << this;
31
32 if (_rebootMessageSuppressedBy) {
33 _rebootMessageSuppressedBy->unsuppressRebootMessage();
34 }
35}
36
38{
39 if (suppress == suppressRebootMessage()) {
40 return;
41 }
42
43 if (suppress) {
44 if (!_vehicle || !_vehicle->parameterManager()) {
45 return;
46 }
47 _rebootMessageSuppressedBy = _vehicle->parameterManager();
48 _rebootMessageSuppressedBy->suppressRebootMessage();
49 // The suppression ends with the vehicle's parameter manager
50 (void) connect(_rebootMessageSuppressedBy, &QObject::destroyed, this,
52 } else {
53 (void) disconnect(_rebootMessageSuppressedBy, &QObject::destroyed, this,
55 _rebootMessageSuppressedBy->unsuppressRebootMessage();
56 _rebootMessageSuppressedBy = nullptr;
57 }
59}
60
61void FactPanelController::_reportMissingParameter(int componentId, const QString &name) const
62{
63 if (componentId == ParameterManager::defaultComponentId) {
64 componentId = _vehicle->defaultComponentId();
65 }
66
67 qgcApp()->reportMissingParameter(componentId, name);
68 qCWarning(FactPanelControllerLog) << "Missing parameter:" << componentId << name;
69}
70
71bool FactPanelController::_allParametersExists(int componentId, const QStringList &names) const
72{
73 bool noMissingFacts = true;
74
75 for (const QString &name : names) {
76 if (_vehicle && !_vehicle->parameterManager()->parameterExists(componentId, name)) {
77 _reportMissingParameter(componentId, name);
78 noMissingFacts = false;
79 }
80 }
81
82 return noMissingFacts;
83}
84
85Fact *FactPanelController::getParameterFact(int componentId, const QString &name, bool reportMissing) const
86{
87 if (_vehicle && _vehicle->parameterManager()->parameterExists(componentId, name)) {
88 Fact *const fact = _vehicle->parameterManager()->getParameter(componentId, name);
89 QQmlEngine::setObjectOwnership(fact, QQmlEngine::CppOwnership);
90 return fact;
91 }
92
93 if (reportMissing) {
94 _reportMissingParameter(componentId, name);
95 }
96
97 return nullptr;
98}
99
100bool FactPanelController::parameterExists(int componentId, const QString &name) const
101{
102 return (_vehicle ? _vehicle->parameterManager()->parameterExists(componentId, name) : false);
103}
104
105void FactPanelController::getMissingParameters(const QStringList &rgNames)
106{
107 for (const QString &name: rgNames) {
108 _missingParameterWaitList.append(name);
109 _vehicle->parameterManager()->refreshParameter(MAV_COMP_ID_AUTOPILOT1, name);
110 }
111
112 _missingParametersTimer.start();
113}
114
115void FactPanelController::_checkForMissingParameters()
116{
117 const QStringList waitList = _missingParameterWaitList;
118 for (const QString &name: waitList) {
119 if (_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_AUTOPILOT1, name)) {
120 (void) _missingParameterWaitList.removeOne(name);
121 }
122 }
123
124 if (_missingParameterWaitList.isEmpty()) {
126 } else {
127 _missingParametersTimer.start();
128 }
129}
#define qgcApp()
#define QGC_LOGGING_CATEGORY(name, categoryStr)
bool _allParametersExists(int componentId, const QStringList &names) const
void _reportMissingParameter(int componentId, const QString &name) const
Report a missing parameter.
void missingParametersAvailable()
Q_INVOKABLE Fact * getParameterFact(int componentId, const QString &name, bool reportMissing=true) const
Q_INVOKABLE void getMissingParameters(const QStringList &rgNames)
FactPanelController(QObject *parent=nullptr)
void setSuppressRebootMessage(bool suppress)
void suppressRebootMessageChanged()
Q_INVOKABLE bool parameterExists(int componentId, const QString &name) const
bool suppressRebootMessage() const
A Fact is used to hold a single value within the system.
Definition Fact.h:15
static MultiVehicleManager * instance()
Vehicle * offlineEditingVehicle() const
bool parameterExists(int componentId, const QString &paramName) const
static constexpr int defaultComponentId
ParameterManager * parameterManager()
Definition Vehicle.h:600