dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
sysalarmsmessagingplugin.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
30 
32 #include <coreplugin/icore.h>
33 #include "systemalarms.h"
34 #include <QtPlugin>
35 #include <QMainWindow>
36 
37 #include <QDebug>
38 
39 SysAlarmsMessagingPlugin::SysAlarmsMessagingPlugin()
40 {
41 }
42 
43 SysAlarmsMessagingPlugin::~SysAlarmsMessagingPlugin()
44 {
45 }
46 
47 void SysAlarmsMessagingPlugin::extensionsInitialized()
48 {
49  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
50  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
51  SystemAlarms *obj =
52  dynamic_cast<SystemAlarms *>(objManager->getObject(QString("SystemAlarms")));
53  connect(obj, &UAVObject::objectUpdated, this, &SysAlarmsMessagingPlugin::updateAlarms);
54 }
55 
61 bool SysAlarmsMessagingPlugin::initialize(const QStringList &arguments, QString *errorString)
62 {
63  Q_UNUSED(arguments);
64  Q_UNUSED(errorString);
65  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
66  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
67  SystemAlarms *obj = SystemAlarms::GetInstance(objManager);
68 
69  for (const auto field : obj->getFields()) {
70  for (int i = 0; i < field->getNumElements(); ++i) {
71  QString element = field->getElementNames()[i];
72  GlobalMessage *msg =
74  msg->setActive(false);
75  errorMessages.insert(element, msg);
77  msg->setActive(false);
78  warningMessages.insert(element, msg);
79  }
80  }
81  TelemetryManager *telMngr = pm->getObject<TelemetryManager>();
82  connect(telMngr, &TelemetryManager::disconnected, this,
83  &SysAlarmsMessagingPlugin::onAutopilotDisconnect);
84  return true;
85 }
86 
92 void SysAlarmsMessagingPlugin::updateAlarms(UAVObject *systemAlarm)
93 {
94  UAVObjectField *field = systemAlarm->getField(QString("Alarm"));
95 
96  for (int i = 0; i < field->getNumElements(); ++i) {
97  const QString element = field->getElementNames()[i];
98  const QString value = field->getValue(i).toString();
99  if (value == field->getOptions().at(SystemAlarms::ALARM_ERROR)) {
100  errorMessages.value(element)->setActive(true);
101  errorMessages.value(element)->setDescription(element + " module is in error state");
102  warningMessages.value(element)->setActive(false);
103  } else if (value == field->getOptions().at(SystemAlarms::ALARM_CRITICAL)) {
104  errorMessages.value(element)->setActive(true);
105  errorMessages.value(element)->setDescription(element + " module is in CRITICAL state");
106  warningMessages.value(element)->setActive(false);
107  } else if (value == field->getOptions().at(SystemAlarms::ALARM_WARNING)) {
108  warningMessages.value(element)->setActive(true);
109  warningMessages.value(element)->setDescription(element + " module is in warning state");
110  errorMessages.value(element)->setActive(false);
111  } else if (value == field->getOptions().at(SystemAlarms::ALARM_UNINITIALISED)) {
112  warningMessages.value(element)->setActive(false);
113  errorMessages.value(element)->setActive(false);
114  } else if (value == field->getOptions().at(SystemAlarms::ALARM_OK)) {
115  warningMessages.value(element)->setActive(false);
116  errorMessages.value(element)->setActive(false);
117  }
118  }
119 }
120 
121 void SysAlarmsMessagingPlugin::onAutopilotDisconnect()
122 {
123  foreach (GlobalMessage *msg, errorMessages.values())
124  msg->setActive(false);
125  foreach (GlobalMessage *msg, warningMessages.values())
126  msg->setActive(false);
127 }
GlobalMessage * addErrorMessage(QString brief, QString description)
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
QVariant getValue(int index=0) const
void setActive(bool value)
int getNumElements() const
for i
Definition: OPPlots.m:140
virtual GlobalMessaging * globalMessaging() const =0
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
QStringList getOptions() const
static ICore * instance()
Definition: coreimpl.cpp:46
UAVObjectField * getField(const QString &name)
Definition: uavobject.cpp:236
QStringList getElementNames() const
GlobalMessage * addWarningMessage(QString brief, QString description)
UAVObject * getObject(const QString &name, quint32 instId=0)